Skip to content
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 show a preview when typing or moving cursor #838

Open
andylokandy opened this issue Sep 30, 2024 · 4 comments
Open

How to show a preview when typing or moving cursor #838

andylokandy opened this issue Sep 30, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@andylokandy
Copy link
Contributor

andylokandy commented Sep 30, 2024

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 andylokandy added the enhancement New feature or request label Sep 30, 2024
@fdncred
Copy link
Collaborator

fdncred commented Sep 30, 2024

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

@andylokandy
Copy link
Contributor Author

andylokandy commented Sep 30, 2024

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

@sholderbach
Copy link
Member

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.

@andylokandy
Copy link
Contributor Author

andylokandy commented Sep 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants