diff options
| -rw-r--r-- | editor.cpp | 20 | ||||
| -rw-r--r-- | editor.h | 2 |
2 files changed, 19 insertions, 3 deletions
@@ -5,7 +5,7 @@ #include <iostream> Editor::Editor(std::vector<std::string>* contents, const std::string& filename): - m_current_line(0), m_filename(filename) { + m_current_line(0), m_filename(filename), m_stopped(false) { m_contents = contents; } @@ -13,8 +13,7 @@ Editor::Editor(std::vector<std::string>* contents, const std::string& filename): int Editor::run_editor() { std::vector<std::string>* c = m_contents; - bool stopped = false; - while (!stopped) { + while (!m_stopped) { print_contents_on_line(m_current_line); char input = Utils::getch(); @@ -28,6 +27,9 @@ int Editor::run_editor() { case 'w': write_command(); break; + case 'q': + quit_command(); + break; default: break; } @@ -112,3 +114,15 @@ int Editor::write() { return 0; } + +int Editor::quit_command() { + std::cout << "Really quit? [y/n] "; + char answer = Utils::getch(); + + if (answer == 'y') { + m_stopped = true; + std::cout << "\n"; + } + + return 0; +} @@ -14,11 +14,13 @@ class Editor { std::vector<std::string>* m_contents; std::string m_filename; int m_current_line; + bool m_stopped; int print_contents_on_line(int line) const; int edit_command(); int move_to_command(); int write_command(); + int quit_command(); int edit_line(int line); int move_to_line(int line); |
