This repository has been archived by the owner on Nov 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUI.cpp
108 lines (100 loc) · 2.19 KB
/
UI.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include <string>
#include <iomanip>
#include "Buffer.h"
#include "UI.h"
using namespace std;
void UI::display()
{
const string Short_Dash(10, '-');
const string Long_Dash(80, '-');
// prints error if there is one
m_buffer.printError();//Prints error if one exists
cout << m_buffer.currentFile() << endl;
cout << Long_Dash << endl
<< endl;
m_buffer.display();
cout << endl
<< Long_Dash << endl;
cout << "-(O)pen -(G)o -(B)ack -(N)ext Page -(P)revious Page -(Q)uit\n";
cout << Short_Dash << endl;
}
void UI::execute(char selection, bool &isDone)
{
switch (selection)
{
case 'N':
case 'n':
{
// Next page
m_buffer.nextPage();
break;
}
case 'G':
case 'g':
{
// Go ---opens a link
int linkNumber;
cout << "Link Number: ";
cin >> linkNumber;
m_buffer.openLink(linkNumber);
break;
}
case 'O':
case 'o':
{
// open file
cout << "File Name: ";
string file_name;
getline(cin, file_name);
m_buffer.openFile(file_name);
break;
}
case 'B':
case 'b':
{
// last file
m_buffer.openLastFile();
break;
}
case 'P':
case 'p':
{
// previous page
m_buffer.lastPage();
break;
}
case 'Q':
case 'q':
{
// quit
isDone = true;
break;
}
default:
{
m_buffer.setUIError("Invalid command");
}
}
}
void UI::run()
{
char command;
std::cout << "\033c";
std::cout << "Welcome to Tyler and Cary's File Browser!\n\n";
cout << "Enter Window Height (Lines): ";
cin >> m_vertical_lines;
cout << "Enter Window Width (Characters Per Line): ";
cin >> m_horizontal_lines;
m_buffer.setViewableArea(m_vertical_lines, m_horizontal_lines);
bool isDone = false;
while (!isDone)
{
std::cout << "\033c"; // clears the terminal to allow for the next presentation of the UI
display();
cout << "Please Enter Command (One Character): ";
cin >> command;
cin.get();
execute(command, isDone);
}
}