2 * $Id: inserts.c,v 1.5 2003/08/09 22:07:06 tom Exp $
4 * Demonstrate the winsstr() and winsch functions.
5 * Thomas Dickey - 2002/10/19
12 static int margin = (2 * TABSIZE) - 1;
15 legend(WINDOW *win, char *buffer, int length)
19 "The Strings/Chars displays should match. Enter any characters.\n");
21 "Use down-arrow or ^N to repeat on the next line, 'q' to exit.\n");
23 wprintw(win, "Inserted %d characters <%s>", length, buffer);
27 ColOf(char *buffer, int length)
32 for (n = 0, result = margin + 1; n < length; ++n) {
33 int ch = UChar(buffer[n]);
36 /* actually newline should clear the remainder of the line
37 * and move to the next line - but that seems a little awkward
48 result += (TABSIZE - (result % TABSIZE));
64 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
77 (void) cbreak(); /* take input chars one at a time, no wait for \n */
78 (void) noecho(); /* don't echo input */
82 work = newwin(limit, COLS, 0, 0);
83 show = newwin(4, COLS, limit + 1, 0);
86 for (col = margin + 1; col < COLS; col += TABSIZE)
87 mvwvline(work, row, col, '.', limit - 2);
90 mvwvline(work, row, margin, ACS_VLINE, limit - 2);
91 mvwvline(work, row, margin + 1, ACS_VLINE, limit - 2);
94 mvwaddstr(work, 1, 2, "String");
95 mvwaddstr(work, limit + 1, 2, "Chars");
98 buffer[length = 0] = '\0';
99 legend(show, buffer, length);
105 * Show the characters inserted in color, to distinguish from those that
110 init_pair(1, COLOR_WHITE, COLOR_BLUE);
111 wbkgdset(work, COLOR_PAIR(1) | ' ');
114 while ((ch = wgetch(work)) != 'q') {
115 wmove(work, row, margin + 1);
121 /* put the whole string in, all at once */
122 mvwinsstr(work, row, margin + 1, buffer);
124 /* do the corresponding single-character insertion */
125 for (col = 0; col < length; ++col) {
126 mvwinsch(work, limit + row, ColOf(buffer, col), buffer[col]);
136 if (ch <= 0 || ch > 255) {
140 buffer[length++] = ch;
141 buffer[length] = '\0';
142 /* put the string in, one character at a time */
145 ColOf(buffer, length - 1), buffer + length - 1);
147 /* do the corresponding single-character insertion */
150 ColOf(buffer, length - 1), ch);
153 legend(show, buffer, length);
161 ExitProgram(EXIT_SUCCESS);