|
|
|
@ -8,7 +8,7 @@ namespace groove { |
|
|
|
|
|
|
|
|
|
Editor::Editor(std::string filename) : x(0), y(0), |
|
|
|
|
buffer(std::make_unique<Buffer>()), mode_(Mode::EDIT), |
|
|
|
|
filename(filename), offset(0) { |
|
|
|
|
filename(filename), offset(0), lineMode(LineMode::NONE) { |
|
|
|
|
this->modes.emplace(Mode::INSERT, std::make_unique<modes::Insert>(*this)); |
|
|
|
|
this->modes.emplace(Mode::EDIT, std::make_unique<modes::Edit>(*this)); |
|
|
|
|
this->modes.emplace(Mode::QUIT, std::make_unique<modes::Quit>(*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<long>(std::sqrt(std::pow(static_cast<double>(this->y - linenumber), 2))); |
|
|
|
|
ln = ln == 0 ? linenumber : ln; |
|
|
|
|
long ln; |
|
|
|
|
switch (this->lineMode) { |
|
|
|
|
case LineMode::RELATIVE: |
|
|
|
|
ln = static_cast<long>(std::sqrt(std::pow(static_cast<double>(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; |
|
|
|
|