diff --git a/src/Editor.cpp b/src/Editor.cpp index 5544aab..8811386 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -8,7 +8,7 @@ namespace groove { Editor::Editor(std::string filename) : x(0), y(0), buffer(std::make_unique()), mode_(Mode::EDIT), - filename(filename), offset(0) { + filename(filename), offset(0), lineMode(LineMode::NONE) { this->modes.emplace(Mode::INSERT, std::make_unique(*this)); this->modes.emplace(Mode::EDIT, std::make_unique(*this)); this->modes.emplace(Mode::QUIT, std::make_unique(*this)); @@ -56,11 +56,21 @@ namespace groove { void Editor::render() { long linenumber = this->offset; - this->vspace = Editor::Digits(this->buffer->linebuffer().size()) + 2; + this->vspace = this->lineMode == LineMode::RELATIVE || this->lineMode == LineMode::NUMBERS ? + Editor::Digits(this->buffer->linebuffer().size()) + 2 : 0; clear(); for (int i = this->offset; i < LINES - 1 + this->offset; i++) { - long ln = static_cast(std::sqrt(std::pow(static_cast(this->y - linenumber), 2))); - ln = ln == 0 ? linenumber : ln; + long ln; + switch (this->lineMode) { + case LineMode::RELATIVE: + ln = static_cast(std::sqrt(std::pow(static_cast(this->y - linenumber), 2))); + ln = ln == 0 ? linenumber : ln; + break; + case LineMode::NUMBERS: + ln = linenumber; + break; + } + if(i >= this->buffer->linebuffer().size()) { move(i - this->offset, 0); clrtoeol(); @@ -72,13 +82,17 @@ namespace groove { long x = this->vspace; long found = -1; long len = -1; - std::string label = std::string(x - Editor::Digits(ln) - 1, ' '); - label += std::to_string(ln) + ' '; - if (linenumber != this->y) - attron(A_REVERSE); - mvprintw(i - offset, 0, label.c_str()); - if (linenumber != this->y) - attroff(A_REVERSE); + + if (this->lineMode != LineMode::NONE) { + std::string label = std::string(x - Editor::Digits(ln) - 1, ' '); + label += std::to_string(ln) + ' '; + if (linenumber != this->y) + attron(A_REVERSE); + mvprintw(i - offset, 0, label.c_str()); + if (linenumber != this->y) + attroff(A_REVERSE); + } + for (auto& car : line) { if (hilist.find(x - this->vspace) != hilist.end()) { found = x - this->vspace; diff --git a/src/Editor.hpp b/src/Editor.hpp index b74fe12..7fc98ec 100644 --- a/src/Editor.hpp +++ b/src/Editor.hpp @@ -18,6 +18,13 @@ namespace groove { QUIT }; + enum LineMode { + NUMBERS, + RELATIVE, + NONE, + COUNT + }; + class Editor { friend class modes::Mode; friend class modes::Insert; @@ -29,6 +36,7 @@ namespace groove { int offset; long vspace; char lastChar = 0; + LineMode lineMode; std::unique_ptr buffer; Mode mode_; std::string clipboard = ""; diff --git a/src/modes/Edit.cpp b/src/modes/Edit.cpp index cd76315..cb0e04f 100644 --- a/src/modes/Edit.cpp +++ b/src/modes/Edit.cpp @@ -36,6 +36,19 @@ namespace groove { case 'd': this->editor.buffer->remove(this->editor.y); break; + case 'l': + switch (this->editor.lineMode) { + case LineMode::NUMBERS: + this->editor.lineMode = LineMode::RELATIVE; + break; + case LineMode::RELATIVE: + this->editor.lineMode = LineMode::NONE; + break; + case LineMode::NONE: + this->editor.lineMode = LineMode::NUMBERS; + break; + } + break; } } }