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

Improve user experience of interactive mode #136

Open
wants to merge 8 commits into
base: fkloss/numpy2
Choose a base branch
from

Conversation

luator
Copy link
Member

@luator luator commented Nov 7, 2024

Description

Use cmd.Cmd for interactive mode. This gives some benefits over doing things manually:

  • Tab completion and history of commands
  • help command for free
  • Code gets a bit nicer
  • Allows to easily add command arguments. This is already done for show_job which now expects the ID as argument instead of separately prompting for it (as a bonus, there is even tab completion for the argument :) ).

While working on this, also make the output a bit nicer:

  • Remove superfluous prints (no need to say this is the "list of successfull jobs" if just one line above I entered the command list_successful_jobs).
  • Use Cmd.columnize for lists of job IDs. Results in much nicer, more readable output.

Note that calling show_job without argument now results in an error (expects ID as argument). I don't consider this as breaking change w.r.t. versioning, though, as it only affects the interactive command, i.e. no existing script/config or the like should break due to this change.

Resolves #47.
Resolves #135.

Do not merge before

Use the readline module to add tab-completion for the available
commands.  This also automagically gives us arrow-up-history for the
input prompt.

Note that the history is not perfect as it also includes input from
other prompts (e.g. the question whether an existing output directory
should be deleted) but I think it's good enough.

Resolves #47.
@luator luator added the feature label Nov 7, 2024
@luator luator added this to the 3.1 milestone Nov 7, 2024
@luator luator self-assigned this Nov 7, 2024
Use the cmd.Cmd class for interactive mode.  This gives some benefits
over doing things manually:

- No need to take care of tab-completion ourselves
- `help` command for free
- Code gets a bit nicer
- Allows to easily add command arguments (not done in this commit,
  though)
Instead of just always exiting the command loop after one command, make
it based on the return value of the command function.  If all goes well,
it should return True to exit the loop but in case of an error (e.g.
invalid ID provided), it can return False, so the prompt stays open and
the user can try again.
It is always possible to exit the loop by simply pressing enter on an
empty line.
Instead of prompting for it after entering the command, it now expected
the job ID as argument (e.g. `show_job 42`).
There is also tab-completion for the argument (not sure how useful this
is but it might be nice to easily get a list of valid IDs).
This results in more nicely structured output, which is easier to read.
I don't see any gain in being told that the following is the "list of
running jobs" after I just entered `list_running_jobs` (which will still
be visible in the terminal just one line above).
Simple remove those prints from the various list functions.
@luator luator changed the title Tab-completion & history for interactive mode Improve user experience of interactive mode Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant