5
#include <grass/glocale.h>
7
#include "local_proto.h"
15
static Window *make_window(int top, int bottom, int left, int right)
19
if (top < 0 || bottom >= LINES || left < 0 || right >= COLS
20
|| bottom - top <= 1 || right - left <= 1) {
22
G_warning(_("make_window(%d,%d,%d,%d): illegal screen values."),
23
top, bottom, left, right);
27
window = (Window *) G_malloc(sizeof(Window));
29
window->bottom = bottom;
31
window->right = right;
32
Curses_clear_window(window);
36
int Begin_curses(void)
38
/* should only be called once at program outset */
40
initscr(); /* initialize curses standard screens */
41
raw(); /* set tty modes via curses calls */
47
/* make a window to save stdscr */
48
save = newwin(LINES, COLS, 0, 0);
50
/* make_window (nrows, ncols, start_row, start_col) */
51
INFO_WINDOW = make_window(0, LINES - 4, COLS / 2, COLS - 1);
52
MENU_WINDOW = make_window(0, LINES - 4, 0, COLS / 2);
53
PROMPT_WINDOW = make_window(LINES - 4, LINES - 1, 0, COLS - 1);
61
/* should only be called upon program exit */
63
clear(); /* clear the screen */
65
endwin(); /* let curses reset the tty now */
69
int Suspend_curses(void)
71
overwrite(stdscr, save);
79
int Resume_curses(void)
83
overwrite(save, stdscr);
88
int Curses_allow_interrupts(int ok)
98
int Curses_clear_window(Window * window)
104
for (y = window->top + 1; y < window->bottom; y++) {
105
move(y, x = window->left + 1);
106
while (x++ < window->right)
109
Curses_outline_window(window);
114
int Curses_outline_window(Window * window)
118
move(window->top, x = window->left + 1);
119
while (x++ < window->right)
121
move(window->bottom, x = window->left + 1);
122
while (x++ < window->right)
124
for (y = window->top + 1; y < window->bottom; y++) {
125
move(y, window->left);
127
move(y, window->right);
130
move(window->top, window->left);
132
move(window->top, window->right);
134
move(window->bottom, window->left);
136
if (window->bottom < LINES - 1 || window->right < COLS - 1) {
137
move(window->bottom, window->right);
143
int Curses_write_window(Window * window, int line, int col, char *message)
148
G_message(_("%s"), message);
151
if (line <= 0 || line >= window->bottom - window->top)
153
if (col <= 0 || col >= window->right - window->left)
155
move(y = window->top + line, x = window->left + col);
156
while (*message != 0 && *message != '\n' && x < window->right) {
161
if (*message == '\n')
162
for (i = x; i < window->right; i++)
170
int Curses_replot_screen(void)
181
int Curses_prompt_gets(char *prompt, char *answer)
190
Curses_write_window(PROMPT_WINDOW, 1, 1, "\n");
191
Curses_write_window(PROMPT_WINDOW, 1, 1, prompt);
196
if (c == '\n' || c == '\r')
200
if (c > '\037' && c < '\177') { /* octal codes: accept space to '~' */
201
if (x < PROMPT_WINDOW->right) {
209
if (c == '\b' || c == '\177') { /* backspace or DEL (decimal 8,127) */
232
int Curses_getch(int with_echo)
243
if (c == interrupt_char) {
253
Curses_replot_screen();