-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo.c
188 lines (138 loc) · 4.02 KB
/
demo.c
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
nocurses.h - nocurses library demo
Compile and run with: $ make demo && ./demo
*/
#include <stdio.h>
#include "nocurses.h"
int i;
int waiting(){
printf("\n\nHit ENTER to continue...");
wait();
clrscr();
return 0;
}
int fancyline(void){
int j;
j = 0;
for(i=0;i<51;i++){
setfontcolor(j);
j++;
if (j == 8) j = 0;
printf(".");
}
setfontcolor(BLACK);
return 0;
}
int main(void) {
clrscr();
setfontbold(TRUE);
fancyline();
printf("\n\
_\n\
_ __ ___ ___ _ _ _ __ ___ ___ ___ | |__\n\
| '_ \\ / _ \\ / __| | | | '__/ __|/ _ \\/ __| | '_ \\\n\
| | | | (_) | (__| |_| | | \\__ \\ __/\\__ \\_| | | |\n\
|_| |_|\\___/ \\___|\\__,_|_| |___/\\___||___(_)_| |_|\n");
fancyline();
setfontbold(FALSE);
setfontcolor(WHITE);
printf("\n\n\nHello! Welcome to nocurses.h demo!\nLet me present you its features... \n");
waiting();
printf("The nocurses.h provides these set of functions:\n\n\
wait()\n\
clrscr()\n\
setfontcolor(COLOR_NAME)\n\
setbgrcolor(COLOR_NAME)\n\
gotoxy(XPOS,YPOS)\n\
setfontbold(STATE)\n\
setunderline(STATE)\n\
setblink(STATE)\n\
settitle(TITLE)\n\
setcurshape(SHAPE_NAME)\n\
gettermsize()\n\
getch()\n\
getche()\n\
clrline()\n\
resetcolors()\n");
waiting();
printf("I am using the wait() function to wait for your\ncommand.");
waiting();
printf("See it? The screen was cleared with the clrscr() function.");
waiting();
gotoxy(5, 6);
printf("Now I am here!");
gotoxy(10, 8);
printf("And now I am there!");
printf("\n\nJust use gotoxy(position x, position y) to move around!");
waiting();
for(i=0;i<8;i++){
setfontcolor(i);
printf("I can change font colors!\n");
}
printf("\nUse setfontcolor(COLOR_NAME) function!");
waiting();
for(i=0;i<8;i++){
setbgrcolor(i);
printf("I can also change background colors!\n");
}
setbgrcolor(BLUE);
setfontcolor(WHITE);
printf("\nYou just have to use setbgrcolor(COLOR_NAME) function!");
waiting();
printf("See it!?\n\nThis is what happens if you clear\n a screen with your new colors!");
waiting();
resetcolors();
clrscr();
printf("Now I used resetcolors()");
waiting();
struct termsize size = gettermsize();
printf("I can detect your terminal size.\n\nThis terminal is %d columns and %d rows, so one line should look like this:\n\n", size.cols, size.rows);
for (int i=0;i<size.cols;i++) {
printf("=");
}
waiting();
printf("I have getch() and getche()! Here is getch() until you press q:\n\nPress q to exit:");
while (getch() != 'q');
clrscr();
printf("Here is getche() until you press q:\n\nPress q to exit:");
while (getche() != 'q');
clrscr();
printf("Now some fancy stuff. \n\nThis may or may not work in your terminal emulator,\n so I am going to TRY stuff, ok?\n\n");
waiting();
setfontcolor(WHITE);
setbgrcolor(BLACK);
setfontbold(TRUE);
printf("BOLD is set to TRUE --> setfontbold(TRUE)\n\n");
waiting();
setfontbold(FALSE);
printf("BOLD is set to FALSE --> setfontbold(FALSE)\n\n");
waiting();
setunderline(TRUE);
printf("UNDERLINE is set to TRUE --> setunderline(TRUE)\n\n");
waiting();
setunderline(FALSE);
printf("UNDERLINE is set to FALSE --> setunderline(FALSE)\n\n");
waiting();
setblink(TRUE);
printf("Blinking cursor is set to TRUE --> setblink(TRUE)\n\n");
waiting();
setblink(FALSE);
printf("Blinking cursor is set to FALSE --> setblink(FALSE)\n\n");
waiting();
settitle("nocurses demo");
printf("Title is set to \"nocurses demo\" --> settitle(\"nocurses demo\")\n\n");
waiting();
setcurshape(BLOCK);
printf("Cursor is set to BLOCK --> setcurshape(BLOCK)\n\n");
waiting();
setcurshape(UNDERLINE);
printf("Cursor is set to UNDERLINE --> setcurshape(UNDERLINE)\n\n");
waiting();
setcurshape(BAR);
printf("Cursor is set to BAR --> setcurshape(BAR)\n\n");
waiting();
printf("\n\nThat's all! Simple nocurses.h\n\nContribute with it on https://github.com/LionyxML/nocurses/\n\n");
waiting();
clrscr();
return 0;
}