#pragma once #include #include #include namespace groove { enum class Mode { INSERT, EDIT, SAVE, QUIT }; class Editor { private: int x, y; int offset; char lastChar = 0; std::unique_ptr buffer; Mode mode_; std::string clipboard = ""; std::string filename; bool load(); bool save(); void status(); void scrollUp() { if (this->y < this->offset && this->offset > 0) this->offset--; } void scrollDown() { if (this->y >= LINES - 1) this->offset++; } void left() { if (this->x - 1 >= 0) this->x--; } void right() { if (this->x + 1 <= COLS && this->x + 1 <= this->buffer->linebuffer().at(this->y).length()) this->x++; } void up() { if (this->y - 1 >= 0) this->y--; else { return; } if (this->x >= this->buffer->linebuffer().at(this->y).length()) { int length = this->buffer->linebuffer().at(this->y).length(); this->x = length > 0 ? length - 1 : 0; } this->scrollUp(); } void down() { if (this->y + 1 < this->buffer->linebuffer().size()) this->y++; else { return; } if (this->x >= this->buffer->linebuffer().at(this->y).length()) { int length = this->buffer->linebuffer().at(this->y).length(); this->x = length > 0 ? length - 1 : 0; } this->scrollDown(); } public: Editor() : x(0), y(0), buffer(std::make_unique()), mode_(Mode::EDIT), filename("unbenannt"), offset(0) { this->buffer->insert(""); } Editor(std::string file); Mode mode() { return this->mode_; } void input(int c); void render(); static int Digits(int number); }; }