aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--editor.cpp20
-rw-r--r--editor.h2
2 files changed, 19 insertions, 3 deletions
diff --git a/editor.cpp b/editor.cpp
index 27169ef..e714a15 100644
--- a/editor.cpp
+++ b/editor.cpp
@@ -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;
+}
diff --git a/editor.h b/editor.h
index 9d2a773..6693446 100644
--- a/editor.h
+++ b/editor.h
@@ -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);