Popup.kak -- run shells and programs within a kakoune client info modal

These past few days I’ve been working on a new plugin, popup.kak. This lets you create interactive info modals that could contain a shell or command and make use of their standard output. Here’s a demo:

asciicast

An example invocation looks something like this:

popup --title open --kak-script %{ edit %opt{popup_output} } -- fish -c __fzf_find

And shows up like this:

I think it’s mostly free of bugs in its current state, but there are some missing features, namely:

  • Have a way to pass standard input to the command in the popup. This could be super useful through kak-lsp to find references without having to jump to a buffer.
  • Color support (this is kind of annoying, I’ll have to write a clone of kak-ansi).
  • Display where the cursor is.

Implementation

This is implemented using a tmux session, that is actually holding the state of the modal. The tmux session is periodically queried, and the info modal is updated if anything has changed. Keys are captured using a recursive on-key command, and sent to the tmux session. Lastly standard error and standard out are captured by augmenting the provided command with some bash redirection.

Why

Well, I really like switching to new files fuzzily, and from within my kakoune instance. I currently use a hacky wrapper around a terminal multiplexer to overlay an instance of fzf to switch between files. I wanted to see if it was possible to do something similar without wrapping kakoune in a multiplexer.

Let me know what you guys think!

8 Likes

Does Kakoune have to be running inside tmux, or does the plugin automatically start a private tmux session to run the popup command in?

Kakoune does not run inside tmux. The popup command runs under tmux and uses it as a terminal emulator so I can read it’s state and display it in the modal.

So if I understand correctly, this is spawning a tmux session consisting of the application/script that was run, using on-key to detect and send keystrokes to the tmux session, and then grabbing the tmux session’s output to send back to Kakoune?

Very clever! It never ceases to amaze me what is possible with Kakoune’s minimalist approach to plugins. I’ll have to consider something similar for when it comes time to implement a debug console in kak-dap…

Yep that’s it!

That’s a very cool approach. I’ve wanted nested modal terminals before, but never thought it might be possible to do using a continuously updating info.

Thanks! I’m kind of surprised on how well it works. I’ve added support for coloring where the cursor is in the modal, and I’m currently trying to add color support. The PoC for coloring already looks promising:

Looks like colors work :slight_smile: