From 0b66d839bede8a00430cf6b5bd3a3ad7c9e59867 Mon Sep 17 00:00:00 2001 From: Michael Ochmann Date: Thu, 9 Mar 2017 20:05:04 +0100 Subject: [PATCH] added pageup/down support; tried help screen, not working yet, though --- src/Editor.cpp | 6 ++++++ src/Editor.hpp | 10 ++++++++++ src/modes/Edit.cpp | 13 ++++++++++++- src/ncurses/ncurses.hpp | 5 ++++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Editor.cpp b/src/Editor.cpp index a9be452..8bba891 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -14,6 +14,10 @@ namespace groove { this->modes.emplace(Mode::EDIT, std::make_unique(*this)); this->modes.emplace(Mode::QUIT, std::make_unique(*this)); this->modes.emplace(Mode::SAVE, std::make_unique(*this)); + + this->overlay = newwin(LINES * 0.9, COLS * 0.9, (LINES * 0.1f) / 2.0f, (COLS * 0.1f) / 2.0f); + box(this->overlay, 0, 0); + if (!this->load()) { std::cerr << "Could not open file: '" << this->filename << "', creating it on save.\n"; this->buffer->insert(""); @@ -126,6 +130,8 @@ namespace groove { } this->status(); move(static_cast(this->y - this->offset), static_cast(this->x + this->vspace)); + this->renderOverlay(); + } void Editor::status() { diff --git a/src/Editor.hpp b/src/Editor.hpp index d85d50d..bdbac95 100644 --- a/src/Editor.hpp +++ b/src/Editor.hpp @@ -40,6 +40,7 @@ namespace groove { long vspace; bool inComment; char lastChar = 0; + WINDOW* overlay; History history; LineMode lineMode; std::unique_ptr buffer; @@ -126,11 +127,20 @@ namespace groove { return false; } } + void renderOverlay() { + wbkgd(this->overlay, COLOR_PAIR(ncurses::Colors::STATUSBAR)); + mvwaddstr(this->overlay, 3, 3, "Hallo win"); + refresh(); + wrefresh(this->overlay); + } public: Editor(std::string file = "ubenannt"); Mode mode() { return this->mode_; } + ~Editor() { + delete this->overlay; + } void input(int c); void render(); static long Digits(long number); diff --git a/src/modes/Edit.cpp b/src/modes/Edit.cpp index a8cf72a..34e442b 100644 --- a/src/modes/Edit.cpp +++ b/src/modes/Edit.cpp @@ -1,9 +1,10 @@ #include #include +#include namespace groove { namespace modes { - + void Edit::input(int c) { if (this->editor.movement(c)) return; @@ -104,6 +105,16 @@ namespace groove { this->editor.y = this->editor.buffer->size() - 1; this->editor.offset = this->editor.buffer->size() - LINES + 1; break; + case KEY_NPAGE: + for (int i = 0; i < LINES; i++) { + this->editor.down(); + } + break; + case KEY_PPAGE: + for (int i = 0; i < LINES; i++) { + this->editor.up(); + } + break; } } } diff --git a/src/ncurses/ncurses.hpp b/src/ncurses/ncurses.hpp index 589b2aa..1f7c6d0 100644 --- a/src/ncurses/ncurses.hpp +++ b/src/ncurses/ncurses.hpp @@ -30,8 +30,11 @@ namespace groove { }; class ncurses { + private: + WINDOW* overlay; public: - ncurses() {}; + ncurses() { + }; void init() { setlocale(LC_ALL, ""); initscr(); // Start ncurses mode