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