diff --git a/graph_browser.cpp b/graph_browser.cpp index 8adffb0..e660a17 100644 --- a/graph_browser.cpp +++ b/graph_browser.cpp @@ -50,7 +50,7 @@ void GraphBrowser::destroy() endwin(); } -GraphBrowser::GraphBrowser(const Graph& g) +GraphBrowser::GraphBrowser(Graph& g) : menu_(0) , current_win_(0) , n_win(0) @@ -92,7 +92,7 @@ GraphBrowser::GraphBrowser(const Graph& g) wrefresh(n_of_n_win_); // bottom text - mvprintw(TERM_MAX_Y-1, 0, "ESC to exit, cursor keys to navigate"); + mvprintw(TERM_MAX_Y-1, 0, "ESC to exit, cursor keys to navigate, d to delete"); refresh(); } @@ -144,7 +144,21 @@ void GraphBrowser::mainLoop() menu_driver(menu_, REQ_SCR_UPAGE); break; + case KEY_DEL: { + const std::string current = history_.back(); + if (current == history_.front()) // cannot delete the first + break; + + graph_.removeVertex(current); + + history_.pop_back(); + const std::string prev = history_.back(); + updateCurrent(prev); + updateNeighbours(); + } + } + wrefresh(current_win_); } } diff --git a/graph_browser.hpp b/graph_browser.hpp index fa97188..af90ba6 100644 --- a/graph_browser.hpp +++ b/graph_browser.hpp @@ -13,7 +13,10 @@ public: static constexpr size_t TERM_MAX_X = 80; static constexpr size_t TERM_MAX_Y = 24; + static constexpr int KEY_ESC = 27; + static constexpr int KEY_DEL = 100; // d + static constexpr size_t window_height = TERM_MAX_Y-2; static constexpr size_t current_window_width = TERM_MAX_X/4; static constexpr size_t n_window_width = TERM_MAX_X/4; @@ -21,7 +24,7 @@ public: void static init(); void static destroy(); - GraphBrowser(const Graph& g); + GraphBrowser(Graph& g); ~GraphBrowser(); void mainLoop(); @@ -36,7 +39,7 @@ private: MENU *menu_; WINDOW *current_win_, *n_win, * n_of_n_win_; ITEM **items_; - const Graph& graph_; + Graph& graph_; std::deque history_; }; diff --git a/main.cpp b/main.cpp index 70e2626..594a80c 100644 --- a/main.cpp +++ b/main.cpp @@ -52,7 +52,7 @@ Graph generateRandomGraph(size_t number_of_vertices, int main(int argc, char* argv[]) { - const Graph g = generateRandomGraph(10, 200, 5, 20); + Graph g = generateRandomGraph(10, 200, 5, 20); GraphBrowser::init();