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

View file

@ -28,8 +28,8 @@ the channel tree and divider. For example, `./irc9 --color FF8800` uses
orange on terminals with true-color support. orange on terminals with true-color support.
Use `--scrollback LINES` to set how many lines each window retains. The default Use `--scrollback LINES` to set how many lines each window retains. The default
is 500 lines. For example, `./irc9 --scrollback 2000` keeps 2000 lines per window. is 500 lines. For example, `./irc9 --scrollback 2000` keeps 2000 lines per window.
Use `--history` to save submitted slash commands to `~/.irc9_history` and Use `--history` to save submitted slash and colon commands to `~/.irc9_history` and
recall the 64 most recent commands with Up and Down across sessions. recall the 256 most recent commands with Up and Down across sessions.
With no config path, irc9 looks next to the executable, in this order: With no config path, irc9 looks next to the executable, in this order:
`irc9rc`, `config`, then `~/.irc9rc`. Paths are relative to the binary, not to `irc9rc`, `config`, then `~/.irc9rc`. Paths are relative to the binary, not to
@ -182,7 +182,7 @@ MODE, TOPIC, and INVITE events are shown in the relevant window.
| `ctrl-l` | clear the screen (history stays scrollable) | | `ctrl-l` | clear the screen (history stays scrollable) |
| `ctrl-t` | toggle copy view, which hides the tree, chat timestamps, and sender names | | `ctrl-t` | toggle copy view, which hides the tree, chat timestamps, and sender names |
| `ctrl-s` | save the current window’s scrollback to a new plain-text file | | `ctrl-s` | save the current window’s scrollback to a new plain-text file |
| Up / Down | browse slash command history with `--history` | | Up / Down | browse slash and colon command history with `--history` |
| Left / Right, Home / End | edit the input line | | Left / Right, Home / End | edit the input line |
| `Del` | delete the character at the cursor | | `Del` | delete the character at the cursor |
@ -193,8 +193,8 @@ cancel. Existing files are protected from overwrites.
## Runtime options ## Runtime options
Type a command starting with `:` in the input line to use a command-line Type a command starting with `:` in the input line to use a command-line
option inside irc9. Settings apply to the current session. To send a message option inside irc9. Settings apply to the current session. Only the command names below are
that starts with a literal colon, type two colons. reserved. Other colon-prefixed text is sent as a chat message.
| Command | Action | | Command | Action |
| --- | --- | | --- | --- |
@ -202,7 +202,7 @@ that starts with a literal colon, type two colons.
| `:silent` / `:nosilent` | Hide or show future channel activity notices | | `:silent` / `:nosilent` | Hide or show future channel activity notices |
| `:color RRGGBB` / `:nocolor` | Set the interface accent or restore the default cyan | | `:color RRGGBB` / `:nocolor` | Set the interface accent or restore the default cyan |
| `:scrollback LINES` / `:noscrollback` | Resize scrollback in every window or restore the 500-line default. Reducing the limit discards the oldest lines | | `:scrollback LINES` / `:noscrollback` | Resize scrollback in every window or restore the 500-line default. Reducing the limit discards the oldest lines |
| `:history` / `:nohistory` | Enable or disable saving and browsing slash-command history | | `:history` / `:nohistory` | Enable or disable saving and browsing slash and colon command history |
| `:version` | Show the program version in the current window | | `:version` | Show the program version in the current window |
| `:help` | List the runtime options in the current window | | `:help` | List the runtime options in the current window |

28
irc9.c
View file

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