mirror of
https://github.com/BoredDevNL/BoredOS.git
synced 2026-05-15 10:48:38 +00:00
Adding a argument in bshrc to enable/disable terminal color
This commit is contained in:
parent
01aa75a4f1
commit
75c3e4c27a
2 changed files with 40 additions and 5 deletions
|
|
@ -42,4 +42,4 @@ HISTORY_SIZE=200
|
|||
GLOB=true
|
||||
COMPLETE=true
|
||||
SUGGEST=true
|
||||
|
||||
TERMINAL_COLOR=false
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -877,11 +896,11 @@ static void update_input_color(TerminalSession *s) {
|
|||
|
||||
while (i < s->input_len &&
|
||||
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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue