]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
con: allow alias loops involving wait to be broken, eg with unalias or quit
authorbones_was_here <bones_was_here@xonotic.au>
Sat, 30 Dec 2023 20:49:08 +0000 (06:49 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Sat, 30 Dec 2023 22:28:44 +0000 (08:28 +1000)
Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
cmd.c
keys.c

diff --git a/cmd.c b/cmd.c
index 0343dd10582c83393f448d21a1a4827f38ccffc3..df218d9e0fecae0f5bf031b6c7e3d546c083bc11 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -425,8 +425,10 @@ static void Cbuf_Frame_Input(void)
 {
        char *line;
 
+       // bones_was_here: prepending allows a loop such as `alias foo "bar; wait; foo"; foo`
+       // to be broken with an alias or unalias command
        while ((line = Sys_ConsoleInput()))
-                       Cbuf_AddText(cmd_local, line);
+               Cbuf_InsertText(cmd_local, line);
 }
 
 void Cbuf_Frame(cmd_buf_t *cbuf)
diff --git a/keys.c b/keys.c
index 739510ec34ecc4f76d77bef246a1df6bb6c93a49..fd0a24b202a07b64491ec1e2dc793db61e774676 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -1098,8 +1098,7 @@ static int Key_Convert_NumPadKey(int key)
        return key;
 }
 
-static void
-Key_Console(cmd_state_t *cmd, int key, int unicode)
+static void Key_Console(cmd_state_t *cmd, int key, int unicode)
 {
        int linepos;
 
@@ -1121,8 +1120,9 @@ Key_Console(cmd_state_t *cmd, int key, int unicode)
 
        if ((key == K_ENTER || key == K_KP_ENTER) && KM_NONE)
        {
-               Cbuf_AddText (cmd, key_line+1); // skip the ]
-               Cbuf_AddText (cmd, "\n");
+               // bones_was_here: prepending allows a loop such as `alias foo "bar; wait; foo"; foo`
+               // to be broken with an alias or unalias command
+               Cbuf_InsertText(cmd, key_line+1); // skip the ]
                Key_History_Push();
                key_linepos = Key_ClearEditLine(true);
                // force an update, because the command may take some time