mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Cleanup
This commit is contained in:
parent
1fb0cad7b9
commit
70f69899fc
3 changed files with 52 additions and 1 deletions
23
src/print.c
23
src/print.c
|
|
@ -20,7 +20,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "print.h"
|
#include "print.h"
|
||||||
|
|
||||||
|
|
@ -50,3 +52,24 @@ void print_init_ansi_formatting()
|
||||||
sprintf(ansi_format, "\e[1;38;5;%dm", option.color);
|
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("");
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,14 @@ extern char ansi_format[];
|
||||||
print_tainted = false; \
|
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
|
#ifdef DEBUG
|
||||||
#define tio_debug_printf(format, args...) \
|
#define tio_debug_printf(format, args...) \
|
||||||
fprintf (stdout, "[debug] " format, ## args)
|
fprintf (stdout, "[debug] " format, ## args)
|
||||||
|
|
@ -87,3 +95,4 @@ extern char ansi_format[];
|
||||||
void print_hex(char c);
|
void print_hex(char c);
|
||||||
void print_normal(char c);
|
void print_normal(char c);
|
||||||
void print_init_ansi_formatting(void);
|
void print_init_ansi_formatting(void);
|
||||||
|
void tio_printf_array(const char *array);
|
||||||
|
|
|
||||||
21
src/tty.c
21
src/tty.c
|
|
@ -74,13 +74,14 @@
|
||||||
#define KEY_G 0x67
|
#define KEY_G 0x67
|
||||||
#define KEY_H 0x68
|
#define KEY_H 0x68
|
||||||
#define KEY_L 0x6C
|
#define KEY_L 0x6C
|
||||||
|
#define KEY_SHIFT_L 0x4C
|
||||||
#define KEY_P 0x70
|
#define KEY_P 0x70
|
||||||
#define KEY_Q 0x71
|
#define KEY_Q 0x71
|
||||||
#define KEY_S 0x73
|
#define KEY_S 0x73
|
||||||
#define KEY_T 0x74
|
#define KEY_T 0x74
|
||||||
#define KEY_U 0x55
|
#define KEY_U 0x55
|
||||||
#define KEY_V 0x76
|
#define KEY_V 0x76
|
||||||
#define KEY_SHIFT_L 0x4C
|
#define KEY_Z 0x7a
|
||||||
|
|
||||||
#define NORMAL 0
|
#define NORMAL 0
|
||||||
#define HEX 1
|
#define HEX 1
|
||||||
|
|
@ -92,6 +93,20 @@ enum line_mode_t
|
||||||
LINE_PULSE
|
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;
|
bool interactive_mode = true;
|
||||||
|
|
||||||
static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old;
|
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);
|
tio_printf("tio v%s", VERSION);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case KEY_Z:
|
||||||
|
tio_printf_array(random_array);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Ignore unknown ctrl-t escaped keys */
|
/* Ignore unknown ctrl-t escaped keys */
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue