Skip to content

Create cmd2-specific input() function #778

@kmvanbrunt

Description

@kmvanbrunt

Provide developers a function for reading input with the following signature:

def read_input(self, prompt: str, enable_completion: bool = False) -> str

The name isn't set in stone.

Difference between this function and the existing _pseudo_read_input

  1. Raises EOFError exceptions instead returning the string eof
  2. Turns off tab completion by default

_pseudo_read_input will be replaced by something similar to the following:

def _read_command_line(self, prompt: str) -> str:
    try:
        # Wrap in try since terminal_lock may not be locked
        try:
            # Command line is about to be drawn. Allow asynchronous changes to the terminal.
            self.terminal_lock.release()
        except RuntimeError:
            pass
        return self.read_input(prompt, enable_completion=True)
    except EOFError:
        return 'eof'
    finally:
        # Command line is gone. Do not allow asynchronous changes to the terminal.
        self.terminal_lock.acquire()

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions