|
|
|
@ -56,20 +56,20 @@ namespace groove { |
|
|
|
|
|
|
|
|
|
void Editor::render() { |
|
|
|
|
int linenumber = 0; |
|
|
|
|
int space = Editor::Digits(this->buffer->linebuffer().size()) + 2; |
|
|
|
|
this->vspace = Editor::Digits(this->buffer->linebuffer().size()) + 2; |
|
|
|
|
clear(); |
|
|
|
|
for (int i = 0; i < LINES - 1 + this->offset; i++) { |
|
|
|
|
int ln = static_cast<int>(std::sqrt(std::pow(static_cast<double>(this->y - linenumber), 2))); |
|
|
|
|
unsigned long ln = static_cast<unsigned long>(std::sqrt(std::pow(static_cast<double>(this->y - linenumber), 2))); |
|
|
|
|
ln = ln == 0 ? linenumber : ln; |
|
|
|
|
if(i >= this->buffer->linebuffer().size()) { |
|
|
|
|
move(i - this->offset, 0); |
|
|
|
|
clrtoeol(); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
std::string line = /*std::to_string(i) + " | " +*/ this->buffer->at(i); |
|
|
|
|
std::string line = this->buffer->at(i); |
|
|
|
|
Highlighter highlighter(line); |
|
|
|
|
std::unordered_map<int, std::pair<int, ncurses::Colors>> hilist = highlighter.get(); |
|
|
|
|
int x = space; |
|
|
|
|
int x = this->vspace; |
|
|
|
|
int found = -1; |
|
|
|
|
int len = -1; |
|
|
|
|
std::string label = std::string(x - Editor::Digits(ln) - 1, ' '); |
|
|
|
@ -80,14 +80,14 @@ namespace groove { |
|
|
|
|
if (linenumber != this->y) |
|
|
|
|
attroff(A_REVERSE); |
|
|
|
|
for (auto& car : line) { |
|
|
|
|
if (hilist.find(x - space) != hilist.end()) { |
|
|
|
|
found = x - space; |
|
|
|
|
len = hilist.at(x - space).first; |
|
|
|
|
if (hilist.find(x - this->vspace) != hilist.end()) { |
|
|
|
|
found = x - this->vspace; |
|
|
|
|
len = hilist.at(x - this->vspace).first; |
|
|
|
|
} |
|
|
|
|
if (found >= 0 && len >= 0) { |
|
|
|
|
if (x - space >= found && x - space <= found + len - 1) |
|
|
|
|
if (x - this->vspace >= found && x - this->vspace <= found + len - 1) |
|
|
|
|
attron(COLOR_PAIR(hilist.at(found).second)); |
|
|
|
|
else if (x - space > found && x - space >= found + len) { |
|
|
|
|
else if (x - this->vspace > found && x - this->vspace >= found + len) { |
|
|
|
|
attron(COLOR_PAIR(ncurses::Colors::MAIN)); |
|
|
|
|
found = -1; |
|
|
|
|
len = -1; |
|
|
|
@ -103,7 +103,7 @@ namespace groove { |
|
|
|
|
linenumber++; |
|
|
|
|
} |
|
|
|
|
this->status(); |
|
|
|
|
move(this->y - this->offset, this->x + space); |
|
|
|
|
move(static_cast<int>(this->y - this->offset), static_cast<int>(this->x + this->vspace)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Editor::status() { |
|
|
|
@ -119,8 +119,8 @@ namespace groove { |
|
|
|
|
attroff(COLOR_PAIR(ncurses::Colors::STATUSBAR)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int Editor::Digits(int number) { |
|
|
|
|
return number > 0 ? (int) log10 ((double) number) + 1 : 1; |
|
|
|
|
unsigned long Editor::Digits(unsigned long number) { |
|
|
|
|
return number > 0 ? static_cast<unsigned long>(log10 ((double) number) + 1) : 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |