added modi for linenumbering

development
Michael Ochmann 8 years ago
parent cecf3079f6
commit f5a4a896a6
  1. 20
      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), Editor::Editor(std::string filename) : x(0), y(0),
buffer(std::make_unique<Buffer>()), mode_(Mode::EDIT), 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::INSERT, std::make_unique<modes::Insert>(*this));
this->modes.emplace(Mode::EDIT, std::make_unique<modes::Edit>(*this)); this->modes.emplace(Mode::EDIT, std::make_unique<modes::Edit>(*this));
this->modes.emplace(Mode::QUIT, std::make_unique<modes::Quit>(*this)); this->modes.emplace(Mode::QUIT, std::make_unique<modes::Quit>(*this));
@ -56,11 +56,21 @@ namespace groove {
void Editor::render() { void Editor::render() {
long linenumber = this->offset; 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(); clear();
for (int i = this->offset; i < LINES - 1 + this->offset; i++) { 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))); 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; ln = ln == 0 ? linenumber : ln;
break;
case LineMode::NUMBERS:
ln = linenumber;
break;
}
if(i >= this->buffer->linebuffer().size()) { if(i >= this->buffer->linebuffer().size()) {
move(i - this->offset, 0); move(i - this->offset, 0);
clrtoeol(); clrtoeol();
@ -72,6 +82,8 @@ namespace groove {
long x = this->vspace; long x = this->vspace;
long found = -1; long found = -1;
long len = -1; long len = -1;
if (this->lineMode != LineMode::NONE) {
std::string label = std::string(x - Editor::Digits(ln) - 1, ' '); std::string label = std::string(x - Editor::Digits(ln) - 1, ' ');
label += std::to_string(ln) + ' '; label += std::to_string(ln) + ' ';
if (linenumber != this->y) if (linenumber != this->y)
@ -79,6 +91,8 @@ namespace groove {
mvprintw(i - offset, 0, label.c_str()); mvprintw(i - offset, 0, label.c_str());
if (linenumber != this->y) if (linenumber != this->y)
attroff(A_REVERSE); attroff(A_REVERSE);
}
for (auto& car : line) { for (auto& car : line) {
if (hilist.find(x - this->vspace) != hilist.end()) { if (hilist.find(x - this->vspace) != hilist.end()) {
found = x - this->vspace; found = x - this->vspace;

@ -18,6 +18,13 @@ namespace groove {
QUIT QUIT
}; };
enum LineMode {
NUMBERS,
RELATIVE,
NONE,
COUNT
};
class Editor { class Editor {
friend class modes::Mode; friend class modes::Mode;
friend class modes::Insert; friend class modes::Insert;
@ -29,6 +36,7 @@ namespace groove {
int offset; int offset;
long vspace; long vspace;
char lastChar = 0; char lastChar = 0;
LineMode lineMode;
std::unique_ptr<Buffer> buffer; std::unique_ptr<Buffer> buffer;
Mode mode_; Mode mode_;
std::string clipboard = ""; std::string clipboard = "";

@ -36,6 +36,19 @@ namespace groove {
case 'd': case 'd':
this->editor.buffer->remove(this->editor.y); this->editor.buffer->remove(this->editor.y);
break; 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