// TextEditor.cpp #include "TextEditor.h" #include using std::cin; using std::cout; using std::endl; #include using std::string; void TextEditor::display() { const string long_separator(50, '-'); const string short_separator(8, '-'); if (!error_message.empty()) { cout << "ERROR: " + error_message << endl; error_message.clear(); } string file_name = buffer.get_file_name(); if (file_name.empty()) cout << "\n"; else cout << file_name << endl; cout << long_separator << endl; buffer.display(); cout << long_separator << endl; cout << " next jump insert open quit\n"; cout << " previous replace delete save\n"; cout << short_separator << endl; } void TextEditor::run() { cout << "Window height? "; cin >> window_height; cin.get(); // '\n' cout << '\n'; buffer.set_window_height(window_height); bool done = false; while (!done) { display(); cout << "choice: "; char command; cin >> command; cin.get(); // '\n' switch (command) { case 'd': { buffer.erase(); break; } case 'i': { cout << "new line: "; string new_line; getline(cin, new_line); buffer.insert(new_line); break; } case 'j': { error_message = "Command jump not yet implemented"; break; } case 'n': { buffer.move_to_next_line(); break; } case 'o': { cout << "file name: "; string file_name; getline(cin, file_name); if (!buffer.open(file_name)) error_message = "Could not open " + file_name; break; } case 'p': { buffer.move_to_previous_line(); break; } case 'q': { done = true; break; } case 'r': { error_message = "Command replace not yet implemented"; break; } case 's': { cout << "file name: "; string file_name; getline(cin, file_name); if (!buffer.save(file_name)) error_message = "Could not open " + file_name; break; } }; cout << endl; } // while return; }