8 #include "memory_manage.h"
14 int lineback, lineforward;
17 static void range_set(void *obj, int value)
19 struct cui_gauge *t = obj;
23 static void console_move(int line)
30 CONSOLE_SCREEN_BUFFER_INFO info;
31 c = GetStdHandle(STD_OUTPUT_HANDLE);
32 if(GetConsoleScreenBufferInfo(c, &info) == 0){
33 //command.com, cygwin shell, mingw shell
35 printf("\x1b[%dA", -line);
42 printf("\x1b[%dB", line - 1);
43 // printf("\x1b[%dB", line - 1);
48 info.dwCursorPosition.X = 0;
49 info.dwCursorPosition.Y += line;
50 SetConsoleCursorPosition(c, info.dwCursorPosition);
54 printf("\x1b[%dA\x1b[35D", -line);
56 printf("\x1b[%dB\x1b[35D", line);
62 static void draw(const struct cui_gauge *t)
64 const int barnum = 16;
65 const int unit = t->range / barnum;
66 int igeta = t->value / unit;
67 char bar[barnum + 3 + 1];
70 assert(igeta <= barnum);
71 printf("%s 0x%06x/0x%06x ", t->name, (int) t->value, (int) t->range);
73 for(i = 0; i < igeta; i++){
79 for(; i < barnum; i++){
92 static void value_set(void *obj, void *d, int value)
94 struct cui_gauge *t = (struct cui_gauge *) obj;
102 static void value_add(void *obj, void *d, int value)
104 struct cui_gauge *t = (struct cui_gauge *) obj;
106 console_move(t->lineback);
108 console_move(t->lineforward);
111 static void name_set(void *obj, const char *name, int lineforward, int lineback)
113 struct cui_gauge *t = (struct cui_gauge *) obj;
115 t->lineforward = lineforward;
116 t->lineback = lineback;
119 static void label_set(void *obj, const char *format, ...)
122 const struct cui_gauge *t = (const struct cui_gauge *) obj;
124 va_start(list, format);
125 console_move(t->lineback);
126 printf("%s ", t->name);
127 vprintf(format, list);
128 console_move(t->lineforward);
132 void cui_gauge_new(struct gauge *t, const char *name, int lineforward, int lineback)
134 t->bar = Malloc(sizeof(struct cui_gauge));
136 name_set(t->bar, name, lineforward, lineback);
137 t->range_set = range_set;
138 t->value_set = value_set;
139 t->value_add = value_add;
140 t->label_set = label_set;
143 void cui_gauge_destory(struct gauge *t)