-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.c
More file actions
66 lines (55 loc) · 1.64 KB
/
Copy pathexample.c
File metadata and controls
66 lines (55 loc) · 1.64 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
#include <locale.h> // for setlocale
#include <ncurses.h> // for ncurses
#define ST_STYLE 2 // 0 for custom, 1 for simple, 2 for unicode
#include "simpletables.h" // for simpletables
int main(void) {
// Initialize ncurses
setlocale(LC_ALL, "");
initscr();
start_color();
init_pair(1, COLOR_BLACK, COLOR_CYAN);
wbkgd(stdscr, COLOR_PAIR(1));
refresh();
// Create a table
// "Example" is the title of the table
// 80 is the width of the table
// 3 is the number of columns
st_table *table = st_create_table("Example", 80, 5);
// Check if table is ok
if (!table) {
endwin();
perror("Failed to create table");
return 1;
}
// Set the column names
// table is the table
// 0 is the column number
// "C1" is the name of the column
// 0.2 is the width modifier of the column
st_set_column(table, 0, "C1", 0.2);
st_set_column(table, 1, "C2", 0.2);
st_set_column(table, 2, "C3", 0.2);
st_set_column(table, 3, "C4", 0.2);
st_set_column(table, 4, "C5", 0.2);
// Add a rows
// table is the table
// {"1", "2", "3", ...} is the row
st_add_row(table, (char *[]){"1", "2", "3", "4", "5"});
st_add_row(table, (char *[]){"6", "7", "8", "9", "10"});
// Create style
st_style *style = st_create_style(".", ".", ".", ".", ".", ".", ".", ".", ".",
".", ".", false);
// Print the table with default style
st_print(table);
// Print the table with custom style
st_print_styled(table, style);
// Free the table
st_free(table);
// Free the style
st_free_style(style);
// End ncurses
printw("Press any key to exit...");
getch();
endwin();
return 0;
}