Skip to content

Commit 8c27364

Browse files
committed
support changing $TERM with -term command line arg
1 parent 5af86d5 commit 8c27364

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ static int opt_use_embedded_font_for_keyboard = 0;
1717

1818
static const Uint32 BUTTON_HELD_DELAY = 150; // milliseconds between button triggers when held
1919

20-
/* TERM value */
21-
char termname[] = "xterm";
20+
/* TERM value - defaults to xterm-256color but can be overridden */
21+
char *termname = NULL; /* Will be set in main() - initialized to default if not overridden */
2222

2323
unsigned int tabspaces = 4;
2424

src/main.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "keyboard.h"
3030
#include "vt100.h"
3131

32-
#define USAGE "Simple Terminal\nusage: simple-terminal [-h] [-scale 2.0] [-font font.ttf] [-fontsize 14] [-fontshade 0|1|2] [-rotate 0|90|180|270] [-o file] [-q] [-r command ...]\n"
32+
#define USAGE "Simple Terminal\nusage: simple-terminal [-h] [-scale 2.0] [-font font.ttf] [-fontsize 14] [-fontshade 0|1|2] [-rotate 0|90|180|270] [-term xterm-256color|xterm|linux|vt100...] [-o file] [-q] [-r command ...]\n"
3333

3434
/* Arbitrary sizes */
3535
#define DRAW_BUF_SIZ 20 * 1024
@@ -147,6 +147,7 @@ SDL_Thread *thread = NULL;
147147
char **opt_cmd = NULL;
148148
int opt_cmd_size = 0;
149149
char *opt_io = NULL;
150+
char *opt_term = NULL; /* override TERM environment variable */
150151

151152
static int embedded_font_name = 1; // 1 or 2
152153
static volatile int thread_should_exit = 0;
@@ -1282,6 +1283,15 @@ int main(int argc, char *argv[]) {
12821283
}
12831284
continue;
12841285
}
1286+
if (strcmp(argv[i], "-term") == 0) {
1287+
if (++i < argc) {
1288+
opt_term = argv[i];
1289+
} else {
1290+
fprintf(stderr, "Missing argument for -term\n");
1291+
die(USAGE);
1292+
}
1293+
continue;
1294+
}
12851295
if (strcmp(argv[i], "-useEmbeddedFontForKeyboard") == 0) {
12861296
if (++i < argc) {
12871297
opt_use_embedded_font_for_keyboard = atoi(argv[i]);
@@ -1327,6 +1337,13 @@ int main(int argc, char *argv[]) {
13271337
int content_h = main_window.surface ? main_window.surface->h : main_window.height;
13281338
t_new((content_w - borderpx) / main_window.char_width, (content_h - borderpx) / main_window.char_height);
13291339
}
1340+
1341+
if (opt_term != NULL) {
1342+
termname = opt_term; /* User-specified override */
1343+
} else {
1344+
termname = "xterm-256color"; /* Default: 256-color support */
1345+
}
1346+
13301347
tty_new();
13311348
create_tty_thread();
13321349
scale_to_size((int)(main_window.width / opt_scale), (int)(main_window.height / opt_scale));

src/vt100.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern unsigned int defaultfg;
2020
extern unsigned int defaultbg;
2121
extern unsigned int tabspaces;
2222
extern char default_shell[];
23-
extern char termname[];
23+
extern char *termname;
2424
extern int scrollback_lines;
2525

2626
/* External variables from main.c */

0 commit comments

Comments
 (0)