Parameters:
nude
(bool, optional): IfTrue
, removes command signals from the command output. Defaults toTrue
.rm_boilerplate
(bool, optional): IfTrue
, sends an initial command to clear unnecessary startup text from the command line interface. Defaults toTrue
.end_signal
(str, optional): A unique string used to indicate the end of a command's output. It helps to ensure the command output does not mix with regular output. Defaults to a random string unlikely to occur in normal output.log_mode
(bool, optional): IfTrue
, logs all terminal text internally. Useful for debugging or tracking command history. Defaults toFalse
.
Behavior:
- Initializes an instance of the
CmdInterface
class. - Creates a subprocess that runs the command line interface (
cmd
). - Sets up basic properties and manages an initial empty command if
rm_boilerplate
isTrue
.
Behavior:
- Ensures the subprocess is properly closed and terminated when the
CmdInterface
instance is destroyed.
Behavior:
- Similar to
__del__
, this method explicitly closes and terminates the associated subprocess.
Parameters:
command
(str): The command string to be executed in the command line interface.
Behavior:
- Sends a command to the command line interface.
- Appends a unique end signal to the command to detect when the output ends.
- Waits and collects the output until the end signal is detected.
- Optionally strips the command end signal from the output if
nude
isTrue
. - If
log_mode
isTrue
, adds the output to the internal log. - Handles concurrent command sending using a thread locking mechanism but no ordered queue.
Returns:
output
(list of str): The output lines in a list produced by the command, optionally cleaned of command signals.
Returns:
- A copy of the log list containing all command outputs logged so far.
Behavior:
- Enables logging mode, which causes all outputs to be saved to the internal log.
Behavior:
- Disables logging mode, stopping the accumulation of outputs in the internal log.
Returns:
- The total number of commands sent since the instance was created. Minus the optional starting command that clears boilerplate.