3 * David Leonard <d@openbsd.org>, 1999. Public domain.
5 * $OpenBSD: display.c,v 1.4 2002/02/19 19:39:36 millert Exp $
12 #if !defined(USE_CURSES)
19 #define _USE_OLD_CURSES_
24 static struct termios saved_tty;
26 char screen[SCREEN_HEIGHT][SCREEN_WIDTH2];
27 char blanks[SCREEN_WIDTH];
32 * Handle stop and start signals
41 mvcur(cur_row, cur_col, HEIGHT, 0);
46 (void) fflush(stdout);
47 tcsetattr(0, TCSADRAIN, &__orig_termios);
48 (void) kill(getpid(), SIGSTOP);
49 (void) signal(SIGTSTP, tstp);
50 tcsetattr(0, TCSADRAIN, &saved_tty);
55 _puts(tgoto(CM, cur_row, cur_col));
56 display_redraw_screen();
57 (void) fflush(stdout);
69 if (!isatty(0) || (term = getenv("TERM")) == NULL)
70 errx(1, "no terminal type");
76 tcgetattr(0, &saved_tty);
80 (void) signal(SIGTSTP, tstp);
101 (void) fflush(stdout);
106 * clear to end of line, without moving cursor
109 display_clear_eol(void)
112 tputs(CE, 1, __cputchar);
114 fwrite(blanks, sizeof (char), SCREEN_WIDTH - cur_col, stdout);
115 if (COLS != SCREEN_WIDTH)
116 mvcur(cur_row, SCREEN_WIDTH, cur_row, cur_col);
118 mvcur(cur_row + 1, 0, cur_row, cur_col);
120 mvcur(cur_row, SCREEN_WIDTH - 1, cur_row, cur_col);
122 memcpy(&screen[cur_row][cur_col], blanks, SCREEN_WIDTH - cur_col);
127 * put one character on the screen, move the cursor right one,
131 display_put_ch(char ch)
134 fprintf(stderr, "r,c,ch: %d,%d,%d", cur_row, cur_col, ch);
137 screen[cur_row][cur_col] = ch;
139 if (++cur_col >= COLS) {
143 if (++cur_row >= LINES)
150 * put a string of characters on the screen
153 display_put_str(const char *s)
160 * display_clear_the_screen:
161 * clear the screen; move cursor to top left
164 display_clear_the_screen(void)
168 if (blanks[0] == '\0')
169 for (i = 0; i < SCREEN_WIDTH; i++)
173 tputs(CL, LINES, __cputchar);
174 for (i = 0; i < SCREEN_HEIGHT; i++)
175 memcpy(screen[i], blanks, SCREEN_WIDTH);
177 for (i = 0; i < SCREEN_HEIGHT; i++) {
178 mvcur(cur_row, cur_col, i, 0);
183 mvcur(cur_row, cur_col, 0, 0);
185 cur_row = cur_col = 0;
193 display_move(int y, int x)
195 mvcur(cur_row, cur_col, y, x);
205 display_getyx(int *yp, int *xp)
218 tcsetattr(0, TCSADRAIN, &__orig_termios);
225 * return a character from the screen
228 display_atyx(int y, int x)
234 * display_redraw_screen:
238 display_redraw_screen(void)
242 mvcur(cur_row, cur_col, 0, 0);
243 for (i = 0; i < SCREEN_HEIGHT - 1; i++) {
244 fwrite(screen[i], sizeof (char), SCREEN_WIDTH, stdout);
245 if (COLS > SCREEN_WIDTH || (COLS == SCREEN_WIDTH && !AM))
248 fwrite(screen[SCREEN_HEIGHT - 1], sizeof (char), SCREEN_WIDTH - 1,
250 mvcur(SCREEN_HEIGHT - 1, SCREEN_WIDTH - 1, cur_row, cur_col);
253 #else /* CURSES */ /* --------------------------------------------------- */
273 display_refresh(void)
279 display_clear_eol(void)
285 display_put_ch(char c)
291 display_put_str(const char *s)
297 display_clear_the_screen(void)
305 display_move(int y, int x)
311 display_getyx(int *yp, int *xp)
313 getyx(stdscr, *yp, *xp);
323 display_atyx(int y, int x)
328 display_getyx(&oy, &ox);
329 c = mvwinch(stdscr, y, x) & 0x7f;
330 display_move(oy, ox);
335 display_redraw_screen(void)
337 clearok(stdscr, TRUE);
342 display_iserasechar(char ch)
344 return ch == erasechar();
348 display_iskillchar(char ch)
350 return ch == killchar();