Hide/show toolsclient manually/automatically

I’ve been reading the posts on using toolsclient/docsclient and my impression is that if you have one of them you basically have to keep them open at all times, taking up some valuable screen real estate. Am I understanding this correctly? Is there a way to have them hide/show on demand?

Ideally, the clients would automatically popup when there is something to show. ie. I do a grep, which automatically uses toolsclient, the search results popup in a separate window, either a terminal split, tab, or new window. Then I’d have a command to dismiss it when I’m done.

Does anything like this exist already? If not, how much interest is there in a tool that would do this? I already have an architecture in mind that I think would work, but want to make sure it’s worth the time and nothing exists already.

I’m working on a plugin that will (eventually) allow you to do exactly this. Unfortunately, I rain into some race conditions when attempting to implement this specific feature, so it’s been put on hold until I get the MVP done. But it’ll get there eventually!

The thing with kak is that since it doesn’t have a windowing system, you’ll have to integrate with whichever terminal emulator or window manager you’re using. So it won’t be completely straightforward no matter what.

Do you need the string-equality (streq) hack I’ve mentioned in my kakscript computability post)?

def list-len-eq0 -params 0 nop  # empty-list test

decl str-list str_test
def streq -params 2 %{
  set         global str_test %arg{1}
  set -remove global str_test %arg{2}
  list-len-eq0 %opt{str_test}
}

Then, you can if-then-else via exceptions:

try %{ streq %arg{1} %opt{toolsclent}
#then code
} catch %{
#else code
}

This is how I defined the +=ssl alias (aka sel-editor-live-new) in sel-editor. If toolsclient is not defined, it automatically resets to %val{client}.

You also probably need a ClientClose hook (I haven’t added added this yet to sel-editor) to remove the toolsclient setting if, well, the toolsclient closes.

My post also details a way to check for a specific exception, so you can make your if-then-else foolproof.

Final note: if you use this, please add a “namespace prefix” to all commands, so they don’t collide with other plugins.

Cool that you are working on this too! I couldn’t think of a way to do this as a plug-in so I thought it would require a wrapper program. I’ll definitely take a look at your code later today.

My plan was to have two threads, one in the foreground running the primary kak ui, the other a background a toolsclient instance connected to the same session, but using the json UI. Then when a message comes through for toolsclient it would open a terminal window populated with the content from the message (would likely use another kak instance).

My plan for this was to have a set of terminal adapters; it could only support terminals that are scriptable, which is unfortunate, but I don’t see any way around this.

@raiguard I’m curious what race condition you ran into? The code seems like a source-able kakscript, with %sh call-points. So not a wrapper that re-executes kak (which could bring on server multithreading issues)

Maybe I’ve got confused?

I was attempting to add hooks that would fire right before and right after my program would print its location list. This was to make it so you could open a new client if you want, then re-focus your main client after it’s done (if you want). I attempted to use this to open a new client at the bottom of my screen before it would print the goto buffer, but it would print the goto buffer before the client actually opened, because kak does not open clients synchronously for some reason.

I’m not completely sure what you’re trying to do, but maybe you’re looking for the ClientCreate hook?