mirror of
https://github.com/BoredDevNL/BoredOS.git
synced 2026-05-15 10:48:38 +00:00
Removing ref to the history
This commit is contained in:
parent
e1864b2a66
commit
01aa75a4f1
1 changed files with 5 additions and 90 deletions
|
|
@ -19,9 +19,8 @@
|
||||||
#define TAB_CLOSE_W 12
|
#define TAB_CLOSE_W 12
|
||||||
#define TAB_CLOSE_PAD 6
|
#define TAB_CLOSE_PAD 6
|
||||||
#define MAX_TABS 4
|
#define MAX_TABS 4
|
||||||
#define TTY_READ_CHUNK 512
|
#define TTY_READ_CHUNK 512T
|
||||||
#define HISTORY_MAX 64
|
#define LINE_MAX 256
|
||||||
#define HISTORY_LINE_MAX 256
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char c;
|
char c;
|
||||||
|
|
@ -49,12 +48,8 @@ typedef struct {
|
||||||
int saved_row;
|
int saved_row;
|
||||||
int saved_col;
|
int saved_col;
|
||||||
|
|
||||||
|
// for color
|
||||||
char history[HISTORY_MAX][HISTORY_LINE_MAX];
|
char current_input[LINE_MAX];
|
||||||
int history_count;
|
|
||||||
int history_index;
|
|
||||||
|
|
||||||
char current_input[HISTORY_LINE_MAX];
|
|
||||||
int input_len;
|
int input_len;
|
||||||
} TerminalSession;
|
} TerminalSession;
|
||||||
|
|
||||||
|
|
@ -726,8 +721,7 @@ static void tab_init(TerminalSession *s, int tty_id, int bsh_pid) {
|
||||||
s->ansi_param_count = 0;
|
s->ansi_param_count = 0;
|
||||||
s->saved_row = 0;
|
s->saved_row = 0;
|
||||||
s->saved_col = 0;
|
s->saved_col = 0;
|
||||||
s->history_count = 0;
|
|
||||||
s->history_index = 0;
|
|
||||||
s->input_len = 0;
|
s->input_len = 0;
|
||||||
s->current_input[0] = 0;
|
s->current_input[0] = 0;
|
||||||
session_reset_colors(s);
|
session_reset_colors(s);
|
||||||
|
|
@ -935,91 +929,12 @@ static void handle_key(gui_event_t *ev) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// enter = save command
|
|
||||||
if (c == KEY_ENTER) {
|
if (c == KEY_ENTER) {
|
||||||
if (s->input_len > 0) {
|
|
||||||
strcpy(s->history[s->history_count % HISTORY_MAX], s->current_input);
|
|
||||||
s->history_count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->input_color = 0xFFFFFFFF;
|
s->input_color = 0xFFFFFFFF;
|
||||||
s->history_index = s->history_count;
|
|
||||||
s->input_len = 0;
|
s->input_len = 0;
|
||||||
s->current_input[0] = 0;
|
s->current_input[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storing command logic
|
|
||||||
// Backspace
|
|
||||||
else if (c == KEY_BACKSPACE) {
|
|
||||||
if (s->input_len > 0) {
|
|
||||||
s->input_len--;
|
|
||||||
s->current_input[s->input_len] = 0;
|
|
||||||
}
|
|
||||||
update_input_color(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Normal char
|
|
||||||
else if (c >= 32 && c < 127) {
|
|
||||||
if (s->input_len < HISTORY_LINE_MAX - 1) {
|
|
||||||
s->current_input[s->input_len++] = c;
|
|
||||||
s->current_input[s->input_len] = 0;
|
|
||||||
}
|
|
||||||
update_input_color(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restoring command logic
|
|
||||||
if (c == KEY_UP) {
|
|
||||||
if (s->history_count > 0 && s->history_index > 0) {
|
|
||||||
s->history_index--;
|
|
||||||
|
|
||||||
char *cmd = s->history[s->history_index % HISTORY_MAX];
|
|
||||||
|
|
||||||
// remove actual line
|
|
||||||
for (int i = 0; i < s->input_len; i++) {
|
|
||||||
char bs = 8;
|
|
||||||
sys_tty_write_in(s->tty_id, &bs, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(s->current_input, cmd);
|
|
||||||
s->input_len = strlen(cmd);
|
|
||||||
update_input_color(s);
|
|
||||||
|
|
||||||
sys_tty_write_in(s->tty_id, cmd, s->input_len);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == KEY_DOWN) {
|
|
||||||
if (s->history_index < s->history_count - 1) {
|
|
||||||
s->history_index++;
|
|
||||||
|
|
||||||
char *cmd = s->history[s->history_index % HISTORY_MAX];
|
|
||||||
|
|
||||||
for (int i = 0; i < s->input_len; i++) {
|
|
||||||
char bs = 8;
|
|
||||||
sys_tty_write_in(s->tty_id, &bs, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(s->current_input, cmd);
|
|
||||||
s->input_len = strlen(cmd);
|
|
||||||
update_input_color(s);
|
|
||||||
|
|
||||||
sys_tty_write_in(s->tty_id, cmd, s->input_len);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// we want an empty line if we go back and nothing in history
|
|
||||||
for (int i = 0; i < s->input_len; i++) {
|
|
||||||
char bs = 8;
|
|
||||||
sys_tty_write_in(s->tty_id, &bs, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
s->history_index = s->history_count;
|
|
||||||
s->input_len = 0;
|
|
||||||
s->current_input[0] = 0;
|
|
||||||
s->input_color = 0xFFFFFFFF;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sys_tty_write_in(s->tty_id, &c, 1);
|
sys_tty_write_in(s->tty_id, &c, 1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue