Commit | Line | Data |
---|---|---|
d0aeaf5a DF |
1 | /* |
2 | * Copyright (c) 1983 Regents of the University of California. | |
f9ac90b4 KB |
3 | * All rights reserved. |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that this notice is preserved and that due credit is given | |
7 | * to the University of California at Berkeley. The name of the University | |
8 | * may not be used to endorse or promote products derived from this | |
9 | * software without specific prior written permission. This software | |
10 | * is provided ``as is'' without express or implied warranty. | |
d0aeaf5a DF |
11 | */ |
12 | ||
963ce42e | 13 | #ifndef lint |
f9ac90b4 KB |
14 | static char sccsid[] = "@(#)display.c 5.2 (Berkeley) %G%"; |
15 | #endif /* not lint */ | |
a07b5a38 | 16 | |
963ce42e MK |
17 | /* |
18 | * The window 'manager', initializes curses and handles the actual | |
a07b5a38 MK |
19 | * displaying of text |
20 | */ | |
a07b5a38 MK |
21 | #include "talk.h" |
22 | ||
963ce42e MK |
23 | xwin_t my_win; |
24 | xwin_t his_win; | |
25 | WINDOW *line_win; | |
a07b5a38 | 26 | |
963ce42e | 27 | int curses_initialized = 0; |
a07b5a38 | 28 | |
963ce42e MK |
29 | /* |
30 | * max HAS to be a function, it is called with | |
31 | * a argument of the form --foo at least once. | |
32 | */ | |
a07b5a38 | 33 | max(a,b) |
963ce42e | 34 | int a, b; |
a07b5a38 | 35 | { |
963ce42e MK |
36 | |
37 | return (a > b ? a : b); | |
a07b5a38 MK |
38 | } |
39 | ||
40 | /* | |
41 | * Display some text on somebody's window, processing some control | |
42 | * characters while we are at it. | |
43 | */ | |
a07b5a38 | 44 | display(win, text, size) |
963ce42e MK |
45 | register xwin_t *win; |
46 | register char *text; | |
47 | int size; | |
a07b5a38 | 48 | { |
963ce42e MK |
49 | register int i; |
50 | char cch; | |
51 | ||
52 | for (i = 0; i < size; i++) { | |
53 | if (*text == '\n') { | |
54 | xscroll(win, 0); | |
55 | text++; | |
56 | continue; | |
57 | } | |
58 | /* erase character */ | |
59 | if (*text == win->cerase) { | |
60 | wmove(win->x_win, win->x_line, max(--win->x_col, 0)); | |
61 | getyx(win->x_win, win->x_line, win->x_col); | |
62 | waddch(win->x_win, ' '); | |
63 | wmove(win->x_win, win->x_line, win->x_col); | |
64 | getyx(win->x_win, win->x_line, win->x_col); | |
65 | text++; | |
66 | continue; | |
67 | } | |
68 | /* | |
69 | * On word erase search backwards until we find | |
70 | * the beginning of a word or the beginning of | |
71 | * the line. | |
72 | */ | |
73 | if (*text == win->werase) { | |
74 | int endcol, xcol, i, c; | |
75 | ||
76 | endcol = win->x_col; | |
77 | xcol = endcol - 1; | |
78 | while (xcol >= 0) { | |
79 | c = readwin(win->x_win, win->x_line, xcol); | |
80 | if (c != ' ') | |
81 | break; | |
82 | xcol--; | |
83 | } | |
84 | while (xcol >= 0) { | |
85 | c = readwin(win->x_win, win->x_line, xcol); | |
86 | if (c == ' ') | |
87 | break; | |
88 | xcol--; | |
89 | } | |
90 | wmove(win->x_win, win->x_line, xcol + 1); | |
91 | for (i = xcol + 1; i < endcol; i++) | |
92 | waddch(win->x_win, ' '); | |
93 | wmove(win->x_win, win->x_line, xcol + 1); | |
94 | getyx(win->x_win, win->x_line, win->x_col); | |
95 | continue; | |
96 | } | |
97 | /* line kill */ | |
98 | if (*text == win->kill) { | |
99 | wmove(win->x_win, win->x_line, 0); | |
100 | wclrtoeol(win->x_win); | |
101 | getyx(win->x_win, win->x_line, win->x_col); | |
102 | text++; | |
103 | continue; | |
104 | } | |
105 | if (*text == '\f') { | |
106 | if (win == &my_win) | |
107 | wrefresh(curscr); | |
108 | text++; | |
109 | continue; | |
110 | } | |
111 | if (win->x_col == COLS-1) { | |
112 | /* check for wraparound */ | |
113 | xscroll(win, 0); | |
114 | } | |
115 | if (*text < ' ' && *text != '\t') { | |
116 | waddch(win->x_win, '^'); | |
117 | getyx(win->x_win, win->x_line, win->x_col); | |
118 | if (win->x_col == COLS-1) /* check for wraparound */ | |
119 | xscroll(win, 0); | |
120 | cch = (*text & 63) + 64; | |
121 | waddch(win->x_win, cch); | |
122 | } else | |
123 | waddch(win->x_win, *text); | |
124 | getyx(win->x_win, win->x_line, win->x_col); | |
125 | text++; | |
a07b5a38 | 126 | } |
963ce42e | 127 | wrefresh(win->x_win); |
a07b5a38 MK |
128 | } |
129 | ||
130 | /* | |
963ce42e MK |
131 | * Read the character at the indicated position in win |
132 | */ | |
a07b5a38 | 133 | readwin(win, line, col) |
963ce42e | 134 | WINDOW *win; |
a07b5a38 | 135 | { |
963ce42e MK |
136 | int oldline, oldcol; |
137 | register int c; | |
138 | ||
139 | getyx(win, oldline, oldcol); | |
140 | wmove(win, line, col); | |
141 | c = winch(win); | |
142 | wmove(win, oldline, oldcol); | |
143 | return (c); | |
a07b5a38 MK |
144 | } |
145 | ||
146 | /* | |
963ce42e MK |
147 | * Scroll a window, blanking out the line following the current line |
148 | * so that the current position is obvious | |
149 | */ | |
a07b5a38 | 150 | xscroll(win, flag) |
963ce42e MK |
151 | register xwin_t *win; |
152 | int flag; | |
a07b5a38 | 153 | { |
963ce42e MK |
154 | |
155 | if (flag == -1) { | |
156 | wmove(win->x_win, 0, 0); | |
157 | win->x_line = 0; | |
158 | win->x_col = 0; | |
159 | return; | |
160 | } | |
161 | win->x_line = (win->x_line + 1) % win->x_nlines; | |
a07b5a38 | 162 | win->x_col = 0; |
963ce42e MK |
163 | wmove(win->x_win, win->x_line, win->x_col); |
164 | wclrtoeol(win->x_win); | |
165 | wmove(win->x_win, (win->x_line + 1) % win->x_nlines, win->x_col); | |
166 | wclrtoeol(win->x_win); | |
167 | wmove(win->x_win, win->x_line, win->x_col); | |
a07b5a38 | 168 | } |