### Navigation

- index
- modules |
- previous |
- Sage's Development Scripts »

# User Interface

This module provides an abstract base class that is used for displaying messages and prompting for user input.

See also

`CmdLineInterface` for an implementation of this class

AUTHORS:

- David Roe, Julian Rueth: initial version

class `sage.dev.user_interface.``UserInterface`(config)

  Bases: `object`

  An abstract base class for displaying messages and prompting the user for input.

  TESTS:

      sage: from sage.dev.user_interface import UserInterface
      sage: from sage.dev.test.config import DoctestConfig
      sage: UserInterface(DoctestConfig())
      <sage.dev.user_interface.UserInterface object at 0x...>

  `confirm`(question, default=None)

    Ask a yes/no question and return the response as a boolean.

    INPUT:

    - `question` – a string
    - `default` – a boolean or `None` (default: `None`), the default value

    TESTS:

        sage: from sage.dev.user_interface import UserInterface
        sage: from sage.dev.test.config import DoctestConfig
        sage: UI = UserInterface(DoctestConfig())
        sage: UI.confirm("Should I delete your home directory?")
        Traceback (most recent call last):
        ...
        NotImplementedError

  `debug`(message, *args)

    Display `message`.

    INPUT:

    - `message` – a string or list/tuple/iterable of strings.
    - `*args` – optional positional arguments that will be passed to `message.format()`.

    TESTS:

    Debug messages are not displayed in doctests:

        sage: from sage.dev.user_interface import UserInterface
        sage: from sage.dev.test.config import DoctestConfig
        sage: UI = UserInterface(DoctestConfig())
        sage: UI.debug("I ate filet mignon for dinner.")

  `edit`(filename)

    Drop user into an editor with `filename` open.

    OUTPUT:

    Raises a `sage.dev.user_interface_error.OperationCancelledError` if the editor exits with non-zero exit code.

    TESTS:

        sage: from sage.dev.user_interface import UserInterface
        sage: from sage.dev.test.config import DoctestConfig
        sage: UI = UserInterface(DoctestConfig())
        sage: UI.edit("filename")
        Traceback (most recent call last):
        ...
        NotImplementedError

  `error`(message, *args)

    Display `message`.

    INPUT:

    - `message` – a string or list/tuple/iterable of strings.
    - `*args` – optional positional arguments that will be passed to `message.format()`.

    TESTS:

    > sage: from sage.dev.user_interface import UserInterface sage: from sage.dev.test.config import DoctestConfig sage: UI = UserInterface(DoctestConfig()) sage: UI.error(“I ate filet mignon for dinner.”) Traceback (most recent call last): ... NotImplementedError

  `get_input`(prompt)

    Read input after displaying `prompt`.

    TESTS:

        sage: from sage.dev.user_interface import UserInterface
        sage: from sage.dev.test.config import DoctestConfig
        sage: UI = UserInterface(DoctestConfig())
        sage: UI.get_input("What do you want for dinner?")
        Traceback (most recent call last):
        ...
        NotImplementedError

  `get_password`(prompt)

    Ask for a password after displaying `prompt`.

    TESTS:

        sage: from sage.dev.user_interface import UserInterface
        sage: from sage.dev.test.config import DoctestConfig
        sage: UI = UserInterface(DoctestConfig())
        sage: UI.get_password("What is the passphrase for your safe?")
        Traceback (most recent call last):
        ...
        NotImplementedError

  `info`(message, *args)

    Display `message`.

    These are informational messages to be shown to the user, typically indicating how to proceed.

    INPUT:

    - `message` – a string or list/tuple/iterable of strings.
    - `*args` – optional positional arguments that will be passed to `message.format()`.

    TESTS:

    Info messages are not displayed in doctests:

        sage: from sage.dev.user_interface import UserInterface
        sage: from sage.dev.test.config import DoctestConfig
        sage: UI = UserInterface(DoctestConfig())
        sage: UI.info("I ate filet mignon for dinner.")
        Traceback (most recent call last):
        ...
        NotImplementedError

  `select`(prompt, options, default=None)

    Ask the user to select from list of options and return selected option.

    INPUT:

    - `prompt` – a string, prompt to display
    - `options` – iterable of strings, the options
    - `default` – an integer or `None` (default: `None`), the index of the default option

    TESTS:

        sage: from sage.dev.user_interface import UserInterface
        sage: from sage.dev.test.config import DoctestConfig
        sage: UI = UserInterface(DoctestConfig())
        sage: UI.select("Should I delete your home directory?", ("yes","no","maybe"), default=1)
        Traceback (most recent call last):
        ...
        NotImplementedError

  `show`(message, *args, **kwds)

    Display `message`.

    INPUT:

    - `message` – a string or list/tuple/iterable of strings. Each individual message will be wrapped to the terminal width.
    - `*args` – optional positional arguments that will be passed to `message.format()`.
    - `log_level=INFO` – one of `ERROR`, `WARNING`, `NORMAL`, `INFO`, or `DEBUG` (default: `INFO`). Optional keyword argument.

    TESTS:

        sage: from sage.dev.user_interface import UserInterface, DEBUG
        sage: from sage.dev.test.config import DoctestConfig
        sage: UI = UserInterface(DoctestConfig())
        sage: UI.show("I ate filet mignon for dinner.")
        Traceback (most recent call last):
        ...
        NotImplementedError
        sage: UI.show("I ate filet mignon for dinner.", log_level=DEBUG)

  `warning`(message, *args)

    Display `message`.

    INPUT:

    - `message` – a string or list/tuple/iterable of strings.
    - `*args` – optional positional arguments that will be passed to `message.format()`.

    TESTS:

    > sage: from sage.dev.user_interface import UserInterface sage: from sage.dev.test.config import DoctestConfig sage: UI = UserInterface(DoctestConfig()) sage: UI.warning(“I ate filet mignon for dinner.”) Traceback (most recent call last): ... NotImplementedError

### Navigation

- index
- modules |
- previous |
- Sage's Development Scripts »