Skip to content

Shell

Sub classes

Name Children Inherits
PtyShell
acptui.shell
An interactive bash / zsh in a pseudo-terminal, started on the first command.
    ProcessShell
    acptui.shell
    One process per command (Windows, or no bash / zsh): nothing carries over.

      🛈 DocStrings

      Runs the user's commands one at a time; subclasses decide how.

      Source code in src/acptui/shell.py
      class Shell:
          """Runs the user's commands one at a time; subclasses decide how."""
      
          def __init__(self, cwd: str | Path, on_output: OutputCallback | None = None) -> None:
              self.cwd = str(cwd)
              """Where the next command starts (follows ``cd`` in a persistent shell)."""
              self.on_output = on_output
              """Called with the running command whenever it has new output or finishes."""
              self.current: ShellCommand | None = None
              self.persistent = False
              """Whether state (``cd``, variables) carries over between commands."""
      
          @property
          def busy(self) -> bool:
              """Whether a command is running."""
              return self.current is not None
      
          async def run(self, command: str) -> ShellCommand:
              """Start a command; it finishes in the background (see :attr:`ShellCommand.done`)."""
              raise NotImplementedError
      
          async def send_input(self, text: str) -> None:
              """Type a line into the running command."""
              raise NotImplementedError
      
          async def interrupt(self) -> None:
              """Interrupt the running command (Ctrl+C)."""
              raise NotImplementedError
      
          def close(self) -> None:
              """End the shell and whatever runs in it."""
      
          def _notify(self, command: ShellCommand) -> None:
              if self.on_output is not None:
                  self.on_output(command)
      
          def _finish(self, command: ShellCommand, exit_code: int) -> None:
              command.exit_code = exit_code
              if self.current is command:
                  self.current = None
              self._notify(command)
      

      busy property

      busy: bool
      

      Whether a command is running.

      cwd instance-attribute

      cwd = str(cwd)
      

      Where the next command starts (follows cd in a persistent shell).

      on_output instance-attribute

      on_output = on_output
      

      Called with the running command whenever it has new output or finishes.

      persistent instance-attribute

      persistent = False
      

      Whether state (cd, variables) carries over between commands.

      close

      close() -> None
      

      End the shell and whatever runs in it.

      Source code in src/acptui/shell.py
      def close(self) -> None:
          """End the shell and whatever runs in it."""
      

      interrupt async

      interrupt() -> None
      

      Interrupt the running command (Ctrl+C).

      Source code in src/acptui/shell.py
      async def interrupt(self) -> None:
          """Interrupt the running command (Ctrl+C)."""
          raise NotImplementedError
      

      run async

      run(command: str) -> ShellCommand
      

      Start a command; it finishes in the background (see :attr:ShellCommand.done).

      Source code in src/acptui/shell.py
      async def run(self, command: str) -> ShellCommand:
          """Start a command; it finishes in the background (see :attr:`ShellCommand.done`)."""
          raise NotImplementedError
      

      send_input async

      send_input(text: str) -> None
      

      Type a line into the running command.

      Source code in src/acptui/shell.py
      async def send_input(self, text: str) -> None:
          """Type a line into the running command."""
          raise NotImplementedError
      

      :fa-brands-github: Show source on GitHub