-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisp.c
72 lines (64 loc) · 1.47 KB
/
disp.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
#include <ncurses.h>
#include "hash.h"
#include "disp.h"
#define DISP 8
void init() {
initscr();
cbreak();
keypad(stdscr, TRUE);
curs_set(0);
mvprintw(0, 0, "(i)nsert, (d)elete, or (g)et?");
mvprintw(1, 0, "Key: ");
mvprintw(2, 0, "Value: ");
noecho();
}
void end() {
clear();
endwin();
}
char in() {
curs_set(0);
noecho();
char c = getch();
move(1, 5);
clrtoeol();
move(2, 7);
clrtoeol();
return c;
}
void display(Table *t) {
unsigned int i, j;
char *key, *val, *col;
move(3, 0);
clrtobot();
for(i = 0; i < t->size / DISP; ++i) {
for(j = 0; j < (DISP / t->size ? t->size : DISP); ++j) {
key = (t->e[i*DISP+j]) ? t->e[i*DISP+j]->key : "E";
val = (t->e[i*DISP+j]) ? (char *)t->e[i*DISP+j]->val : "-";
col = (t->e[i*DISP+j]) ? (t->e[i*DISP+j]->col ? "t" : "f") : "";
mvprintw(j*2+4, i*20, "%d", i*DISP+j);
mvprintw(j*2+4, i*20+3, "%-15s", key);
mvprintw(j*2+5, i*20+1, "%s", col);
mvprintw(j*2+5, i*20+3, "%-15s", val);
}
}
mvprintw(21, 0, "size: %d", t->size);
mvprintw(21, 10, "entries: %d", t->entries);
}
void dispval(char *val) {
mvprintw(2, 7, "%s", val);
}
void getkeyval(char *key, char *val) {
echo();
curs_set(1);
move(1, 5);
getstr(key);
move(2, 7);
getstr(val);
}
void getkey(char *key) {
echo();
curs_set(1);
move(1, 5);
getstr(key);
}