Save recognized runtime commands in expanded history

This commit is contained in:
Johannes Findeisen 2026-12-02 05:16:35 +01:00
commit d39848e410
2 changed files with 27 additions and 13 deletions

28
irc9.c
View file

@ -57,7 +57,7 @@
#define INBUF 4096
#define MAXLINE 512
#define MAXINPUT 512
#define MAXHIST 64
#define MAXHIST 256
#define MAXSCROLL 500
#define MAXWRAPROWS 128
#define TREEW 24
@ -1974,9 +1974,23 @@ static void read_server(Server *s)
/* ------------------------------------------------------------------ */
/* input line and commands */
static int is_option_command(const char *line)
{
static const char *const names[] = {
"help", "version", "colored", "nocolored", "silent", "nosilent",
"history", "nohistory", "color", "nocolor", "scrollback", "noscrollback"
};
if (*line++ != ':') return 0;
size_t len = strcspn(line, " \t");
for (size_t i = 0; i < sizeof names / sizeof *names; i++)
if (strlen(names[i]) == len && strncmp(names[i], line, len) == 0)
return 1;
return 0;
}
static void history_add(const char *s)
{
if (*s != '/') return;
if (*s != '/' && !is_option_command(s)) return;
if (hist_n == MAXHIST) {
for (int i = 1; i < MAXHIST; i++)
memcpy(history[i - 1], history[i], sizeof history[i]);
@ -2475,7 +2489,7 @@ static void do_option_command(Window *w, char *command)
appendf(w, ":colored / :nocolored, :silent / :nosilent");
appendf(w, ":color RRGGBB / :nocolor, :history / :nohistory");
appendf(w, ":scrollback LINES / :noscrollback, :version, :help");
appendf(w, "Use /help for IRC commands and :: to send a leading colon.");
appendf(w, "Use /help for IRC commands.");
}
} else if (strcmp(name, "colored") == 0 || strcmp(name, "nocolored") == 0) {
colored_nicks = name[0] != 'n';
@ -2509,16 +2523,16 @@ static void submit_input(void)
if (*line == '/') {
if (history_enabled) history_record(line);
do_command(curwin, line);
} else if (line[0] == ':' && line[1] != ':') {
} else if (is_option_command(line)) {
if (history_enabled) history_record(line);
do_option_command(curwin, line + 1);
} else if (*line) {
const char *message = line[0] == ':' ? line + 1 : line;
Window *t = input_target(curwin);
if (!t) {
if (curwin) appendf(curwin, "* no target here; use /join or /msg");
} else {
sendf(t->srv, "PRIVMSG %s :%s", t->name, message);
append_nickf(t, "<", t->srv->nick, "> ", "%s", message);
sendf(t->srv, "PRIVMSG %s :%s", t->name, line);
append_nickf(t, "<", t->srv->nick, "> ", "%s", line);
}
}