Skip to content

shell: Rework getval with ptpython

Valentin Valls requested to merge use-pt-prompt into master

The getval stuffs was using click which is not really convenient in this case.

This MR reworks the implementation to use prompt_toolkit instead of the use of click.

  • Allow to use Ctrl-C during the getval, which raise the defult exception
  • An argument ki_default can be defined to return a default value in case of keyboard interrupt
  • Use validator with error message
  • Added clear_screen to clear the screen before asking the question
  • Using style to format the result
  • Expose title and subtitle for convenience
  • Use getval in the KB focusing procedure
  • No more click dependency (there was no direct dependency to click in the BLISS deps)

Future improvements

Could be improved with

  • auto completion
  • press key without waiting for return (for example for the yes/no stuff)
  • selection with arrow and return key

Formatting

This use prompt toolkit formatting.

So what annoying people can use there own style if they want.

Here is the default

image

Here is with some styles

This can be part of the setup of the beamline session

from bliss.shell import getval
from prompt_toolkit.styles import Style
getval.STYLE = Style.from_dict({
    "": "", # user input
    "question": "orange bold",
    "prompt_char": "yellow",
    "valid_input": "red bold",
    "description": "blue",
    "title": "yellow",
    "subtitle": "bold",
    }
)

image

Edited by Valentin Valls

Merge request reports