-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen.cc
62 lines (54 loc) · 1.32 KB
/
screen.cc
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
#include "screen.h"
static const int FILE_BAR_COLOR = 1;
Screen::Screen(const char* file_name) noexcept
: rows{}, cols{}, file_name{file_name}, file_info_bar{} {
initscr();
start_color();
init_pair(FILE_BAR_COLOR, COLOR_BLACK, COLOR_WHITE);
noecho();
raw();
getmaxyx(stdscr, rows, cols);
scrollok(stdscr, true);
rows -= 2;
file_info_bar = newwin(1, cols, rows, 0);
}
void Screen::display(std::vector<std::string>::const_iterator begin,
std::vector<std::string>::const_iterator end,
const Cursor& cursor) const noexcept {
clear();
std::size_t i = 0;
for (auto iterator = begin; i < rows && iterator != end;
++iterator, ++i) {
printw("%s", iterator->c_str());
if (i != rows - 1) {
printw("\n");
}
}
for (; i < rows; ++i) {
printw("~");
if (i != rows - 1) {
printw("\n");
}
}
refresh();
draw_file_info_bar();
move_cursor(cursor);
}
void Screen::draw_file_info_bar() const noexcept {
wbkgd(file_info_bar, COLOR_PAIR(FILE_BAR_COLOR));
wclear(file_info_bar);
if (is_file_modified) {
mvwprintw(file_info_bar, 0, 0, "%s [+]", file_name.c_str());
}
else {
mvwprintw(file_info_bar, 0, 0, "%s", file_name.c_str());
}
wrefresh(file_info_bar);
}
void Screen::move_cursor(const Cursor& cursor) const noexcept {
move(cursor.y, cursor.x);
}
Screen::~Screen() {
delwin(file_info_bar);
endwin();
}