Increase the size of the 'message' buffer, which is currently
[sgt/tweak] / curses.c
CommitLineData
11825bd4 1#include "tweak.h"
2
6e182d98 3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#include <ctype.h>
7#include <assert.h>
6e182d98 8#include <curses.h>
9
6e182d98 10int display_rows, display_cols;
11
12void display_beep(void)
13{
14 beep();
15}
16
17static void get_screen_size (void) {
18 getmaxyx(stdscr, display_rows, display_cols);
19}
20
21void display_setup(void)
22{
23 initscr();
24 noecho();
25 keypad(stdscr, 0);
26 raw();
27 move(0,0);
28 refresh();
29 get_screen_size();
1610a3c6 30 if (has_colors()) {
6e182d98 31 start_color();
1610a3c6 32 use_default_colors();
33 }
6e182d98 34}
35
36void display_cleanup(void)
37{
38 endwin();
39}
40
41void display_moveto(int y, int x)
42{
43 wmove(stdscr, y, x);
44}
45
46void display_refresh(void)
47{
48 refresh();
49}
50
51void display_write_str(char *str)
52{
53 waddstr(stdscr, str);
54}
55
56void display_write_chars(char *str, int len)
57{
58 waddnstr(stdscr, str, len);
59}
60
61#define MAXCOLOURS 32
62int attrs[MAXCOLOURS];
63
ef7de295 64void display_define_colour(int colour, int fg, int bg, int reverse)
6e182d98 65{
66 static int colours[8] = {
67 COLOR_BLACK,
68 COLOR_RED,
69 COLOR_GREEN,
70 COLOR_YELLOW,
71 COLOR_BLUE,
72 COLOR_MAGENTA,
73 COLOR_CYAN,
74 COLOR_WHITE,
75 };
76
1610a3c6 77 if (fg < 0 && bg < 0) {
78 attrs[colour] = 0;
79 } else {
ef7de295 80 assert(colour >= 0 && colour < MAXCOLOURS);
1610a3c6 81 assert(!(bg & ~7)); /* bold backgrounds are nonportable */
ef7de295 82 if (colour < COLOR_PAIRS-2) {
83 init_pair(colour+1, colours[fg & 7], colours[bg]);
84 attrs[colour] = (fg & 8 ? A_BOLD : 0) | COLOR_PAIR(colour+1);
85 } else {
86 /* can't allocate a colour pair, so we just use b&w attrs */
87 attrs[colour] = (fg & 8 ? A_BOLD : 0) | (reverse ? A_REVERSE : 0);
88 }
1610a3c6 89 }
6e182d98 90}
91
92void display_set_colour(int colour)
93{
94 wattrset(stdscr, attrs[colour]);
95}
96
97void display_clear_to_eol(void)
98{
99 wclrtoeol(stdscr);
100}
101
102int last_getch = ERR;
103
104int display_getkey(void)
105{
106 int ret;
107 extern void schedule_update(void);
108
109 if (last_getch != ERR) {
110 int ret = last_getch;
111 last_getch = ERR;
112 return ret;
113 }
114 while (1) {
115 ret = getch();
116 if (ret == KEY_RESIZE) {
117 schedule_update();
118 continue;
119 }
120 return ret;
121 }
122}
123
124int display_input_to_flush(void)
125{
126 int ret;
127 if (last_getch != ERR)
128 return TRUE;
129
130 nodelay(stdscr, 1);
131 ret = getch();
132 nodelay(stdscr, 0);
133 if (ret == ERR)
134 return FALSE;
135
136 last_getch = ret;
137 return TRUE;
138}
139
140void display_post_error(void)
141{
142 /* I don't _think_ we need do anything here */
143}
144
145void display_recheck_size(void)
146{
147 get_screen_size ();
148}