9 #include "memory_manage.h"
15 int lineback, lineforward;
18 static void range_set(void *obj, int value)
20 struct cui_gauge *t = obj;
25 #define PRINTF wprintf
26 #define VPRINTF vwprintf
29 #define VPRINTF vprintf
31 static void console_move(int line)
38 CONSOLE_SCREEN_BUFFER_INFO info;
39 c = GetStdHandle(STD_OUTPUT_HANDLE);
40 if(GetConsoleScreenBufferInfo(c, &info) == 0){
41 //command.com, cygwin shell, mingw shell
43 PRINTF(wgT("\x1b[%dA"), -line);
50 PRINTF(wgT("\x1b[%dB"), line - 1);
51 // PRINTF(wgT("\x1b[%dB"), line - 1);
56 info.dwCursorPosition.X = 0;
57 info.dwCursorPosition.Y += line;
58 SetConsoleCursorPosition(c, info.dwCursorPosition);
62 PRINTF(wgT("\x1b[%dA\x1b[35D"), -line);
64 PRINTF(wgT("\x1b[%dB\x1b[35D"), line);
70 static void draw(const struct cui_gauge *t)
72 const int barnum = 16;
73 const int unit = t->range / barnum;
74 int igeta = t->value / unit;
75 wgChar bar[barnum + 3 + 1];
78 assert(igeta <= barnum);
79 PRINTF(wgT("%s 0x%06x/0x%06x "), t->name, (int) t->value, (int) t->range);
81 for(i = 0; i < igeta; i++){
87 for(; i < barnum; i++){
100 static void value_set(void *obj, void *d, int value)
102 struct cui_gauge *t = (struct cui_gauge *) obj;
107 PRINTF(wgT("%s skip"), t->name);
112 static void value_add(void *obj, void *d, int value)
114 struct cui_gauge *t = (struct cui_gauge *) obj;
116 console_move(t->lineback);
118 console_move(t->lineforward);
121 static void name_set(void *obj, const wgChar *name, int lineforward, int lineback)
123 struct cui_gauge *t = (struct cui_gauge *) obj;
125 t->lineforward = lineforward;
126 t->lineback = lineback;
129 static void label_set(void *obj, const wgChar *format, ...)
132 const struct cui_gauge *t = (const struct cui_gauge *) obj;
134 va_start(list, format);
135 console_move(t->lineback);
136 PRINTF(wgT("%s "), t->name);
137 VPRINTF(format, list);
138 console_move(t->lineforward);
142 void cui_gauge_new(struct gauge *t, const wgChar *name, int lineforward, int lineback)
144 t->bar = Malloc(sizeof(struct cui_gauge));
146 name_set(t->bar, name, lineforward, lineback);
147 t->range_set = range_set;
148 t->value_set = value_set;
149 t->value_add = value_add;
150 t->label_set = label_set;
153 void cui_gauge_destory(struct gauge *t)