Allow switching rendering mode in terminal on the fly

This commit is contained in:
K. Lange 2018-05-08 17:16:58 +09:00
parent 4c873f9fde
commit 8ccbcb001c
7 changed files with 35 additions and 2 deletions

View File

@ -952,6 +952,14 @@ uint32_t shell_cmd_set(int argc, char * argv[]) {
printf("\033[1556;%sz", argv[2]);
fflush(stdout);
return 0;
} else if (!strcmp(argv[1], "sdf")) {
if (argc < 3) {
fprintf(stderr, "%s %s [sdf enabled, 1 = yes]\n", argv[0], argv[1]);
return 1;
}
printf("\033[1557;%sz", argv[2]);
fflush(stdout);
return 0;
} else if (!strcmp(argv[1], "size")) {
if (argc < 4) {
fprintf(stderr, "%s %s [width] [height]\n", argv[0], argv[1]);

View File

@ -136,6 +136,10 @@ static void set_term_font_size(float s) {
/* do nothing */
}
static void set_term_font_mode(int i) {
/* do nothing */
}
/* Returns the lower of two shorts */
uint16_t min(uint16_t a, uint16_t b) {
return (a < b) ? a : b;
@ -742,6 +746,7 @@ term_callbacks_t term_callbacks = {
unsupported_int,
term_set_csr_show,
set_term_font_size,
set_term_font_mode,
};
void reinit(int send_sig) {

View File

@ -64,7 +64,6 @@ uint16_t term_height = 0; /* Height of the terminal (in cells) */
uint16_t font_size = 13; /* Font size according to SDF library */
uint16_t char_width = 9; /* Width of a cell in pixels */
uint16_t char_height = 20; /* Height of a cell in pixels */
uint16_t char_offset = 0; /* Offset of the font within the cell */
int csr_x = 0; /* Cursor X */
int csr_y = 0; /* Cursor Y */
term_cell_t * term_buffer = NULL; /* The terminal cell buffer */
@ -143,6 +142,11 @@ static void set_term_font_gamma(float s) {
reinit(1);
}
static void set_term_font_mode(int i) {
_use_sdf = i;
reinit(1);
}
/* Returns the lower of two shorts */
int32_t min(int32_t a, int32_t b) {
return (a < b) ? a : b;
@ -1251,6 +1255,7 @@ term_callbacks_t term_callbacks = {
term_get_cell_height,
term_set_csr_show,
set_term_font_gamma,
set_term_font_mode,
};
void reinit(int send_sig) {
@ -1263,6 +1268,9 @@ void reinit(int send_sig) {
char_height *= font_scaling;
char_width *= font_scaling;
}
} else {
char_width = 9;
char_height = 20;
}
int old_width = term_width;

View File

@ -34,6 +34,7 @@ typedef struct {
int (*get_cell_height)(void);
void (*set_csr_on)(int);
void (*set_font_gamma)(float);
void (*set_font_mode)(int);
} term_callbacks_t;
typedef struct {

View File

@ -14,6 +14,7 @@ static void _spin_lock(volatile int * foo) { return; }
static void _spin_unlock(volatile int * foo) { return; }
# define rgba(r,g,b,a) (((uint32_t)a * 0x1000000) + ((uint32_t)r * 0x10000) + ((uint32_t)g * 0x100) + ((uint32_t)b * 0x1))
# define rgb(r,g,b) rgba(r,g,b,0xFF)
# define atof(i) (0.0f)
#include <toaru/termemu.h>
#else
#include <stdlib.h>
@ -190,6 +191,10 @@ static void _ansi_put(term_state_t * s, char c) {
callbacks->set_font_gamma(atof(argv[1]));
}
break;
case 1557:
if (argc > 1) {
callbacks->set_font_mode(atoi(argv[1]));
}
default:
break;
}

View File

@ -94,8 +94,8 @@ static void _libc_init(void) {
void pre_main(int (*main)(int,char**), int argc, char * argv[]) {
if (!__get_argv()) {
/* Statically loaded, must set __argv so __get_argv() works */
__argv = argv;
_libc_init();
}
_init();
_exit(main(argc, argv));

View File

@ -131,6 +131,10 @@ static void term_clear(int i) {
memset(textmemptr, 0x00, sizeof(unsigned short) * 80 * 25);
}
static void set_term_font_mode(int i) {
/* Do nothing */
}
int unsupported_int(void) { return 0; }
void unsupported(int x, int y, char * data) { }
@ -151,6 +155,8 @@ term_callbacks_t term_callbacks = {
unsupported_int,
unsupported_int,
term_set_csr_show,
set_term_font_size,
set_term_font_mode,
};