Reader
Module to hold the reader part of the terminal module.
- PROMPT_MARKER: str = '\x1b]'
Special prompt marker to help us figure out when we should capture a new command/output.
- TERMINAL_CAPTURE_FILE: Path = PosixPath('/home/docs/.local/state/command-line-assistant/terminal.log')
The name of the output file to store the logs.
- class TerminalRecorder(handler, winsize)[source]
Class that controls how the terminal is being read
Constructor of the class.
- Parameters:
handler (IO[Any]) – The file handler opened during the screen reader.
winsize (bytes) – A packed struct with the original terminal size.
- read(fd)[source]
Callback method that is used to read data from pty.
- write_json_block()[source]
Write a json block to the file once it’s read.
- start_capturing()[source]
Routine to start capturing the terminal output and store it in a file.
- Return type:
Note
This routine will capture every single piece of information that is displayed on the terminal as soon as it is enabled.
Currently, we only support
bashas our shell. The reason for that is that we need to inject a specific marker in thePROMPT_COMMANDandPS1to reliably capture the output. The marker can be seen in the global constant of this modulepy:PROMPT_MARKER.The log is stored under $XDG_STATE_HOME/command-line-assistant/terminal.log, if the user specify a path for $XDG_STATE_HOME, we use it, otherwise, we default to
~/.local/statefolder.