1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00
putty-source/windows/pterm.c
Simon Tatham 22911ccdcc New config option for shifted arrow key handling.
This commit introduces a new config option for how to handle shifted
arrow keys.

In the default mode (SHARROW_APPLICATION), we do what we've always
done: Ctrl flips the arrow keys between sending their most usual
escape sequences (ESC [ A ... ESC [ D) and sending the 'application
cursor keys' sequences (ESC O A ... ESC O D). Whichever of those modes
is currently configured, Ctrl+arrow sends the other one.

In the new mode (SHARROW_BITMAP), application cursor key mode is
unaffected by any shift keys, but the default sequences acquire two
numeric arguments. The first argument is 1 (reflecting the fact that a
shifted arrow key still notionally moves just 1 character cell); the
second is the bitmap (1 for Shift) + (2 for Alt) + (4 for Ctrl),
offset by 1. (Except that if _none_ of those modifiers is pressed,
both numeric arguments are simply omitted.)

The new bitmap mode is what current xterm generates, and also what
Windows ConPTY seems to expect. If you start an ordinary Command
Prompt and launch into WSL, those are the sequences it will generate
for shifted arrow keys; conversely, if you run a Command Prompt within
a ConPTY, then these sequences for Ctrl+arrow will have the effect you
expect in cmd.exe command-line editing (going backward or forward a
word). For that reason, I enable this mode unconditionally when
launching Windows pterm.
2021-10-18 20:15:35 +01:00

48 lines
1.4 KiB
C

#include "putty.h"
#include "storage.h"
void gui_term_process_cmdline(Conf *conf, char *cmdline)
{
do_defaults(NULL, conf);
conf_set_str(conf, CONF_remote_cmd, "");
cmdline = handle_restrict_acl_cmdline_prefix(cmdline);
if (handle_special_sessionname_cmdline(cmdline, conf) ||
handle_special_filemapping_cmdline(cmdline, conf))
return;
int argc;
char **argv, **argstart;
split_into_argv(cmdline, &argc, &argv, &argstart);
for (int i = 0; i < argc; i++) {
const char *arg = argv[i];
if (!strcmp(arg, "-e")) {
if (i+1 < argc) {
/* The command to execute is taken to be the unparsed
* version of the whole remainder of the command line. */
conf_set_str(conf, CONF_remote_cmd, argstart[i+1]);
return;
} else {
cmdline_error("option \"%s\" requires an argument", arg);
}
} else if (arg[0] == '-') {
cmdline_error("unrecognised option \"%s\"", arg);
} else {
cmdline_error("unexpected non-option argument \"%s\"", arg);
}
}
conf_set_int(conf, CONF_sharrow_type, SHARROW_BITMAP);
}
const struct BackendVtable *backend_vt_from_conf(Conf *conf)
{
return &conpty_backend;
}
const wchar_t *get_app_user_model_id(void)
{
return L"SimonTatham.Pterm";
}