-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
161 lines (128 loc) · 3.66 KB
/
test.cpp
File metadata and controls
161 lines (128 loc) · 3.66 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* This file is part of pas.
pas is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
pas is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pas. If not, see <http://www.gnu.org/licenses/>.
*/
/* pas is Copyright 2017 by Perry Kivolowitz
CURSES TESTBED - NOT IN PRODUCTION PAS
*/
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <ncursesw/curses.h>
#include <ncursesw/panel.h>
#include <wchar.h>
WINDOW * help_window = nullptr;
WINDOW * background_window = nullptr;
PANEL * help_panel = nullptr;
PANEL * background_panel = nullptr;
using namespace std;
static vector<wstring> help_text;
static int widest_help_line = 0;
// std::string -> std::wstring
inline wstring S2W(string s)
{
wstring ws;
ws.assign(s.begin(), s.end());
return ws;
}
/*
// std::wstring -> std::string
std::wstring ws(L"wstring");
std::string s;
s.assign(ws.begin(), ws.end());
*/
void FillWindow(WINDOW * w, wchar_t f)
{
int lines, cols;
cchar_t C;
C.attr = A_NORMAL;
C.chars[0] = f;
C.chars[1] = L'\0';
getmaxyx(w, lines, cols);
for (int l = 1; l < lines - 1; l++) {
for (int c = 1; c < cols - 1; c++) {
wmove(w, l, c);
wadd_wch(w, &C);
}
}
}
void InitializeHelpText()
{
vector<wstring> * v = &help_text;
v->push_back(S2W("+ next DAC"));
v->push_back(L"- Schönberg DAC");
v->push_back(S2W("UP scroll up"));
v->push_back(S2W("DN scroll down"));
v->push_back(L"^B Schönberg up");
v->push_back(S2W("^F screen down"));
v->push_back(S2W("RET queue"));
v->push_back(S2W("^X Schönberg"));
v->push_back(S2W("^N next"));
v->push_back(S2W("^P pause"));
v->push_back(S2W("^R Schönberg"));
v->push_back(S2W("ESC quit"));
v->push_back(S2W("^H this help"));
for (auto it = v->begin(); it < v->end(); it++) {
if ((int) it->size() > widest_help_line)
widest_help_line = it->size();
}
}
void MakeHelpWindow(WINDOW * w, PANEL * p)
{
if (help_text.size() == 0)
InitializeHelpText();
int width, height;
getmaxyx(w, height, width);
werase(w);
box(w, 0, 0);
wmove(w, 1, 1);
waddwstr(w, S2W("pas-curses-client help any key to return").c_str());
wmove(w, 2, 1);
whline(w, ACS_HLINE, width - 2);
int lines_of_text = height - 4;
int columns_needed = (help_text.size() + lines_of_text - 1) / lines_of_text;
if (columns_needed > 2) {
wmove(w, height - 2, 1);
waddwstr(w, S2W("need a taller window").c_str());
return;
}
int counter = 0;
for (auto it = help_text.begin(); it < help_text.end(); it++, counter++) {
wmove(w, 3 + (counter % lines_of_text), 1 + (counter / lines_of_text) * width / 2);
waddwstr(w, it->c_str());
}
hide_panel(p);
}
int main(int argc, char * argv[])
{
setlocale(LC_ALL,"");
initscr();
background_window = newwin(0, 0, 0, 0);
background_panel = new_panel(background_window);
wborder(background_window, 0, 0, 0, 0, 0, 0, 0, 0);
help_window = newwin(14, 50, 0, 0);
help_panel = new_panel(help_window);
wborder(help_window, 0, 0, 0, 0, 0, 0, 0, 0);
FillWindow(background_window, L'ö');
MakeHelpWindow(help_window, help_panel);
move_panel(help_panel, 10, 10);
update_panels();
doupdate();
wgetch(background_window);
show_panel(help_panel);
update_panels();
doupdate();
wgetch(help_window);
hide_panel(help_panel);
wgetch(background_window);
endwin();
}