diff --git a/src/print.c b/src/print.c index 359c078..cf130f0 100644 --- a/src/print.c +++ b/src/print.c @@ -20,7 +20,9 @@ */ #include +#include #include +#include #include "options.h" #include "print.h" @@ -50,3 +52,24 @@ void print_init_ansi_formatting() sprintf(ansi_format, "\e[1;38;5;%dm", option.color); } } + +void tio_printf_array(const char *array) +{ + int i = 0, j = 0; + + tio_printf(""); + + while (array[i]) + { + if (array[i] == '\n') + { + const char *line = &array[j]; + char *line_copy = strndup(line, i-j); + tio_printf_raw("%s\r", line_copy); + free(line_copy); + j = i; + } + i++; + } + tio_printf(""); +} diff --git a/src/print.h b/src/print.h index c212a7c..24a02b9 100644 --- a/src/print.h +++ b/src/print.h @@ -74,6 +74,14 @@ extern char ansi_format[]; print_tainted = false; \ } +#define tio_printf_raw(format, args...) \ +{ \ + if (print_tainted) \ + putchar('\n'); \ + ansi_printf_raw("[%s] " format, current_time(), ## args); \ + print_tainted = false; \ +} + #ifdef DEBUG #define tio_debug_printf(format, args...) \ fprintf (stdout, "[debug] " format, ## args) @@ -87,3 +95,4 @@ extern char ansi_format[]; void print_hex(char c); void print_normal(char c); void print_init_ansi_formatting(void); +void tio_printf_array(const char *array); diff --git a/src/tty.c b/src/tty.c index 43cfb91..e653c6e 100644 --- a/src/tty.c +++ b/src/tty.c @@ -74,13 +74,14 @@ #define KEY_G 0x67 #define KEY_H 0x68 #define KEY_L 0x6C +#define KEY_SHIFT_L 0x4C #define KEY_P 0x70 #define KEY_Q 0x71 #define KEY_S 0x73 #define KEY_T 0x74 #define KEY_U 0x55 #define KEY_V 0x76 -#define KEY_SHIFT_L 0x4C +#define KEY_Z 0x7a #define NORMAL 0 #define HEX 1 @@ -92,6 +93,20 @@ enum line_mode_t LINE_PULSE }; +const char random_array[] = +{ +0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x28, 0x20, 0x28, 0x0A, 0x20, +0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x29, 0x20, 0x29, 0x0A, 0x20, +0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, +0x2E, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7C, 0x20, 0x20, 0x20, +0x20, 0x20, 0x20, 0x7C, 0x5D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, +0x5C, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2F, 0x0A, 0x20, 0x20, 0x20, 0x20, +0x20, 0x20, 0x20, 0x20, 0x60, 0x2D, 0x2D, 0x2D, 0x2D, 0x27, 0x0A, 0x0A, 0x54, +0x69, 0x6D, 0x65, 0x20, 0x66, 0x6F, 0x72, 0x20, 0x61, 0x20, 0x63, 0x6F, 0x66, +0x66, 0x65, 0x65, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x21, 0x0A, 0x20, 0x0A, +0x00 +}; + bool interactive_mode = true; static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old; @@ -517,6 +532,10 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c tio_printf("tio v%s", VERSION); break; + case KEY_Z: + tio_printf_array(random_array); + break; + default: /* Ignore unknown ctrl-t escaped keys */ break;