reedline icon indicating copy to clipboard operation
reedline copied to clipboard

How to show a preview when typing or moving cursor

Open andylokandy opened this issue 1 year ago • 4 comments

Is it possible to print a preview (maybe multiline) when user is typing or moving the cursor, like a menu that the user can not interact with.

Example

When editing, print the evaluation preview of the expression under the cursor:

~/Code/reedline〉(1+1█) *3
2

Once enter is hit, clear the preview, and the main program prints the result:

~/Code/reedline〉(1+1) *3
6
~/Code/reedline〉█

In nushell, user can edit the filter expression and preview the result:

~/Code> ls | where type == 'dir█' | table
╭───┬────────┬──────┬─────────┬────────────────╮
│ # │  name  │ type │  size   │    modified    │
├───┼────────┼──────┼─────────┼────────────────┤
│ 0 │ cmd    │ dir  │ 4.0 KiB │ 2 months ago   │
│ 1 │ crates │ dir  │ 4.0 KiB │ 2 weeks ago    │
│ 2 │ dev    │ dir  │ 4.0 KiB │ 15 hours ago   │
│ 3 │ docs   │ dir  │ 4.0 KiB │ 2 hours ago    │
│ 4 │ logs   │ dir  │ 4.0 KiB │ 19 minutes ago │
│ 5 │ target │ dir  │ 4.0 KiB │ 21 hours ago   │
│ 6 │ tests  │ dir  │ 4.0 KiB │ a week ago     │
│ 7 │ xtask  │ dir  │ 4.0 KiB │ 2 months ago   │
╰───┴────────┴──────┴─────────┴────────────────╯

andylokandy avatar Sep 30 '24 08:09 andylokandy

sounds a bit dangerous. However, nushell with the explore command there is :try

fdncred avatar Sep 30 '24 10:09 fdncred

Yeah... But my use case is a math evaluator and in that case it is fine.

andylokandy avatar Sep 30 '24 12:09 andylokandy

With the current design of reedline there are no provisions for that (parallel evaluation, with managed output).

From our side this has a low priority (we as Nushell would probably only use such facilities for other status output, without clear existing requirements for that yet). So no guarantees that an addition in that direction will receive maintenance support.

Currently reedline's add-on components are all evaluated in line and in a blocking fashion. So if anything takes too long the UI slows down/freezes. We could accept something in the same vain without much redesign, but if you want that particular feature non-blocking we clearly have to prioritize the design of asynchronous updates for the more important components of reedline.

sholderbach avatar Sep 30 '24 12:09 sholderbach

Parallel evaluation is not too relative imo. To make it possible with minimal effort, reedline could manage an output buffer which is always shown below the line buffer, and reedline could also provide a function to update its content like LineBuffer::set_buffer(), and that's all. The application could listen to the cursor movement event to start evaluation, and update the output buffer once the preview is ready.

The hard point for me is the drawing logic. I'm new in this field. I think it's possible because the menu is working well. I'm appreciate if you could give me some links or file position that I can start from.

andylokandy avatar Sep 30 '24 13:09 andylokandy