xavierog / moulti

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

[FR] Support Ansible's `pause` module's interactive prompting #14

Closed huyz closed 1 month ago

huyz commented 1 month ago

Following up on the discussion at https://github.com/xavierog/moulti/discussions/6#discussioncomment-10094741 :

I have some Ansible playbooks that won't run properly because of interactive prompts from the builtin Ansible module pause.

Example:

- name: Prompt for ssh password if necessary
  when: ansible_password is undefined
  block:
    - name: PAUSE | Conditionally prompt for ssh password
      ansible.builtin.pause:
        prompt: "Password for {{ ansible_user | d('') }}@{{ ansible_host | d('unknown') }}"
        echo: false
      register: password_prompt
      no_log: true

    - name: SET_FACT | Set ansible_password
      ansible.builtin.set_fact:
        ansible_password: "{{ password_prompt.user_input }}"
      no_log: true

The problem I get is:

ok: [mac] => {"ansible_facts": {"password_prompt": null}, "changed": false}                                                                                                                                                                                                  
    [WARNING]: Not waiting for response to prompt as stdin is not interactive   

This is separate from supporting interactivity for Ansible's vars_prompt feature (support for which was added in v1.13.0)

xavierog commented 1 month ago

Technical notes: under the hood, supporting the pause module implies to support Display.prompt_until, a method that takes 5 arguments:

The first three arguments are already ok in my working directory. interrupt_input and complete_input were designed with a tty in mind and translating them to a TUI requires some care:

Applied to the pause module, that would leave us with one input field and three buttons: "Interrupt", "A" and "C" (respectively "Abort" and "Continue").

These buttons should ideally appear right under the input field. The input field is not always necessary, but there is no proper way to tell. There are various approaches to that:

xavierog commented 1 month ago

extending inputquestion so it offers optional push-buttons.

I chose this way. Specifically, I introduced a question widget that combines the abilities of inputquestion and buttonquestion:

questions-step05

widget \ feature input field buttons
inputquestion yes no
buttonquestion no at least 1
question Yes at least 1

That should help me implement this feature request.

xavierog commented 1 month ago

I have implemented and pushed prompt_until():

Your example looks like this: moulti-pause

This feature should land in the next release.

huyz commented 1 month ago

Wow, that's awesome! Bien joué!

xavierog commented 1 month ago

This feature is now available as part of Moulti 1.14.0.

huyz commented 1 month ago

@xavierog Tested and it works great.

Btw, is there a keyboard shortcut to get my cursor inside the prompt's textbox?

xavierog commented 1 month ago

Btw, is there a keyboard shortcut to get my cursor inside the prompt's textbox?

Not in 1.14.0. But I have just pushed a commit (in the devel branch) that implements Ctrl+t and Ctrl+y, which jump to the previous/next unanswered question.