added modi for linenumbering

development
Michael Ochmann 8 years ago
parent cecf3079f6
commit f5a4a896a6
  1. 36
      src/Editor.cpp
  2. 8
      src/Editor.hpp
  3. 13
      src/modes/Edit.cpp

@ -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;

@ -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> buffer;
Mode mode_;
std::string clipboard = "";

@ -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;
}
}
}

Loading…
Cancel
Save