Skip to content

Commit

Permalink
store cmds w/o junk spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
stsp committed Mar 12, 2024
1 parent ec310da commit 355e018
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,16 @@ void cmdbuf_reset(void)
cur = tail = 0;
}

void cmdbuf_store(char *cmd_buf)
void cmdbuf_trunc(char *cmd_buf)
{
int prev_count = (cmdqueue_count - 1) % MAX_CMDQUEUE_LEN;
cmd_buf[tail] = '\0';
/* Reset the cmdbuf */
cur = tail = 0;
}

void cmdbuf_store(const char *cmd_buf)
{
int prev_count = (cmdqueue_count - 1) % MAX_CMDQUEUE_LEN;

if (cmd_buf[0] == '\0')
return;
Expand Down
3 changes: 2 additions & 1 deletion src/cmdbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ int cmdbuf_move(char *cmd_buf, int direction);
void cmdbuf_delch(char *cmd_buf);
int cmdbuf_bksp(char *cmd_buf);
void cmdbuf_clear(char *cmd_buf);
void cmdbuf_trunc(char *cmd_buf);
char cmdbuf_putch(char *cmd_buf, unsigned int buf_size, char ch, unsigned short flag);
void cmdbuf_store(char *cmd_buf);
void cmdbuf_store(const char *cmd_buf);
void cmdbuf_reset(void);
void cmdbuf_init(void);

Expand Down
4 changes: 3 additions & 1 deletion src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ static void prompt_for_and_get_cmd(void)
} while (key != KEY_ENTER);

if (need_store)
cmdbuf_store(conbuf);
cmdbuf_trunc(conbuf);
else
cmdbuf_reset();
strcpy(cmd_line, conbuf);
Expand All @@ -727,6 +727,8 @@ static void prompt_for_and_get_cmd(void)
memmove(cmd_line, cmd_line + len1, len - len1 + 1);
len -= len1;
}
if (need_store)
cmdbuf_store(cmd_line);
parse_cmd_line();
cputs("\r\n");
}
Expand Down

0 comments on commit 355e018

Please sign in to comment.