@@ -13,23 +13,26 @@ namespace ch = std::chrono;
1313
1414class ui {
1515 public:
16- WINDOW* win = nullptr ;
17-
1816 short menu (const string& title, const vector<string>& choices) {
1917 noecho ();
2018 curs_set (false );
21-
22- short choice = 0 , input = 0 , maxLen = 0 ;
23-
24- mvwprintw (win, 0 , 0 , " %s" , title.c_str ());
25- for (int i = 1 ; i < choices.size (); i++) {
26- short len = choices[i].length ();
27- if (len > maxLen) maxLen = len;
19+ short choice = 0 , input = 0 , maxWidth = 0 , maxHeight = choices.size (),
20+ minWidth = 15 ;
21+ for (const string& str : choices) {
22+ short len = str.length ();
23+ if (len > maxWidth) maxWidth = len;
2824 }
29- wattron (win, A_STANDOUT);
30- mvwprintw (win, 1 , 1 , " %s%*c" , choices[0 ].c_str (),
31- maxLen - choices[0 ].length () + 1 , ' \0 ' );
32- wattroff (win, A_STANDOUT);
25+ short titleLen = title.length ();
26+ if (titleLen > maxWidth) maxWidth = titleLen;
27+ if (minWidth > maxWidth) maxWidth = minWidth;
28+ short y, x;
29+ getmaxyx (stdscr, y, x);
30+ WINDOW* win =
31+ newwin (maxHeight + 2 , maxWidth + 2 , y / 2 - (maxHeight + 2 ) / 2 ,
32+ x / 2 - (maxWidth + 2 ) / 2 );
33+ keypad (win, true );
34+ box (win, 0 , 0 );
35+ mvwprintw (win, 0 , 1 , " %s" , title.c_str ());
3336 for (int i = 1 ; i < choices.size (); i++)
3437 mvwprintw (win, i + 1 , 1 , " %s" , choices[i].c_str ());
3538 do {
@@ -39,17 +42,18 @@ class ui {
3942 if (choice > 0 ) {
4043 mvwprintw (win, choice + 1 , 1 , " %s%*c" ,
4144 choices[choice].c_str (),
42- maxLen - choices[choice].length () + 1 , ' \0 ' );
45+ maxWidth - choices[choice].length () + 1 ,
46+ ' \0 ' );
4347 --choice;
4448 }
45-
4649 break ;
4750 case ' j' :
4851 case KEY_DOWN:
4952 if (choice < choices.size () - 1 ) {
5053 mvwprintw (win, choice + 1 , 1 , " %s%*c" ,
5154 choices[choice].c_str (),
52- maxLen - choices[choice].length () + 1 , ' \0 ' );
55+ maxWidth - choices[choice].length () + 1 ,
56+ ' \0 ' );
5357 ++choice;
5458 }
5559 break ;
@@ -58,28 +62,29 @@ class ui {
5862 }
5963 wattron (win, A_STANDOUT);
6064 mvwprintw (win, choice + 1 , 1 , " %s%*c" , choices[choice].c_str (),
61- maxLen - choices[choice].length () + 1 , ' \0 ' );
65+ maxWidth - choices[choice].length () + 1 , ' \0 ' );
6266 wattroff (win, A_STANDOUT);
6367 } while ((input = wgetch (win)) != ' \n ' );
64-
65- clear ();
68+ werase (win);
69+ wrefresh (win);
70+ delwin (win);
6671 echo ();
6772 curs_set (true );
6873 return choice;
6974 }
7075
7176 void progressBar (const long & prog, const long & total) {
7277 short y, x;
73- getyx (win , y, x);
78+ getyx (stdscr , y, x);
7479 const int len = 30 ;
7580 short percent = ceil (float (len) / total * prog);
7681 wchar_t str[len + 1 ];
7782 for (short i = 0 ; i < percent; i++) str[i] = L' \u2588 ' ;
7883 for (short i = percent; i < len; i++) str[i] = L' \u2592 ' ;
7984 str[len] = L' \0 ' ;
80- mvwprintw (win, y, 1 , " |%ls|" , str);
81- if (prog == total) wmove (win, y + 1 , 1 );
82- wrefresh (win );
85+ mvprintw ( y, 0 , " |%ls|" , str);
86+ if (prog == total) move ( y + 1 , 0 );
87+ refresh ( );
8388 }
8489
8590 void notification (const string& title, const vector<string>& message) {
@@ -94,19 +99,20 @@ class ui {
9499 if (titleLen > maxWidth) maxWidth = titleLen;
95100 maxWidth += 4 ;
96101 getmaxyx (stdscr, y, x);
97- WINDOW* ntfwin =
98- newwin (maxHeight + 2 , maxWidth, y / 2 - (maxHeight + 2 ) / 2 ,
99- x / 2 - maxWidth / 2 );
100- box (ntfwin, 0 , 0 );
101- mvwprintw (ntfwin, 0 , maxWidth / 2 - titleLen / 2 , " %s" , title.c_str ());
102+ WINDOW* win = newwin (maxHeight + 2 , maxWidth,
103+ y / 2 - (maxHeight + 2 ) / 2 , x / 2 - maxWidth / 2 );
104+ box (win, 0 , 0 );
105+ mvwprintw (win, 0 , maxWidth / 2 - titleLen / 2 , " %s" , title.c_str ());
102106 for (short i = 0 ; i < maxHeight; i++)
103- mvwprintw (ntfwin, i + 1 , maxWidth / 2 - message[i].length () / 2 ,
104- " %s" , message[i].c_str ());
105- wrefresh (ntfwin);
106- wgetch (ntfwin);
107- werase (ntfwin);
108- wrefresh (ntfwin);
109- delwin (ntfwin);
107+ mvwprintw (win, i + 1 , maxWidth / 2 - message[i].length () / 2 , " %s" ,
108+ message[i].c_str ());
109+ wrefresh (win);
110+
111+ wgetch (win);
112+ werase (win);
113+ wrefresh (win);
114+ delwin (win);
115+
110116 echo ();
111117 curs_set (true );
112118 }
@@ -115,32 +121,22 @@ class ui {
115121 setlocale (LC_ALL, " " );
116122 initscr ();
117123 cbreak ();
118- short y, x;
119- getmaxyx (stdscr, y, x);
120- win = newwin (y, x, 0 , 0 );
121- scrollok (win, true );
122- keypad (win, true );
123- box (win, 0 , 0 );
124- refresh ();
125- wrefresh (win);
126- }
127- ~ui () {
128- delwin (win);
129- endwin ();
124+ scrollok (stdscr, true );
125+ keypad (stdscr, true );
130126 }
127+ ~ui () { endwin (); }
131128};
132129
133130int main () {
134131 ui ui;
135- // ui.menu("Kurwa:", {"sex", "boobies", "AAA"});
136- ui.notification (" KURWA" , {" SEEEEEEEEEEEEEEEEEEX" ,
137- " SEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEX" , " SEX" });
132+ ui.menu (" KURWA:" , {" Boobies" , " SEEEX" , " DICK" });
138133 int n = 29 ;
139- for (int i = 0 ; i < 30 ; i++) {
134+ for (int i = 0 ; i < 25 ; i++) {
140135 for (int j = 0 ; j <= n; j++) {
141- this_thread::sleep_for (ch::milliseconds (10 ));
136+ this_thread::sleep_for (ch::milliseconds (1 ));
142137 ui.progressBar (j, n);
143138 }
144139 }
140+ ui.notification (" SUCKSEX!!!" , {" Go Fuck Yourself :3" });
145141 getch ();
146142}
0 commit comments