Skip to content

Commit c751881

Browse files
committed
'newtest' can now show mouse events (if -m switch is added). On-screen layout rearranged so it fits in 24x80 windows.
1 parent 8576c76 commit c751881

1 file changed

Lines changed: 30 additions & 19 deletions

File tree

demos/newtest.c

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <string.h>
3030
#include <stdio.h>
3131
#include <locale.h>
32+
#include <stdbool.h>
3233

3334
int PDC_write_screen_to_file( const char *filename, WINDOW *win);
3435

@@ -154,6 +155,7 @@ int main( int argc, char **argv)
154155
#endif
155156
{
156157
int quit = 0, i, use_slk = 1;
158+
bool show_mouse_moves = false;
157159
#ifdef PDCURSES
158160
bool blink_state = FALSE;
159161
int fmt = 0xa;
@@ -231,6 +233,9 @@ int main( int argc, char **argv)
231233
sscanf( argv[i] + 2, "%x", &unicode_offset);
232234
break;
233235
#endif
236+
case 'm':
237+
show_mouse_moves = true;
238+
break;
234239
default:
235240
printf( "Option '%s' unrecognized\n", argv[i]);
236241
break;
@@ -261,7 +266,7 @@ int main( int argc, char **argv)
261266
init_pair( 1, COLOR_WHITE, COLOR_BLACK);
262267
init_pair( 2, COLOR_BLACK, COLOR_YELLOW);
263268

264-
mousemask( ALL_MOUSE_EVENTS, NULL);
269+
mousemask( ALL_MOUSE_EVENTS | (show_mouse_moves ? REPORT_MOUSE_POSITION : 0), NULL);
265270
attrset( COLOR_PAIR( 1));
266271
while( !quit)
267272
{
@@ -345,24 +350,33 @@ int main( int argc, char **argv)
345350

346351
#endif
347352

353+
mvaddstr( 5, 1, " 0 1 2 3 4 5 6 7 8 9 a b c d e f");
354+
for( i = 0; i < 8; i++)
355+
{
356+
char buff[4];
357+
358+
sprintf( buff, "%02x",
359+
#ifdef HAVE_WIDE
360+
(unsigned)( i * 16 + unicode_offset) & 0xff);
361+
#else
362+
(unsigned)( i * 16 + 128) & 0xff);
363+
#endif
364+
mvaddstr( 6 + i, 1, buff);
365+
mvaddstr( 6 + i, 36, buff);
366+
}
348367
for( i = 0; i < 128; i++)
349368
{ /* Show extended characters: */
350-
char buff[6];
351369
#ifdef HAVE_WIDE
352-
wchar_t wbuff[3];
353-
354-
sprintf( buff, "%02x ",
355-
(unsigned)( i + unicode_offset) & 0xff);
356-
mvaddstr( 5 + i % 16, (i / 16) * 5, buff);
357-
wbuff[0] = (wchar_t)( i + unicode_offset);
358-
wbuff[1] = (wchar_t)' ';
359-
wbuff[2] = (wchar_t)0;
360-
addwstr( wbuff);
361-
#else
370+
wchar_t buff[2];
362371

363-
sprintf( buff, "%02x %c", i + 128, (char)(i + 128));
364-
mvaddstr( 5 + i % 16, (i / 16) * 5, buff);
372+
buff[0] = (wchar_t)( i + unicode_offset);
373+
buff[1] = '\0';
374+
mvaddwstr( 6 + i / 16, 4 + 2 * (i % 16), buff);
375+
#else
376+
move( 6 + i / 16, 4 + 2 * (i % 16));
377+
addch( i + 128);
365378
#endif
379+
addch( ' ');
366380
}
367381

368382
#if(CHTYPE_LONG >= 2) /* "non-standard" 64-bit chtypes */
@@ -406,8 +420,6 @@ int main( int argc, char **argv)
406420
for( i = 0; i < 6; i++)
407421
{
408422
static const wchar_t spanish[] = L"Espa\xf1ol";
409-
const int line0 = line + i / 3;
410-
const int col = 5 + 25 * (i % 3);
411423

412424
static const wchar_t russian[] = {0x0420, 0x0443, 0x0441, 0x0441,
413425
0x043a, 0x0438, 0x0439, L' ', 0x044f, 0x0437, 0x044b, 0x043a, 0};
@@ -430,15 +442,14 @@ int main( int argc, char **argv)
430442
static const wchar_t *texts[6] = { spanish, russian, greek,
431443
georgian, fullwidth, combining_marks};
432444

433-
if( line0 < ymax && col < xmax)
434-
mvaddnwstr( line0, 5 + 25 * (i % 3), texts[i], xmax - col);
445+
mvaddwstr( 15 + i / 2, 2 + 20 * (i % 2), texts[i]);
435446
}
436447
#if(CHTYPE_LONG >= 2) /* "non-standard" 64-bit chtypes */
437448
mvaddch( line - 1, 58, (chtype)0x1d11e);
438449
#endif /* U+1D11E = musical symbol G clef */
439450
line += 2;
440451
#endif
441-
mvaddstr( line, 1, curses_version( ));
452+
mvaddstr( 19, 1, curses_version( ));
442453

443454
#ifdef MAYBE_TRY_THIS_SOMEWHERE_ELSE
444455
mvaddstr( 1, COL3, "Click on cursor descriptions to");

0 commit comments

Comments
 (0)