aboutsummaryrefslogtreecommitdiffstats
path: root/editor.cpp
diff options
context:
space:
mode:
authorJan Tuomi <jan-sebastian.tuomi@aalto.fi>2016-10-09 13:48:34 +0300
committerJan Tuomi <jan-sebastian.tuomi@aalto.fi>2016-10-09 14:50:24 +0300
commit5bc2a0d9b6be834755efe5b09f9795f7495e8483 (patch)
treeefe8f8393f648e279ac80f188a2bc889fb0d7c9a /editor.cpp
parent40c4dfd312b24a7e012448e39a363c07fa1e8c5d (diff)
Add quit
Diffstat (limited to 'editor.cpp')
-rw-r--r--editor.cpp20
1 files changed, 17 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;
+}