2 * Copyright (C) 2017 IBM Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
21 #include "talloc/talloc.h"
24 #define pb_log(...) printf(__VA_ARGS__)
25 #define pb_debug(...) printf(__VA_ARGS__)
28 * Several example terminal commands, see:
29 * https://vt100.net/docs/vt100-ug/chapter3.html
31 static char identify_rsp[] = {033, 0133, 077, 061, 073, 060, 0143, '\0'};
32 static char decdwl[] = {033, 043, 066, '\0'};
33 static char attrs[] = {033, 0133, 060, 073, 064, 073, 065, 0155, '\0'};
34 static char cursor[] = {033, 070, '\0'};
35 static char conf_test[] = {033, 0133, 062, 073, 061, 0171, '\0'};
36 static char status[] = {033, 0133, 060, 0156, '\0'};
37 static char erase_screen[] = {033, 0133, 062, 0112, '\0'};
38 static char status_ok_rsp[] = {033, 0133, 064, 0156, '\0'};
39 static char garbage[] = {001, 002, 003, 004, '\0'};
40 static char esc_garbage[] = {033, 002, 003, 004, '\0'};
43 static signed char getch(void)
45 if (!ptr || *ptr == '\0')
50 #include "ui/ncurses/console-codes.c"
57 ctx = talloc_new(NULL);
59 ptr = &identify_rsp[1];
60 printf("Identity response\n");
61 seq = handle_control_sequence(ctx, identify_rsp[0]);
62 assert(strncmp(seq, identify_rsp, strlen(identify_rsp)) == 0);
66 seq = handle_control_sequence(ctx, decdwl[0]);
67 assert(strncmp(seq, decdwl, strlen(decdwl)) == 0);
69 printf("Attributes\n");
71 seq = handle_control_sequence(ctx, attrs[0]);
72 assert(strncmp(seq, attrs, strlen(attrs)) == 0);
74 printf("Reset Cursor\n");
76 seq = handle_control_sequence(ctx, cursor[0]);
77 assert(strncmp(seq, cursor, strlen(cursor)) == 0);
79 printf("Confidence Test\n");
81 seq = handle_control_sequence(ctx, conf_test[0]);
82 assert(strncmp(seq, conf_test, strlen(conf_test)) == 0);
86 seq = handle_control_sequence(ctx, status[0]);
87 assert(strncmp(seq, status, strlen(status)) == 0);
89 printf("Erase Screen\n");
90 ptr = &erase_screen[1];
91 seq = handle_control_sequence(ctx, erase_screen[0]);
92 assert(strncmp(seq, erase_screen, strlen(erase_screen)) == 0);
94 printf("Status Response\n");
95 ptr = &status_ok_rsp[1];
96 seq = handle_control_sequence(ctx, status_ok_rsp[0]);
97 assert(strncmp(seq, status_ok_rsp, strlen(status_ok_rsp)) == 0);
101 seq = handle_control_sequence(ctx, garbage[0]);
104 printf("ESC then Garbage\n");
105 ptr = &esc_garbage[1];
106 confused = talloc_asprintf(ctx, "%c%c...", 033, 002);
107 seq = handle_control_sequence(ctx, esc_garbage[0]);
108 assert(strncmp(seq, confused, strlen(confused)) == 0);