open-nomad/ui/app/utils/keys.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

11 lines
190 B
JavaScript
Raw Normal View History

UI: add handling for exec command-editing keys (#7601) This is a minimal implementation that closes #7463. It doesn’t include true support for moving around within the command to edit using arrow keys because it gets too complex when managing wrapping at the edge of the terminal. Instead, arrow keys are ignored. It also ignores ^A and ^E, which are cursor manipulations that pose similar problems to arrow keys. It does support ^U, which deletes the entire command. It also allows a command to be pasted, which was previously unsupported. This is accomplished by migrating from Xterm.js’s onKey handler to onData, which is recommended here: https://github.com/xtermjs/xterm.js/issues/2673#issuecomment-574897733 onData is a higher-level handler that issues events with the final interpreted data instead of the individual key events. That means the processing in this PR has changed from inspecting DOM key events to inspecting their ASCII equivalents, which I’ve extracted into a utility dictionary for use in tests and implementation. One consequence of ignoring most control characters is that if you paste a string that includes a control character, that character will be stripped. It’s somewhat strange for compound sequences like arrow keys; if you run copy('/bin/b' + '\x1b[D' + 'ash') in a Javascript console and paste what’s on the clipboard, you get "/bin/b[Dash". That’s because the left arrow key, as in that centre portion of the string, is represented by the escape character and a coded sequence. Stripping the control character leaves the coded sequence as part of the paste. That seems like an acceptable compromise vs either ignoring any pasted string with control characters (confusing UX) or trying to interpret and strip all such compound control sequences (difficult to be exhaustive).
2020-04-03 17:14:47 +00:00
export default {
LEFT_ARROW: '\x1b[D',
UP_ARROW: '\x1b[A',
RIGHT_ARROW: '\x1b[C',
DOWN_ARROW: '\x1b[B',
CONTROL_A: '\x01',
CONTROL_U: '\x15',
ENTER: '\r',
DELETE: '\x7F',
};