Hi, i don't have issues with tilde when using locally, but i mostly ssh to reach cu, and too many times i've forgotten to configure ssh/use -e, with this cu(1) becomes safer/easier to use for us with non-english keyboard. ~tilde is certainly annoying when it's three key presses alone, and then you mostly get only one shot at trying..
is this bloat? -Artturi diff --git a/usr.bin/cu/command.c b/usr.bin/cu/command.c index c07fe73aeca..d97db3b56de 100644 --- a/usr.bin/cu/command.c +++ b/usr.bin/cu/command.c @@ -223,6 +223,8 @@ start_record(void) void do_command(char c) { + char esc = alt_esc ? '%' : '~'; + if (restricted && strchr("CRX$>", c) != NULL) { cu_warnx("~%c command is not allowed in restricted mode", c); return; @@ -271,15 +273,16 @@ do_command(char c) break; case '?': printf("\r\n" - "~# send break\r\n" - "~$ pipe local command to remote host\r\n" - "~> send file to remote host\r\n" - "~C connect program to remote host\r\n" - "~D de-assert DTR line briefly\r\n" - "~R start recording to file\r\n" - "~S set speed\r\n" - "~X send file with XMODEM\r\n" - "~? get this summary\r\n" + "%c# send break\r\n" + "%c$ pipe local command to remote host\r\n" + "%c> send file to remote host\r\n" + "%cC connect program to remote host\r\n" + "%cD de-assert DTR line briefly\r\n" + "%cR start recording to file\r\n" + "%cS set speed\r\n" + "%cX send file with XMODEM\r\n" + "%c? get this summary\r\n", + esc, esc, esc, esc, esc, esc, esc, esc, esc ); break; } diff --git a/usr.bin/cu/cu.1 b/usr.bin/cu/cu.1 index 104a6ea7893..1d609e14947 100644 --- a/usr.bin/cu/cu.1 +++ b/usr.bin/cu/cu.1 @@ -35,7 +35,7 @@ .Nd serial terminal emulator .Sh SYNOPSIS .Nm -.Op Fl dr +.Op Fl der .Op Fl l Ar line .Op Fl s Ar speed | Fl Ar speed .Nm @@ -55,6 +55,10 @@ The options are as follows: Specify that the line is directly connected and .Nm should not allow the driver to block waiting for a carrier to be detected. +.It Fl e +Use a percent sign +.Pq Ql % +as the escape character instead of tilde. .It Fl l Ar line Specify the line to use. Either of the forms like diff --git a/usr.bin/cu/cu.c b/usr.bin/cu/cu.c index 03a2df4181f..b66f4698605 100644 --- a/usr.bin/cu/cu.c +++ b/usr.bin/cu/cu.c @@ -41,6 +41,7 @@ FILE *record_file; struct termios saved_tio; struct bufferevent *input_ev; struct bufferevent *output_ev; +int alt_esc = 0; int is_direct = -1; int restricted = 0; const char *line_path = NULL; @@ -53,7 +54,7 @@ struct event sighup_ev; enum { STATE_NONE, STATE_NEWLINE, - STATE_TILDE + STATE_ESCAPE } last_state = STATE_NEWLINE; __dead void usage(void); @@ -67,7 +68,7 @@ void try_remote(const char *, const char *, const char *); __dead void usage(void) { - fprintf(stderr, "usage: %s [-dr] [-l line] [-s speed | -speed]\n", + fprintf(stderr, "usage: %s [-der] [-l line] [-s speed | -speed]\n", __progname); fprintf(stderr, " %s [host]\n", __progname); exit(1); @@ -101,11 +102,14 @@ main(int argc, char **argv) errx(1, "speed asprintf"); } - while ((opt = getopt(argc, argv, "drl:s:")) != -1) { + while ((opt = getopt(argc, argv, "derl:s:")) != -1) { switch (opt) { case 'd': is_direct = 1; break; + case 'e': + alt_esc = 1; + break; case 'r': if (pledge("stdio rpath wpath tty", NULL) == -1) err(1, "pledge"); @@ -308,14 +312,14 @@ stream_read(struct bufferevent *bufev, void *data) last_state = STATE_NEWLINE; break; case STATE_NEWLINE: - if (state_change && *ptr == '~') { - last_state = STATE_TILDE; + if (state_change && *ptr == "~%"[alt_esc]) { + last_state = STATE_ESCAPE; continue; } if (*ptr != '\r') last_state = STATE_NONE; break; - case STATE_TILDE: + case STATE_ESCAPE: do_command(*ptr); last_state = STATE_NEWLINE; continue; diff --git a/usr.bin/cu/cu.h b/usr.bin/cu/cu.h index 2a7ca45d414..9d8ea3fc86a 100644 --- a/usr.bin/cu/cu.h +++ b/usr.bin/cu/cu.h @@ -23,6 +23,7 @@ void do_command(char); /* cu.c */ +extern int alt_esc; extern int restricted; extern FILE *record_file; extern struct termios saved_tio;