ref: b36001c95a510ec4f6c8e8613ec09283135dc9fd
parent: 9ff42d4d6cc230ed26ed4e421f0b795104473136
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Oct 14 18:19:05 EDT 2024
console: insert mode and cursor movement, "del" key use
--- a/console.c
+++ b/console.c
@@ -68,12 +68,10 @@
Con_ClearNotify
================
*/
-void Con_ClearNotify (void)
+void
+Con_ClearNotify(void)
{
- int i;
-
- for (i=0 ; i<NUM_CON_TIMES ; i++)
- con_times[i] = 0;
+ memset(con_times, 0, sizeof(con_times));
}
@@ -112,7 +110,8 @@
If the line width has changed, reformat the buffer.
================
*/
-void Con_CheckResize (void)
+void
+Con_CheckResize(void)
{
int i, j, width, oldwidth, oldtotallines, numlines, numchars;
char tbuf[CON_TEXTSIZE];
@@ -171,7 +170,8 @@
Con_Init
================
*/
-void Con_Init (void)
+void
+Con_Init(void)
{
con_text = Hunk_Alloc(CON_TEXTSIZE);
memset(con_text, ' ', CON_TEXTSIZE);
@@ -323,7 +323,8 @@
A Con_Printf that only shows up if the "developer" cvar is set
================
*/
-void Con_DPrintf (char *fmt, ...)
+void
+Con_DPrintf(char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
@@ -362,7 +363,7 @@
{
int y;
int i;
- char *text;
+ char *text, c;
if (key_dest != key_console && !con_forcedup)
return; // don't draw anything
@@ -370,12 +371,10 @@
text = key_lines[edit_line];
// add the cursor frame
- text[key_linepos] = 10+((int)(realtime*con_cursorspeed)&1);
+ c = text[key_linepos];
+ if((int)(realtime*con_cursorspeed)&1)
+ text[key_linepos] = 11;
- // 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;
@@ -382,11 +381,11 @@
// draw it
y = con_vislines-16;
- for (i=0 ; i<con_linewidth ; i++)
+ for(i=0 ; (c != 0 || i <= key_linepos) && i < con_linewidth && text[i] != 0 ; i++)
Draw_Character ( (i+1)<<3, y, text[i]);
// remove cursor
- key_lines[edit_line][key_linepos] = 0;
+ key_lines[edit_line][key_linepos] = c;
}
--- a/keys.c
+++ b/keys.c
@@ -140,13 +140,14 @@
static void
Key_Console(int key)
{
- char *cmd;
+ char *cmd, *s;
+ int n;
- if (key == K_ENTER)
- {
- Cbuf_AddText (key_lines[edit_line]+1); // skip the >
- Cbuf_AddText ("\n");
- Con_Printf ("%s\n",key_lines[edit_line]);
+ s = key_lines[edit_line];
+ if(key == K_ENTER){
+ Cbuf_AddText(s+1); // skip the >
+ Cbuf_AddText("\n");
+ Con_Printf("%s\n", s);
edit_line = (edit_line + 1) & 31;
history_line = edit_line;
key_lines[edit_line][0] = ']';
@@ -157,31 +158,42 @@
return;
}
- if (key == K_TAB)
- { // command completion
- cmd = Cmd_CompleteCommand (key_lines[edit_line]+1);
- if (!cmd)
- cmd = Cvar_CompleteVariable (key_lines[edit_line]+1);
- if (cmd)
- {
- strcpy(key_lines[edit_line]+1, cmd);
+ if(key == K_TAB){ // command completion
+ if((cmd = Cmd_CompleteCommand(s+1)) == nil)
+ cmd = Cvar_CompleteVariable(s+1);
+ if(cmd){
+ strcpy(s+1, cmd);
key_linepos = strlen(cmd)+1;
- key_lines[edit_line][key_linepos] = ' ';
+ s[key_linepos] = ' ';
key_linepos++;
- key_lines[edit_line][key_linepos] = 0;
+ s[key_linepos] = 0;
return;
}
}
- if (key == K_BACKSPACE || key == K_LEFTARROW)
- {
- if (key_linepos > 1)
+ if(key == K_LEFTARROW){
+ if(key_linepos > 1)
key_linepos--;
return;
}
+ if(key == K_RIGHTARROW){
+ if(s[key_linepos] != 0)
+ key_linepos++;
+ return;
+ }
+ if(key == K_BACKSPACE){
+ if(key_linepos > 1){
+ key_linepos--;
+ memmove(s+key_linepos, s+key_linepos+1, strlen(s+key_linepos+1)+1);
+ }
+ return;
+ }
+ if(key == K_DEL){
+ memmove(s+key_linepos, s+key_linepos+1, strlen(s+key_linepos+1)+1);
+ return;
+ }
- if (key == K_UPARROW)
- {
+ if(key == K_UPARROW){
do
{
history_line = (history_line - 1) & 31;
@@ -190,7 +202,7 @@
if (history_line == edit_line)
history_line = (edit_line+1)&31;
key_linepos = strlen(key_lines[history_line]);
- memmove(key_lines[edit_line], key_lines[history_line], key_linepos+1);
+ memmove(s, key_lines[history_line], key_linepos+1);
return;
}
@@ -205,13 +217,13 @@
&& !key_lines[history_line][1]);
if (history_line == edit_line)
{
- key_lines[edit_line][0] = ']';
+ s[0] = ']';
key_linepos = 1;
}
else
{
key_linepos = strlen(key_lines[history_line]);
- memmove(key_lines[edit_line], key_lines[history_line], key_linepos+1);
+ memmove(s, key_lines[history_line], key_linepos+1);
}
return;
}
@@ -247,11 +259,16 @@
if (key < 32 || key > 127)
return; // non printable
- if (key_linepos < MAXCMDLINE-1)
+ if ((n = strlen(s)) < MAXCMDLINE-1)
{
- key_lines[edit_line][key_linepos] = key;
- key_linepos++;
- key_lines[edit_line][key_linepos] = 0;
+ n -= key_linepos;
+ if(s[key_linepos] != 0){
+ memmove(s+key_linepos+1, s+key_linepos, n+1);
+ s[key_linepos++] = key;
+ }else{
+ s[key_linepos++] = key;
+ s[key_linepos] = 0;
+ }
}
}
@@ -496,6 +513,7 @@
consolekeys[K_UPARROW] = true;
consolekeys[K_DOWNARROW] = true;
consolekeys[K_BACKSPACE] = true;
+ consolekeys[K_DEL] = true;
consolekeys[K_PGUP] = true;
consolekeys[K_PGDN] = true;
consolekeys[K_SHIFT] = true;