3 WINDOW* View::win =
nullptr;
9 B15F::abort(
"View::win not initialized, missing context");
11 getmaxyx(win, height, width);
19 void View::setWinContext(WINDOW* win)
24 WINDOW* View::getWinContext()
30 std::vector<std::string> View::str_split(
const std::string& str,
const std::string delim)
32 std::vector<std::string> tokens;
33 size_t prev = 0, pos = 0;
36 pos = str.find(delim, prev);
37 if (pos == std::string::npos) pos = str.length();
38 std::string token = str.substr(prev, pos-prev);
39 if (!token.empty()) tokens.push_back(token);
40 prev = pos + delim.length();
42 while (pos < str.length() && prev < str.length());
47 void View::setTitle(std::string title)
56 if (ioctl(0, TIOCGWINSZ, (
char *) &size) < 0)
57 throw std::runtime_error(
"TIOCGWINSZ error");
60 start_x = floor((size.ws_col - width) / 2.);
61 start_y = floor((size.ws_row - height) / 2.);
64 mvwin(win, start_y, start_x);
70 int offset_x = (width - title.length()) / 2;
71 mvwprintw(win, 1, offset_x,
"%s", title.c_str());