-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get the input character #1100
Comments
Since there doesn't seem to be anything we have to implement code-wise for these, I move forward with closing this issue. For discussions on using xterm.js, you can also use the following channels:
Cheers 😄. |
e.target.value get the last charset 'd',but i want get the 'pwd',what should I do |
C:\Users\wuyql\Desktop\xterm>pwd |
@smalltimoo you can keep "keys" captured via the If you still need some help with this, feel free to reach out at https://gitter.im/sourcelair/xterm.js 😄. Examplelet myBuffer = [];
// This is an xterm.js instance
term.on('key', function(key, e) {
myBuffer.push(key);
});
term.on('lineFeed', function() {
let keysEntered = myBuffer.join(''); // Or something like that
myBuffer = []; // Empty buffer
}); |
I'd love to see a plugin that can extract the command from the input line and emit an event once the command is submitted. Unfortunately it is not easy to get right. The solution above works great to capture a sequence of input keys, but imagine the user mistyped something, deletes some characters, jumps to a character using the arrow keys and then adds something in the middle of a word... uff. The user could also press the arrow up key in the middle of typing, which in most prompts will replace the current input line content with the last command from the history... I think the only way to tackle this is to wait for the lineFeed event, then check if the terminal is in normal buffer, then make sure that the cursor is in the last printed line, then try to get the last line of input, then try to resolve which part of that line belongs to the prompt, and then extract the command... |
Yep, this would need some heuristics. The |
It would be very easy if the end of the prompt (PS1) would be marked with a special control character, but afaik there is no such thing... |
Imho this is more a feature request for a shell extension than for a terminal emulator. The emulator has no knowledge of the foreground process nor the input handling, it just pumps input data and displays some (potentially total different) response (imagine the line end is not marked by NL for some reason which is totally legal). The shell on the other hand knows the foreground process (if it has job control) and is the first candidate to be asked "What command did I just enter" ... |
Related:
|
@Tyriar Thanks for the references, very useful! While reading through #576 I came up with another hack that could potentially work: Image with every lineFeed event (and after making sure that we are in the normal buffer, and the cursor is in the last line of the screen), we would send an invisible, self-defined escape sequence right after it. When doing so, this escape sequence should get echoed back to us in the next line, and in theory it should mark the very first cell right after the prompt. From that point it should be easy to parse the command... |
@mofux that's basically the idea behind #576, the problem though is that each shell needs to be explicitly supported and I'm not sure cmd or PS can support it as
|
Details
Steps to reproduce
The text was updated successfully, but these errors were encountered: