Adding a argument in bshrc to enable/disable terminal color

This commit is contained in:
Lluciocc 2026-04-19 00:35:30 +02:00
parent 01aa75a4f1
commit 75c3e4c27a
2 changed files with 40 additions and 5 deletions

View file

@ -42,4 +42,4 @@ HISTORY_SIZE=200
GLOB=true
COMPLETE=true
SUGGEST=true
TERMINAL_COLOR=false

View file

@ -19,7 +19,7 @@
#define TAB_CLOSE_W 12
#define TAB_CLOSE_PAD 6
#define MAX_TABS 4
#define TTY_READ_CHUNK 512T
#define TTY_READ_CHUNK 512
#define LINE_MAX 256
typedef struct {
@ -48,6 +48,8 @@ typedef struct {
int saved_row;
int saved_col;
bool colors_enabled;
// for color
char current_input[LINE_MAX];
int input_len;
@ -726,6 +728,19 @@ static void tab_init(TerminalSession *s, int tty_id, int bsh_pid) {
s->current_input[0] = 0;
session_reset_colors(s);
scrollback_init(s);
char value[64];
if (read_config_value("TERMINAL_COLOR", value, sizeof(value)) == 0) {
if (strcmp(value, "1") == 0 || strcmp(value, "true") == 0) {
s->colors_enabled = true;
} else {
s->colors_enabled = false;
}
} else {
s->colors_enabled = false;
}
session_clear(s);
}
@ -867,6 +882,10 @@ static bool command_starts_with(const char *prefix) {
}
static void update_input_color(TerminalSession *s) {
if (!s->colors_enabled) {
return;
}
if (s->input_len == 0) {
s->input_color = 0xFFFFFFFF;
return;
@ -876,12 +895,12 @@ static void update_input_color(TerminalSession *s) {
int i = 0;
while (i < s->input_len &&
s->current_input[i] != ' ' &&
i < 63) {
s->current_input[i] != ' ' &&
s->current_input[i] != '\t' &&
i < 63) {
cmd[i] = s->current_input[i];
i++;
}
cmd[i] = 0;
if (command_exists(cmd)) {
s->input_color = 0xFF55FF55; // green
@ -929,6 +948,22 @@ static void handle_key(gui_event_t *ev) {
return;
}
if (!ctrl) {
if (c == KEY_BACKSPACE) {
if (s->input_len > 0) {
s->input_len--;
s->current_input[s->input_len] = 0;
}
} else if (c >= 32 && c < 127) {
if (s->input_len < LINE_MAX - 1) {
s->current_input[s->input_len++] = c;
s->current_input[s->input_len] = 0;
}
}
update_input_color(s);
}
if (c == KEY_ENTER) {
s->input_color = 0xFFFFFFFF;
s->input_len = 0;