// FileViewer.cpp #include "FileViewer.h" using namespace std; void FileViewer::display() { const string long_separator(50, '-'); const string short_separator(8, '-'); system(clear_command); string file_name = buffer_.file_name(); if (file_name.empty()) cout << "\n"; else cout << file_name << endl; cout << long_separator << endl; buffer_.display(); cout << long_separator << endl << " next previous open quit\n" << short_separator << endl; } void FileViewer::execute_command(char command, bool & done) { done = false; // good for all commands except quit switch (command) { case 'n': { buffer_.move_to_next_page(); break; } case 'o': { cout << "file name: "; string file_name; getline(cin, file_name); if (!buffer_.open(file_name)) print_error("Could not open file."); break; } case 'p': { buffer_.move_to_previous_page(); break; } case 'q': { done = true; break; } } } void FileViewer::run() { cout << "Window height? "; cin >> window_height_; cin.ignore(); // '\n' cout << endl; buffer_.set_window_height(window_height_); bool done = false; do { display(); cout << "command: "; char command; cin >> command; cin.ignore(); // '\n' execute_command(command, done); } while (!done); }