question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Terminal doesn't respond to keypresses

See original GitHub issue

I can’t seem to get input from a Terminal when using xterm.js in a html page. I apologize in advance if this is a silly error on my end, but I cannot figure out what I did wrong.

Details

  • Browser and browser version: Google Chrome | 84.0.4147.89 (Official Build) (64-bit)
  • OS version: Ubuntu 20.04 LTS x86_64
  • xterm.js version: 4.8.1

Steps to reproduce

  1. Put this into a file:
<!DOCTYPE html>
<html>
  <head>
   <meta charset="UTF-8">
   <title>Broken :(</title>
   <link rel="stylesheet" href="node_modules/xterm/css/xterm.css" />
   <script src="node_modules/xterm/lib/xterm.js"></script>
  </head>

  <body>
   <div id="terminal"></div>

   <script type = "text/javascript">
      var term = new Terminal();
      term.open(document.getElementById('terminal'));
      term.writeln('Hello World!');
      term.onKey = (key, ev) => {
          console.log(`Key entered: ${key}`);
      }
   </script>
  </body>
</html>
  1. Open it in browser (same behavior also observed when using a basic HTTP server).
  2. There is a properly styled terminal but I cannot type in it. Nothing happens visually. There is also no output in the console.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Tyriarcommented, Sep 2, 2020

@anatoly314 I think it’s like this because the keyboard (the IME) is hanging onto the words until they are committed. This is similar to how other language keyboards work, in the below image the Japanese characters are not part of the textarea just yet, but part of the “composition” until committed.

image

Proper mobile support would really need some more thinking on how to make the experience nice, plus you would likely require a bunch of key/modifier buttons to do things like holding ctrl and pressing esc. Right now it’s out of scope for the lib until we decide to tackle https://github.com/xtermjs/xterm.js/issues/1101

1reaction
Tyriarcommented, Jul 31, 2020

term.onKey = (key, ev) => {

term.onKey is a function:

term.onKey((key, ev) => {

});

Also you should typically be using onData instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Unresponsive Terminal - Learning the UNIX ... - O'Reilly
If you can type commands, but nothing happens when you press RETURN, try pressing LINE FEED or typing CTRL-J. If this works, your...
Read more >
If your Mac doesn't respond to key presses - Apple Support (KG)
Choose Apple menu > System Settings, click Accessibility in the sidebar, then click Pointer Control on the right. (You may need to scroll...
Read more >
How to Fix Can't Type in Terminal Issue in Linux
Try pressing Ctrl + Z in your non-responding terminal to suspend any active task.
Read more >
keyboard - What is the most probable cause of terminal freeze ...
If a terminal is frozen but not the rest of the GUI, then the first place to check is if you typed Ctrl...
Read more >
Fix Keyboard Input on Terminals - Please - LeoNerd
I want terminal keypresses to Just Work. What do I mean Just Work? ... Explain that, because their program doesn't correctly handle these ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found