svn up
[tore.git] / pytx / txops.c
blobf4e7e5d392c1c92ff7c69aaa0e6536b2bfe34884
1 #include <ncurses.h>
2 #include <assert.h>
3 #include <signal.h>
4 #include <sys/ioctl.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <signal.h>
8 #include <assert.h>
9 #include <sys/ioctl.h>
10 #include "txops.h"
11 #include "txlist.h"
13 char *tx_text_blank(char *t, int w) {
14 char *b;
16 b = malloc(sizeof(char) * w);
17 assert(b);
19 memset(b, ' ', w);
20 if (t) memcpy(b, t, MIN(strlen(t), w));
21 b[w-1] = 0;
22 return b;
25 void tx_box(WINDOW *win) {
26 int winwidth;
27 int winheight;
29 scrollok(win, 0);
31 getmaxyx(win, winheight, winwidth);
32 winheight--;
33 winwidth--;
35 mvwaddch(win, 0, 0, ACS_ULCORNER);
36 mvwaddch(win, winheight, 0, ACS_LLCORNER);
37 mvwaddch(win, 0, winwidth, ACS_URCORNER);
38 mvwaddch(win, winheight, winwidth, ACS_LRCORNER);
40 mvwhline(win, 0, 1, ACS_HLINE, winwidth - 1);
41 mvwhline(win, winheight, 1, ACS_HLINE, winwidth - 1);
42 mvwvline(win, 1, 0, ACS_VLINE, winheight - 1);
43 mvwvline(win, 1, winwidth, ACS_VLINE, winheight - 1);
44 doupdate();
47 void tx_ungetc(int c) {
48 ungetch(c);
51 void tx_resize(void) {
52 struct winsize ws;
53 int r;
54 r = ioctl(0, TIOCGWINSZ, &ws);
55 assert(r != -1);
57 r = resizeterm(ws.ws_row, ws.ws_col);
58 assert(r != -1);
61 void signals(int sig) {
62 switch (sig) {
63 case SIGWINCH: tx_resize(); break;
67 void tx_init(void) {
68 initscr();
69 cbreak();
70 noecho();
71 nonl();
72 keypad(stdscr, 1);
73 curs_set(0);
74 clear();
75 signal(SIGWINCH, signals);
76 //signal(SIGINT, sighandler);
78 /* set to globals to NULL */
79 tx_obj_root = NULL;
80 tx_obj_focus = NULL;
83 void tx_free(void) {
84 endwin();
87 void tx_stdwinset(WINDOW * win) {
88 meta(win, TRUE);
89 keypad(win, TRUE);
90 notimeout(win, 0);
91 scrollok(win, 1);
94 void tx_refresh_screen(void) {
95 endwin();
96 doupdate();
97 curs_set(0);