xavierog / moulti

Moulti is a CLI-driven Terminal User Interface (TUI) displaying arbitrary outputs inside visual, collapsible blocks called steps.
MIT License
108 stars 4 forks source link

[FR] maintain expanded/collapsed preference for incoming messages #11

Closed huyz closed 1 week ago

huyz commented 1 month ago

Once I hit x or o to expand or collapse all, it would be nice if incoming messages would obey that preference. Right now if I hit o, new messages come in expanded.

xavierog commented 1 month ago

Right now if I hit o, new messages come in expanded.

Technically, new steps come in the way they were described client-side, and that part of Moulti defaults to expanded. But I see what you mean. I'll try to think of a smart way to implement that.

xavierog commented 2 weeks ago

New expand/collapse keybindings are available in the devel branch: image

Additionally, the environment variable MOULTI_ENFORCE_COLLAPSIBLE (possible values: collapse, expand) does the same as soon as Moulti starts.

huyz commented 1 week ago

Thanks! I'm trying it out.

I'm thinking that maybe there should always be an exception when there's a prompt, in which case the step should auto-expand regardless of the current collapsed state since there can be no progress unless the user expands the item and inputs some keystroke(s).

My ansible runs start with checking that I have the right ssh key loaded up, and if not yet loaded, it's added to my ssh-agent, which prompts for a passphrase. Since I prefer to start off with all steps as collapsed, then my Ansible runs often start with a collapsed prompt step, which is a bit inconvenient and odd.

xavierog commented 1 week ago

I expected that request :) I'll have a look.

xavierog commented 1 week ago

Actually, we may have solved this issue from the wrong end. Since the driver here is Moulti's own Ansible callback plugin, we could simply implement an environment variable named MOULTI_ANSIBLE_COLLAPSE that describes what to collapse. By default, nothing would be collapsed and, for instance, export MOULTI_ANSIBLE_COLLAPSE=step would collapse step widgets (and only step widgets) from the very start. Question widgets would naturally remain expanded.

Of course, we can keep the o/x/O/X/Ctrl+o/Ctrl+x keybindings, they do not hurt and can be a good complement to the "Lock scroll" feature.

What do you think?

huyz commented 1 week ago

Sounds good to me

xavierog commented 1 week ago

Ok, I have implemented environment variable MOULTI_ANSIBLE_COLLAPSE. Later, we could introduce another variable that defines what to do after a question was answered: collapse it (delay), remove it, leave it untouched, etc.

huyz commented 1 week ago

You think step could also exclude collapsing the PLAY RECAP at the end?

xavierog commented 1 week ago

You think step could also exclude collapsing the PLAY RECAP at the end?

I am going to adjust MOULTI_ANSIBLE_COLLAPSE so it deals with Ansible concepts instead of Moulti widgets.

xavierog commented 1 week ago

Done. MOULTI_ANSIBLE_COLLAPSE now accepts a comma-separated list of Ansible concepts: prompt, task, recap. MOULTI_ANSIBLE_COLLAPSE=task matches your needs.

By the way, this is not documented, but Moulti's Ansible stdout callback plugin assigns meaningful TCSS classes:

Ansible concept Moulti Widget TCSS class
Playbook divider ansible_playbook
Play divider ansible_play
Task step ansible_task
Recap step ansible_recap
Prompt inputquestion question ansible_prompt

PS: do not git pull, I have force-pushed :roll_eyes:

xavierog commented 1 week ago

Fixed in 1.15.0.