-
Notifications
You must be signed in to change notification settings - Fork 8
/
bd_global.c
105 lines (79 loc) · 2 KB
/
bd_global.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
#include <string.h>
#include <bedd.h>
#include <time.h>
#include <io.h>
void bd_global_draw(void) {
io_cursor(0, 0);
io_printf(IO_INVERT " bedd r02 " IO_SHADOW_2 " ");
struct tm *tm_time = localtime(&bd_time);
char buffer[100];
strftime(buffer, 100, " %d %b %Y, %H:%M:%S ", tm_time);
for (int i = 0; i < bd_width - (12 + (int)(strlen(buffer))); i++) {
io_printf("\u2550");
}
io_printf(" " IO_INVERT "%s" IO_SHADOW_1, buffer);
io_cursor(0, 1);
for (int i = 0; i < bd_view_count; i++) {
int width = ((bd_width * (i + 1)) / bd_view_count) - ((bd_width * i) / bd_view_count);
if (i == bd_view) {
io_printf(IO_INVERT);
}
if (bd_config.column_tiny) {
width -= 1;
} else {
io_printf("\u2576");
width -= 4;
}
char title[256];
strcpy(title, bd_views[i].title);
int length = strlen(title);
if (length > width) {
memset(title + (width - 3), '.', 3);
title[width] = '\0';
width = 0;
} else {
width -= length;
}
io_printf("%s", title);
while (width--) {
io_printf("\u2500");
}
if (bd_config.column_tiny) {
io_printf("\u2574");
} else {
io_printf("\u2500\u00D7\u2574");
}
if (i == bd_view) {
io_printf(IO_SHADOW_1);
}
}
io_printf(IO_NORMAL);
io_cursor(0, 2);
}
int bd_global_click(int x, int y) {
if (y < 1) {
return 0;
}
int start_x = 0;
for (int i = 0; i < bd_view_count; i++) {
int width = ((bd_width * (i + 1)) / bd_view_count) - ((bd_width * i) / bd_view_count);
int end_x = start_x + width;
if (x >= start_x && x < end_x) {
if (x == end_x - 2) {
bd_view_remove(bd_views + i);
if (bd_view && bd_view >= i) {
bd_view--;
}
return 1;
}
if (i == bd_view) {
return 0;
} else {
bd_view = i;
return 1;
}
}
start_x = end_x;
}
return 0;
}