I am new to using the blessed library and so far, I could not get key events to work.
I would expect the following piece of code to print q
whenever the Q key is pressed and Enter
whenever the Enter key is pressed. It should also print keypress
whenever any key is pressed.
const blessed = require('blessed');
const screen = blessed.screen({
smartCSR: true,
title: 'Title',
});
screen.key('q', () => console.log('q'));
screen.key('Enter', () => console.log('Enter'));
screen.on('keypress', () => console.log('keypress'));
screen.render();
The actual behavior is that if any "printable" key (such as alphanumeric characters) is pressed then that key is just written to the console (just as if it was typed regularly). keypress
is not printed either.
The behavior is slightly different for the Enter key. Enter
is still not being printed, but keypress
is.
Is there anything wrong with my setup? I am using the default Gnome terminal under ArchLinux. However, that should not cause an issue because the program json-log-viewer, which is also blessed-based, works just fine.