I'm writing a simple task manager in blessed (the JS version). I use a list widget to display my current tasks. I can select the item using enter, however I want to use different commands with the "hovered" item, e.g., hover over a item and press d to delete the task, or c to mark it as completed.
However, from the documentation I can't find how to do it. The selected event only listens to the enter key, the list.key() doesn't know who is the "hovered" item in the list.
A simple example:
const blessed = require('blessed');
const screen = blessed.screen({smartCSR: true});
const taskList = blessed.list({keys: true, items: ['a', 'b', 'c']});
taskList.on('selected', () => { console.log('got an enter'); });
taskList.key('d', () => { console.log('got an a'); });
Is there a way to either get the selected item in the list when pressing the key, or attaching the key to the 'selected' event and then use a switch to discover which key was pressed?
In order to access selected item, you can use regular, not arrow, function in callback, in order to access "this", that refers to taskList
Note: list component should be specified with
parent: screen, in order to capture key events, please see github issueComplete sample