-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathncurses_utils.cpp
More file actions
executable file
·112 lines (91 loc) · 2.9 KB
/
Copy pathncurses_utils.cpp
File metadata and controls
executable file
·112 lines (91 loc) · 2.9 KB
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
109
110
111
112
#include "ncurses_utils.h"
#include "msg_box.h"
#include <string>
#include <cstring>
#include <sstream>
#include <string>
#include <panel.h>
#include <algorithm>
using namespace std;
//**************************************************************//
// PRINT IN THE MIDDLE //
//**************************************************************//
//Print a string in the centre of a given ncurses window
void nutil::print_in_middle(WINDOW *win, int starty, int startx, int width,
const char *string, chtype color) {
//DECLARATIONS
int length, x, y;
float temp;
if(win == NULL)
win = stdscr;
getyx(win, y, x);
if(startx != 0)
x = startx;
if(starty != 0)
y = starty;
if(width == 0)
width = 80;
length = strlen(string);
temp = (width - length)/ 2;
x = startx + (int)temp;
wattron(win, color);
mvwprintw(win, y, x, "%s", string);
wattroff(win, color);
}
//**************************************************************//
// DRAW A BOX INSIDE A WINDOW //
//**************************************************************//
void nutil::sub_box(WINDOW *win, int height, int width, int y_pos, int x_pos) {
//place a T in the left location to mark the end of the header
//TOP LINE
mvwaddch(win, y_pos, x_pos, ACS_ULCORNER);
mvwhline(win, y_pos, x_pos +1, ACS_HLINE, width -2);
mvwaddch(win, y_pos, x_pos + width -1, ACS_URCORNER);
//VERTICALS
mvwvline(win, y_pos +1, x_pos, ACS_VLINE, height -2);
mvwvline(win, y_pos +1, x_pos + width -1, ACS_VLINE, height -2);
//BOTTOM LINE
mvwaddch(win, y_pos + height -1, x_pos, ACS_LLCORNER);
mvwhline(win, y_pos + height -1, x_pos +1, ACS_HLINE, width -2);
mvwaddch(win, y_pos + height -1, x_pos + width -1, ACS_LRCORNER);
update_panels();
doupdate();
}
//**************************************************************//
// CLEAN STRING //
//**************************************************************//
string nutil::CleanString(string name){
//REMOVE LEADING WHITESPACE
name.erase(name.begin(), std::find_if(name.begin(), \
name.end(), std::bind1st(std::not_equal_to<char>(), ' ')));
//REMOVE TRAILING WHITESPACE
name.erase(std::find_if(name.rbegin(), name.rend(), \
std::bind1st(std::not_equal_to<char>(), ' ')).base(), name.end());
return name;
}
//**************************************************************//
// DEBUG MESSAGE BOX FUNCTIONS //
//**************************************************************//
void nutil::db() {
update_panels();
doupdate();
msg_box().info("Break Point", "DEBUG");
update_panels();
doupdate();
}
void nutil::db(int number) {
update_panels();
doupdate();
std::stringstream ss;
ss << "The value returned is: " << number;
msg_box().info(ss.str(), "DEBUG: ");
update_panels();
doupdate();
}
void nutil::db(std::string msg_string) {
update_panels();
doupdate();
msg_box().info(msg_string, "DEBUG");
update_panels();
doupdate();
}