From 29eb6a601f953b98a42b6abe42f7c3ba115b670b Mon Sep 17 00:00:00 2001 From: BjossiAlfreds Date: Wed, 31 Jul 2024 21:40:11 +0000 Subject: [PATCH 1/5] Q_strdel and Q_strins utility functions --- src/common/header/shared.h | 7 ++++++ src/common/shared/shared.c | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/common/header/shared.h b/src/common/header/shared.h index a15a2340..f0755955 100644 --- a/src/common/header/shared.h +++ b/src/common/header/shared.h @@ -329,6 +329,13 @@ char *Q_strlwr(char *s); int Q_strlcpy(char *dst, const char *src, int size); int Q_strlcat(char *dst, const char *src, int size); +/* Delete n characters from s starting at index i */ +void Q_strdel(char *s, size_t i, size_t n); + +/* Insert src into dest starting at index i, total, n is the total size of the buffer */ +/* Returns length of src on success, 0 if there is not enough space in dest for src */ +size_t Q_strins(char *dest, const char *src, size_t i, size_t n); + /* ============================================= */ /* Unicode wrappers that also make sure it's a regular file around fopen(). */ diff --git a/src/common/shared/shared.c b/src/common/shared/shared.c index 33a1e2e1..792ffde8 100644 --- a/src/common/shared/shared.c +++ b/src/common/shared/shared.c @@ -1144,6 +1144,52 @@ Q_strlcat(char *dst, const char *src, int size) return (d - dst) + Q_strlcpy(d, src, size); } +void +Q_strdel(char *s, size_t i, size_t n) +{ + size_t len; + + if (!n) + { + return; + } + + len = strlen(s); + + if (i >= len || n > (len - i)) + { + return; + } + + memmove(s + i, s + i + n, len - i); + s[len - n] = '\0'; +} + +size_t +Q_strins(char *dest, const char *src, size_t i, size_t n) +{ + size_t dlen; + size_t slen; + + if (!src || *src == '\0') + { + return 0; + } + + slen = strlen(src); + dlen = strlen(dest); + + if (i > dlen || (dlen + slen + 1) > n) + { + return 0; + } + + memmove(dest + i + slen, dest + i, dlen - i + 1); + memcpy(dest + i, src, slen); + + return slen; +} + /* * An unicode compatible fopen() Wrapper for Windows. */ From ced8be673e2332f63d781f627ae0a69cfa633d22 Mon Sep 17 00:00:00 2001 From: BjossiAlfreds Date: Wed, 31 Jul 2024 21:41:40 +0000 Subject: [PATCH 2/5] CTRL+letter actions in console + cursor can be inside edit line --- src/client/cl_console.c | 38 ++++++++++------ src/client/cl_keyboard.c | 93 ++++++++++++++++++++++++++-------------- src/client/input/sdl2.c | 16 +++++++ src/client/input/sdl3.c | 16 +++++++ 4 files changed, 117 insertions(+), 46 deletions(-) diff --git a/src/client/cl_console.c b/src/client/cl_console.c index 827ad6db..f92a4b3b 100644 --- a/src/client/cl_console.c +++ b/src/client/cl_console.c @@ -471,6 +471,8 @@ Con_DrawInput(void) int i; float scale; char *text; + char ch; + int txtlen; if (cls.key_dest == key_menu) { @@ -486,28 +488,38 @@ Con_DrawInput(void) scale = SCR_GetConsoleScale(); text = key_lines[edit_line]; - /* add the cursor frame */ - text[key_linepos] = 10 + ((int)(cls.realtime >> 8) & 1); - - /* fill out remainder with spaces */ - for (i = key_linepos + 1; i < con.linewidth; i++) - { - text[i] = ' '; - } - /* prestep if horizontally scrolling */ if (key_linepos >= con.linewidth) { text += 1 + key_linepos - con.linewidth; } + txtlen = strlen(text); + for (i = 0; i < con.linewidth; i++) { - Draw_CharScaled(((i + 1) << 3) * scale, con.vislines - 22 * scale, text[i], scale); - } + if (i == key_linepos) + { + if (cls.realtime & 8) + { + ch = 11; + } + else + { + ch = (text[i] == '\0') ? 10 : text[i]; + } + } + else if (i >= txtlen) + { + ch = ' '; + } + else + { + ch = text[i]; + } - /* remove cursor */ - key_lines[edit_line][key_linepos] = 0; + Draw_CharScaled(((i + 1) << 3) * scale, con.vislines - 22 * scale, ch, scale); + } } /* diff --git a/src/client/cl_keyboard.c b/src/client/cl_keyboard.c index 5b00a0a3..c4ef5d44 100644 --- a/src/client/cl_keyboard.c +++ b/src/client/cl_keyboard.c @@ -29,6 +29,8 @@ #include "header/client.h" +void IN_GetClipboardText(char *out, size_t n); + static cvar_t *cfg_unbindall; /* @@ -346,6 +348,8 @@ CompleteMapNameCommand(void) void Key_Console(int key) { + char txt[2], cliptext[256]; + /* * Ignore keypad in console to prevent duplicate * entries through key presses processed as a @@ -375,13 +379,25 @@ Key_Console(int key) break; } - if (key == 'l') + if (keydown[K_CTRL]) { - if (keydown[K_CTRL]) + if (key == 'l') { Cbuf_AddText("clear\n"); return; } + + if (key == 'v') + { + IN_GetClipboardText(cliptext, sizeof(cliptext)); + + if (*cliptext != '\0') + { + key_linepos += Q_strins(key_lines[edit_line], cliptext, key_linepos, MAXCMDLINE); + } + + return; + } } if ((key == K_ENTER) || (key == K_KP_ENTER)) @@ -423,9 +439,7 @@ Key_Console(int key) return; } - if ((key == K_BACKSPACE) || (key == K_LEFTARROW) || - (key == K_KP_LEFTARROW) || - ((key == 'h') && (keydown[K_CTRL]))) + if (key == K_LEFTARROW) { if (key_linepos > 1) { @@ -435,11 +449,35 @@ Key_Console(int key) return; } + if (key == K_RIGHTARROW) + { + if (key_lines[edit_line][key_linepos] != '\0') + { + key_linepos++; + } + + return; + } + + if ((key == K_BACKSPACE) || + ((key == 'h') && (keydown[K_CTRL]))) + { + if (key_linepos > 1) + { + Q_strdel(key_lines[edit_line], key_linepos - 1, 1); + key_linepos--; + } + + return; + } + if (key == K_DEL) { - memmove(key_lines[edit_line] + key_linepos, - key_lines[edit_line] + key_linepos + 1, - sizeof(key_lines[edit_line]) - key_linepos - 1); + if (key_lines[edit_line][key_linepos] != '\0') + { + Q_strdel(key_lines[edit_line], key_linepos, 1); + } + return; } @@ -547,32 +585,10 @@ Key_Console(int key) return; /* non printable character */ } - if (key_linepos < MAXCMDLINE - 1) - { - int last; - int length; + *txt = key; + *(txt + 1) = '\0'; - length = strlen(key_lines[edit_line]); - - if (length >= MAXCMDLINE - 1) - { - return; - } - - last = key_lines[edit_line][key_linepos]; - - memmove(key_lines[edit_line] + key_linepos + 1, - key_lines[edit_line] + key_linepos, - length - key_linepos); - - key_lines[edit_line][key_linepos] = key; - key_linepos++; - - if (!last) - { - key_lines[edit_line][key_linepos] = 0; - } - } + key_linepos += Q_strins(key_lines[edit_line], txt, key_linepos, MAXCMDLINE); } qboolean chat_team; @@ -1009,6 +1025,10 @@ Key_ReadConsoleHistory() } } + /* input line is always blank */ + key_linepos = 1; + strcpy (key_lines[edit_line], "]"); + fclose(f); } @@ -1045,6 +1065,7 @@ Key_Init(void) consolekeys[i] = true; } + consolekeys[K_DEL] = true; consolekeys[K_ENTER] = true; consolekeys[K_KP_ENTER] = true; consolekeys[K_TAB] = true; @@ -1380,6 +1401,12 @@ Key_Event(int key, qboolean down, qboolean special) return; } + /* FIXME: Better way to do CTRL+letter actions in the console */ + if (keydown[K_CTRL] && cls.key_dest == key_console && key >= 'a' && key <= 'z') + { + special = true; + } + /* All input subsystems handled after this point only care for key down events (=> if(!down) returns above). */ diff --git a/src/client/input/sdl2.c b/src/client/input/sdl2.c index 520c134a..0f53e2cd 100644 --- a/src/client/input/sdl2.c +++ b/src/client/input/sdl2.c @@ -2412,3 +2412,19 @@ IN_Shutdown(void) } /* ------------------------------------------------------------------ */ + +void +IN_GetClipboardText(char *out, size_t n) +{ + char *s = SDL_GetClipboardText(); + + if (!s || *s == '\0') + { + *out = '\0'; + return; + } + + Q_strlcpy(out, s, n - 1); + + SDL_free(s); +} diff --git a/src/client/input/sdl3.c b/src/client/input/sdl3.c index 5972c708..68dcdc6a 100644 --- a/src/client/input/sdl3.c +++ b/src/client/input/sdl3.c @@ -2410,3 +2410,19 @@ IN_Shutdown(void) } /* ------------------------------------------------------------------ */ + +void +IN_GetClipboardText(char *out, size_t n) +{ + char *s = SDL_GetClipboardText(); + + if (!s || *s == '\0') + { + *out = '\0'; + return; + } + + Q_strlcpy(out, s, n - 1); + + SDL_free(s); +} From d11ba119bc09b31de9ae808eacfadefcefca8ebc Mon Sep 17 00:00:00 2001 From: BjossiAlfreds Date: Fri, 2 Aug 2024 00:42:40 +0000 Subject: [PATCH 3/5] CTRL+x and c for cut/copy to clipboard --- src/client/cl_keyboard.c | 19 ++++++++++++++++++- src/client/input/header/input.h | 8 ++++++++ src/client/input/sdl2.c | 6 ++++++ src/client/input/sdl3.c | 6 ++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/client/cl_keyboard.c b/src/client/cl_keyboard.c index c4ef5d44..66a0762b 100644 --- a/src/client/cl_keyboard.c +++ b/src/client/cl_keyboard.c @@ -30,6 +30,7 @@ #include "header/client.h" void IN_GetClipboardText(char *out, size_t n); +int IN_SetClipboardText(const char *s); static cvar_t *cfg_unbindall; @@ -348,7 +349,8 @@ CompleteMapNameCommand(void) void Key_Console(int key) { - char txt[2], cliptext[256]; + char txt[2]; + char cliptext[256]; /* * Ignore keypad in console to prevent duplicate @@ -387,6 +389,21 @@ Key_Console(int key) return; } + if (key == 'c' || key == 'x') + { + if (IN_SetClipboardText(key_lines[edit_line] + 1)) + { + Com_Printf("Copy to clipboard failed.\n"); + } + else if (key == 'x') + { + key_lines[edit_line][1] = '\0'; + key_linepos = 1; + } + + return; + } + if (key == 'v') { IN_GetClipboardText(cliptext, sizeof(cliptext)); diff --git a/src/client/input/header/input.h b/src/client/input/header/input.h index 7c9656f5..9fb73bc8 100644 --- a/src/client/input/header/input.h +++ b/src/client/input/header/input.h @@ -59,4 +59,12 @@ void IN_Update(void); */ void In_FlushQueue(void); +/* Clipboard get/set */ + +/* Copy clipboard to buffer of size n */ +void IN_GetClipboardText(char *out, size_t n); + +/* Copy text to clipboard */ +int IN_SetClipboardText(const char *s); + #endif diff --git a/src/client/input/sdl2.c b/src/client/input/sdl2.c index 0f53e2cd..050c8ae2 100644 --- a/src/client/input/sdl2.c +++ b/src/client/input/sdl2.c @@ -2428,3 +2428,9 @@ IN_GetClipboardText(char *out, size_t n) SDL_free(s); } + +int +IN_SetClipboardText(const char *s) +{ + return SDL_SetClipboardText(s); +} diff --git a/src/client/input/sdl3.c b/src/client/input/sdl3.c index 68dcdc6a..40e778c0 100644 --- a/src/client/input/sdl3.c +++ b/src/client/input/sdl3.c @@ -2426,3 +2426,9 @@ IN_GetClipboardText(char *out, size_t n) SDL_free(s); } + +int +IN_SetClipboardText(const char *s) +{ + return SDL_SetClipboardText(s); +} From a18ea4b11dd2a496f1ad7024c3ae71e9e0bce4e8 Mon Sep 17 00:00:00 2001 From: BjossiAlfreds Date: Fri, 2 Aug 2024 01:02:34 +0000 Subject: [PATCH 4/5] CTRL actions work in pre-game console window --- src/client/cl_console.c | 15 ++++++++++---- src/client/cl_keyboard.c | 45 +++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/client/cl_console.c b/src/client/cl_console.c index f92a4b3b..f5a33655 100644 --- a/src/client/cl_console.c +++ b/src/client/cl_console.c @@ -60,7 +60,9 @@ DrawAltStringScaled(int x, int y, char *s, float factor) void Key_ClearTyping(void) { - key_lines[edit_line][1] = 0; /* clear any typing */ + key_lines[edit_line][0] = ']'; + key_lines[edit_line][1] = '\0'; + key_linepos = 1; } @@ -473,6 +475,7 @@ Con_DrawInput(void) char *text; char ch; int txtlen; + int linepos; if (cls.key_dest == key_menu) { @@ -487,18 +490,22 @@ Con_DrawInput(void) scale = SCR_GetConsoleScale(); text = key_lines[edit_line]; + linepos = key_linepos; /* prestep if horizontally scrolling */ - if (key_linepos >= con.linewidth) + if (linepos >= con.linewidth) { - text += 1 + key_linepos - con.linewidth; + int ofs = 1 + linepos - con.linewidth; + + text += ofs; + linepos -= ofs; } txtlen = strlen(text); for (i = 0; i < con.linewidth; i++) { - if (i == key_linepos) + if (i == linepos) { if (cls.realtime & 8) { diff --git a/src/client/cl_keyboard.c b/src/client/cl_keyboard.c index 66a0762b..e116a46b 100644 --- a/src/client/cl_keyboard.c +++ b/src/client/cl_keyboard.c @@ -29,6 +29,7 @@ #include "header/client.h" +void Key_ClearTyping(void); void IN_GetClipboardText(char *out, size_t n); int IN_SetClipboardText(const char *s); @@ -346,6 +347,14 @@ CompleteMapNameCommand(void) /* * Interactive line editing and console scrollback */ +static int +IsInConsole(void) +{ + return cls.key_dest == key_console || + (cls.key_dest == key_game && + (cls.state == ca_disconnected || cls.state == ca_connecting)); +} + void Key_Console(int key) { @@ -391,14 +400,16 @@ Key_Console(int key) if (key == 'c' || key == 'x') { - if (IN_SetClipboardText(key_lines[edit_line] + 1)) + if (key_lines[edit_line][1] != '\0') { - Com_Printf("Copy to clipboard failed.\n"); - } - else if (key == 'x') - { - key_lines[edit_line][1] = '\0'; - key_linepos = 1; + if (IN_SetClipboardText(key_lines[edit_line] + 1)) + { + Com_Printf("Copy to clipboard failed.\n"); + } + else if (key == 'x') + { + Key_ClearTyping(); + } } return; @@ -434,9 +445,8 @@ Key_Console(int key) Com_Printf("%s\n", key_lines[edit_line]); edit_line = (edit_line + 1) & (NUM_KEY_LINES - 1); history_line = edit_line; - key_lines[edit_line][0] = ']'; - key_lines[edit_line][1] = '\0'; - key_linepos = 1; + + Key_ClearTyping(); if (cls.state == ca_disconnected) { @@ -535,8 +545,7 @@ Key_Console(int key) if (history_line == edit_line) { - key_lines[edit_line][0] = ']'; - key_linepos = 1; + Key_ClearTyping(); } else { @@ -1042,9 +1051,8 @@ Key_ReadConsoleHistory() } } - /* input line is always blank */ - key_linepos = 1; - strcpy (key_lines[edit_line], "]"); + /* don't remember the input line */ + Key_ClearTyping(); fclose(f); } @@ -1418,8 +1426,11 @@ Key_Event(int key, qboolean down, qboolean special) return; } - /* FIXME: Better way to do CTRL+letter actions in the console */ - if (keydown[K_CTRL] && cls.key_dest == key_console && key >= 'a' && key <= 'z') + /* FIXME: Better way to do CTRL+ actions in the console? + special should be set to true in this case. + */ + if (keydown[K_CTRL] && IsInConsole() && + key >= 'a' && key <= 'z') { special = true; } From 98d33fad062e4f3b443b9f870e5b003ff5bbf7b8 Mon Sep 17 00:00:00 2001 From: BjossiAlfreds Date: Sun, 11 Aug 2024 12:55:35 +0000 Subject: [PATCH 5/5] Moved input line indicator ] out of line buffer --- src/client/cl_console.c | 22 +++++--- src/client/cl_keyboard.c | 105 +++++++++++++++++------------------- src/client/header/console.h | 3 ++ 3 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/client/cl_console.c b/src/client/cl_console.c index f5a33655..23bf2115 100644 --- a/src/client/cl_console.c +++ b/src/client/cl_console.c @@ -60,10 +60,8 @@ DrawAltStringScaled(int x, int y, char *s, float factor) void Key_ClearTyping(void) { - key_lines[edit_line][0] = ']'; - key_lines[edit_line][1] = '\0'; - - key_linepos = 1; + key_lines[edit_line][0] = '\0'; + key_linepos = 0; } void @@ -476,6 +474,7 @@ Con_DrawInput(void) char ch; int txtlen; int linepos; + int draw_icon; if (cls.key_dest == key_menu) { @@ -493,23 +492,30 @@ Con_DrawInput(void) linepos = key_linepos; /* prestep if horizontally scrolling */ - if (linepos >= con.linewidth) + if (linepos >= (con.linewidth - 1)) { int ofs = 1 + linepos - con.linewidth; text += ofs; linepos -= ofs; + + draw_icon = 0; + } + else + { + Draw_CharScaled(8 * scale, con.vislines - 22 * scale, CON_INPUT_INDICATOR, scale); + draw_icon = 1; } txtlen = strlen(text); - for (i = 0; i < con.linewidth; i++) + for (i = 0; i < (con.linewidth - draw_icon); i++) { if (i == linepos) { if (cls.realtime & 8) { - ch = 11; + ch = CON_INPUT_CURSOR; } else { @@ -525,7 +531,7 @@ Con_DrawInput(void) ch = text[i]; } - Draw_CharScaled(((i + 1) << 3) * scale, con.vislines - 22 * scale, ch, scale); + Draw_CharScaled(((i + 1 + draw_icon) << 3) * scale, con.vislines - 22 * scale, ch, scale); } } diff --git a/src/client/cl_keyboard.c b/src/client/cl_keyboard.c index e116a46b..fc05b228 100644 --- a/src/client/cl_keyboard.c +++ b/src/client/cl_keyboard.c @@ -272,9 +272,10 @@ keyname_t keynames[] = { void CompleteCommand(void) { - char *cmd, *s; + char *cmd; + char *s; - s = key_lines[edit_line] + 1; + s = key_lines[edit_line]; if ((*s == '\\') || (*s == '/')) { @@ -282,65 +283,48 @@ CompleteCommand(void) } cmd = Cmd_CompleteCommand(s); - - if (cmd) + if (!cmd) { - key_lines[edit_line][1] = '/'; - strcpy(key_lines[edit_line] + 2, cmd); - key_linepos = strlen(cmd) + 2; - - if (Cmd_IsComplete(cmd)) - { - key_lines[edit_line][key_linepos] = ' '; - key_linepos++; - key_lines[edit_line][key_linepos] = 0; - } - else - { - key_lines[edit_line][key_linepos] = 0; - } + return; } - return; + *key_lines[edit_line] = '/'; + strcpy(key_lines[edit_line] + 1, cmd); + key_linepos = strlen(cmd) + 1; + + if (Cmd_IsComplete(cmd)) + { + key_lines[edit_line][key_linepos] = ' '; + key_linepos++; + } + + key_lines[edit_line][key_linepos] = '\0'; } void CompleteMapNameCommand(void) { - int i; - char *s, *t, *cmdArg; + char *s, *cmdArg; const char *mapCmdString = "map "; - s = key_lines[edit_line] + 1; + s = key_lines[edit_line]; if ((*s == '\\') || (*s == '/')) { s++; } - t = s; - - for (i = 0; i < strlen(mapCmdString); i++) + if (strncmp(mapCmdString, s, strlen(mapCmdString)) != 0) { - if (t[i] == mapCmdString[i]) - { - s++; - } - else - { - return; - } + return; } - cmdArg = Cmd_CompleteMapCommand(s); + cmdArg = Cmd_CompleteMapCommand(s + strlen(mapCmdString)); if (cmdArg) { - key_lines[edit_line][1] = '/'; - strcpy(key_lines[edit_line] + 2, mapCmdString); + snprintf(key_lines[edit_line], MAXCMDLINE, "/%s%s", mapCmdString, cmdArg); key_linepos = strlen(key_lines[edit_line]); - strcpy(key_lines[edit_line] + key_linepos, cmdArg); - key_linepos = key_linepos + strlen(cmdArg); } } @@ -400,9 +384,9 @@ Key_Console(int key) if (key == 'c' || key == 'x') { - if (key_lines[edit_line][1] != '\0') + if (*key_lines[edit_line] != '\0') { - if (IN_SetClipboardText(key_lines[edit_line] + 1)) + if (IN_SetClipboardText(key_lines[edit_line])) { Com_Printf("Copy to clipboard failed.\n"); } @@ -431,18 +415,18 @@ Key_Console(int key) if ((key == K_ENTER) || (key == K_KP_ENTER)) { /* slash text are commands, else chat */ - if ((key_lines[edit_line][1] == '\\') || - (key_lines[edit_line][1] == '/')) + if ((*key_lines[edit_line] == '\\') || (*key_lines[edit_line] == '/')) { - Cbuf_AddText(key_lines[edit_line] + 2); /* skip the > */ + Cbuf_AddText(key_lines[edit_line] + 1); /* skip the > */ } else { - Cbuf_AddText(key_lines[edit_line] + 1); /* valid command */ + Cbuf_AddText(key_lines[edit_line]); /* valid command */ } Cbuf_AddText("\n"); - Com_Printf("%s\n", key_lines[edit_line]); + Com_Printf("%c%s\n", CON_INPUT_INDICATOR, key_lines[edit_line]); + edit_line = (edit_line + 1) & (NUM_KEY_LINES - 1); history_line = edit_line; @@ -468,7 +452,7 @@ Key_Console(int key) if (key == K_LEFTARROW) { - if (key_linepos > 1) + if (key_linepos > 0) { key_linepos--; } @@ -489,7 +473,7 @@ Key_Console(int key) if ((key == K_BACKSPACE) || ((key == 'h') && (keydown[K_CTRL]))) { - if (key_linepos > 1) + if (key_linepos > 0) { Q_strdel(key_lines[edit_line], key_linepos - 1, 1); key_linepos--; @@ -516,7 +500,7 @@ Key_Console(int key) history_line = (history_line - 1) & (NUM_KEY_LINES-1); } while (history_line != edit_line && - !key_lines[history_line][1]); + key_lines[history_line][0] == '\0'); if (history_line == edit_line) { @@ -524,7 +508,8 @@ Key_Console(int key) } memmove(key_lines[edit_line], key_lines[history_line], sizeof(key_lines[edit_line])); - key_linepos = (int)strlen(key_lines[edit_line]); + key_linepos = strlen(key_lines[edit_line]); + return; } @@ -541,7 +526,7 @@ Key_Console(int key) history_line = (history_line + 1) & (NUM_KEY_LINES-1); } while (history_line != edit_line && - !key_lines[history_line][1]); + key_lines[history_line][0] == '\0'); if (history_line == edit_line) { @@ -550,7 +535,7 @@ Key_Console(int key) else { memmove(key_lines[edit_line], key_lines[history_line], sizeof(key_lines[edit_line])); - key_linepos = (int)strlen(key_lines[edit_line]); + key_linepos = strlen(key_lines[edit_line]); } return; @@ -585,7 +570,7 @@ Key_Console(int key) else { - key_linepos = 1; + key_linepos = 0; } return; @@ -600,7 +585,7 @@ Key_Console(int key) else { - key_linepos = (int)strlen(key_lines[edit_line]); + key_linepos = strlen(key_lines[edit_line]); } return; @@ -995,7 +980,7 @@ Key_WriteConsoleHistory() int lineIdx = (edit_line+i) & (NUM_KEY_LINES-1); const char* line = key_lines[lineIdx]; - if(line[1] != '\0' && strcmp(lastWrittenLine, line ) != 0) + if(*line != '\0' && strcmp(lastWrittenLine, line) != 0) { // if the line actually contains something besides the ] prompt, // and is not identical to the last written line, write it to the file @@ -1042,6 +1027,7 @@ Key_ReadConsoleHistory() history_line = i; break; } + // remove trailing newlines int lastCharIdx = strlen(key_lines[i])-1; while((key_lines[i][lastCharIdx] == '\n' || key_lines[i][lastCharIdx] == '\r') && lastCharIdx >= 0) @@ -1049,6 +1035,12 @@ Key_ReadConsoleHistory() key_lines[i][lastCharIdx] = '\0'; --lastCharIdx; } + + /* backwards compatibility with old history files */ + if(key_lines[i][0] == ']') + { + memmove(key_lines[i], key_lines[i] + 1, MAXCMDLINE - 1); + } } /* don't remember the input line */ @@ -1077,12 +1069,11 @@ Key_Init(void) int i; for (i = 0; i < NUM_KEY_LINES; i++) { - key_lines[i][0] = ']'; - key_lines[i][1] = 0; + key_lines[i][0] = '\0'; } // can't call Key_ReadConsoleHistory() here because FS_Gamedir() isn't set yet - key_linepos = 1; + key_linepos = 0; /* init 128 bit ascii characters in console mode */ for (i = 32; i < 128; i++) diff --git a/src/client/header/console.h b/src/client/header/console.h index 432b76ad..1ce0062f 100644 --- a/src/client/header/console.h +++ b/src/client/header/console.h @@ -27,6 +27,9 @@ #ifndef CL_HEADER_CONSOLE_H #define CL_HEADER_CONSOLE_H +#define CON_INPUT_INDICATOR ']' +#define CON_INPUT_CURSOR 11 + #define NUM_CON_TIMES 4 #define CON_TEXTSIZE 32768