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

Feature request: Ability to use $EDITOR to write comments #1380

Open
ConorMurphy21 opened this issue Jan 30, 2025 · 16 comments
Open

Feature request: Ability to use $EDITOR to write comments #1380

ConorMurphy21 opened this issue Jan 30, 2025 · 16 comments
Labels
enhancement Feature Request

Comments

@ConorMurphy21
Copy link

:comment and :tag functionality is awesome. It's super useful to be able to write comments to both keep landmarks for yourself to know where you are, as well as to call out potentially buggy behaviour. I've also found them useful for documenting buggy behaviour with logs by using a script that writes out the logs and comments in a markdown file.

For this second purpose, having the ability to edit longer comments in an editor of choice instead of command line would be super useful. Especially with the support for markdown and newlines. It would be a lot less tedious to handle new lines. And a text editor may have syntax highlighting for markdown.

Hopefully this isn't too hard to implement, I'm not sure how curses is with allowing editors to take over.

@ConorMurphy21 ConorMurphy21 added the enhancement Feature Request label Jan 30, 2025
@tstack
Copy link
Owner

tstack commented Jan 31, 2025

It's good to hear that you're making use of comments/tags. I don't always know what functionality folks are using and am sometimes tempted to remove things.

As for the editor, I've always wanted to replace readline with a builtin multiline editor. I think I'll finally bite the bullet and do it for the version after the upcoming v0.12.4 release. In the case of comments, I can imagine clicking on the comment in the main view and you can just start editing right there instead of down in the prompt.

I'm not sure how curses is with allowing editors to take over.

The current readline functionality works by running readline in a subprocess and emulating a vt52 console. I've always thought about doing that for other programs, but I suspect it would be pretty finicky.

@tstack
Copy link
Owner

tstack commented Feb 17, 2025

I've pushed a change to get this working in the main prompt. Here's a capture of it in action:

multiline-comment.mp4

So, when you enter :comment, the prompt switches to multiline with a height of five lines. You can then move around as usual and with emacs-like key bindings. There is also syntax-highlighting for Markdown directives. Since ENTER will insert a new line, you press CTRL-X to perform the operation.

The top-of-tree is still unstable, but if you have some time to give it a go, I'd be interested in your feedback. Thanks.

@ConorMurphy21
Copy link
Author

Yeah sure I can check it out. Is there a link to a nightly build for Linux I can find or should I just build from sources.

My initial thoughts are, already looks a lot more useable for multiline comments than before. Seems reasonable to only show abt 3-5 lines of the the block since you can see what was commented there above anyways.

I think I would maybe consider making it so the first line of the comment is on a new line, it seems a little strange to see the test on the same line as the comment, could you edit the :comment part?

Otherwise looks good except I don't know EMACS keybinds yet, but I'm since I was mostly looking for multiline paragraph writing keybinds won't make a massive difference.

@tstack
Copy link
Owner

tstack commented Feb 18, 2025

Is there a link to a nightly build for Linux I can find or should I just build from sources.

The bins workflow produces binaries on any changes. Here's a recent one:

https://github.com/tstack/lnav/actions/runs/13395971018

I think I would maybe consider making it so the first line of the comment is on a new line

That's possible, I can experiment with it.

could you edit the :comment part?

Yes, it's still the same command prompt. So, you could change the :comment to another command and it should shrink back down (but, it's glitching right now and not handling the change totally correctly).

I don't know EMACS keybinds yet

They're basically the same as the readline hotkeys, but there are a couple more. I need to wire up F1 so that it shows the help for the editor, which has the bindings.

@ConorMurphy21
Copy link
Author

Yes, it's still the same command prompt. So, you could change the :comment to another command and it should shrink back down (but, it's glitching right now and not handling the change totally correctly).

Interesting, yeah I don't know about what's easier to implement, but if that's glitchy and hard to get working I'd think that just having it be there but not considered part of the command prompt anymore is fine. I don't think people would often want to change the command away from :comment instead of just aborting and typing a different command.

@ConorMurphy21
Copy link
Author

I'm not sure if it's from these changes or not but, :prompt <initialvalue> isn't working. I was checking for ease of use with keybinding something to :prompt command : 'comment ' but initialvalue doesn't get filled.

I'm also wondering is :comment expected? It pops up a help text, on first enter, and then second enter adds the word comment to the new line. Seems a little strange but I guess enter enter is also a strange thing to type.

@tstack
Copy link
Owner

tstack commented Feb 18, 2025

but if that's glitchy and hard to get working

It's not terribly hard to get working. Making the :comment part uneditable might be harder to do actually... Anyhow, this is still a work in progress, there's various things that are not wired up or debugged yet.

I'm not sure if it's from these changes or not but, :prompt isn't working.

It's these changes, I haven't gotten around to restoring that yet.

It pops up a help text, on first enter, and then second enter adds the word comment to the new line. Seems a little strange but I guess enter enter is also a strange thing to type.

The completion logic is opening the popup on the 2nd line with "comment" selected for some reason. Not sure why it's suggesting that, probably not hard to fix.

@ConorMurphy21
Copy link
Author

Just thought I'd add that I have a script called update-comment.lnav so that the existing comment will already be populated in the command line. So just thought it might be worth testing how something like this would work with the multiline prompt. (I assume it would be fine but wasn't able to check myself due to the :prompt not being rewired yet)

#
# @synopsis: update-comment
# @description: prompt with :comment <existing-comment> if log already has a comment
#

# find the current line depending on movement mode
;SELECT 
   CASE movement
      WHEN 'cursor' THEN selection
      WHEN 'top' THEN top
   END as current
 FROM lnav_top_view  

# find the comment associated with the current line
;SELECT printf("'comment %s'", log_comment) as comment
   FROM all_logs
   WHERE log_line = $current

# open the file
:eval :prompt command : ${comment}

@tstack
Copy link
Owner

tstack commented Feb 20, 2025

Hmm, I thought the comment was already pre-populated when you type out :comment. Does the script do something different?

@ConorMurphy21
Copy link
Author

Hmm, yeah it doesn't seem to populate the comment for me, maybe not on the latest or maybe bug in my environment.
The script doesn't do much special, I made it before comment was multiline and it wasn't being populated in those versions either.

@tstack
Copy link
Owner

tstack commented Feb 20, 2025

Thanks for the heads up on that. I’m out right now, I will follow up later

@tstack
Copy link
Owner

tstack commented Feb 20, 2025

Here's what I see on lnav v0.12.3 on macOS/Terminal.app:

Image

Here's the top-of-tree:

Image

Would you be able to send a capture of what you see?

@ConorMurphy21
Copy link
Author

ConorMurphy21 commented Feb 20, 2025

Ah I see you get the comment there if you use tab complete (I didn't realise that existed good to know). I guess what makes my script special then is I can bind a key to it so that I don't have to type :com and tab. So then yeah my main hope is just that :prompt when given an initial value with new lines will properly expand to the 5 line editor.

Edit:
Oh nevermind :prompt command : 'comment ' seems to call tab complete, so as long as tab complete is working I don't think my script is special.

@tstack
Copy link
Owner

tstack commented Feb 20, 2025

Ah, yes, the prefill only working on tab-complete is the bug. I tried a really old version (v0.10.1) and there it would work when pressing space.

So then yeah my main hope is just that :prompt when given an initial value with new lines will properly expand to the 5 line editor.

I think this is working again on top-of-tree.

@tstack
Copy link
Owner

tstack commented Feb 27, 2025

Just FYI: as mentioned in #1396, pressing CTRL+O will transfer the current contents of the prompt to a file named saved-prompt.lnav in the lnav config directory. If VSCode is available, that file will be opened for editing. You can then run that script with |saved-prompt. This seemed useful for saving a prompt to a file for safe keeping or turning it into a script.

@ConorMurphy21
Copy link
Author

Sounds maybe useful for writing comments, definitely super useful for writing lnav scripts tho and playing around with sql queries!

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

No branches or pull requests

2 participants