Save recognized runtime commands in expanded history
This commit is contained in:
parent
493b69e21e
commit
d39848e410
2 changed files with 27 additions and 13 deletions
12
README.md
12
README.md
|
|
@ -28,8 +28,8 @@ the channel tree and divider. For example, `./irc9 --color FF8800` uses
|
|||
orange on terminals with true-color support.
|
||||
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.
|
||||
Use `--history` to save submitted slash commands to `~/.irc9_history` and
|
||||
recall the 64 most recent commands with Up and Down across sessions.
|
||||
Use `--history` to save submitted slash and colon commands to `~/.irc9_history` and
|
||||
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:
|
||||
`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-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 |
|
||||
| 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 |
|
||||
| `Del` | delete the character at the cursor |
|
||||
|
||||
|
|
@ -193,8 +193,8 @@ cancel. Existing files are protected from overwrites.
|
|||
## Runtime options
|
||||
|
||||
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
|
||||
that starts with a literal colon, type two colons.
|
||||
option inside irc9. Settings apply to the current session. Only the command names below are
|
||||
reserved. Other colon-prefixed text is sent as a chat message.
|
||||
|
||||
| Command | Action |
|
||||
| --- | --- |
|
||||
|
|
@ -202,7 +202,7 @@ that starts with a literal colon, type two colons.
|
|||
| `:silent` / `:nosilent` | Hide or show future channel activity notices |
|
||||
| `: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 |
|
||||
| `: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 |
|
||||
| `:help` | List the runtime options in the current window |
|
||||
|
||||
|
|
|
|||
28
irc9.c
28
irc9.c
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue