terminhtml package¶
Run shell commands and convert into an HTML/CSS animated terminal
Subpackages¶
Submodules¶
terminhtml.ansi_converter module¶
- terminhtml.ansi_converter.ansi_styles()[source]¶
Returns the ansi2html stylesheet, narrowed to what this block of ansi needs.
- Return type:
terminhtml.base_exc module¶
terminhtml.cli module¶
- terminhtml.cli.run_commands_create_html(commands=typer.Argument, setup_commands=typer.Option, input=typer.Option, allow_exceptions=typer.Option, prompt_matchers=typer.Option, command_timeout=typer.Option, cwd=typer.Option, out_path=typer.Option, partial_html=typer.Option, inline_css=typer.Option, echo=typer.Option, no_force_color=typer.Option)¶
Create an animated HTML/CSS terminal by running commands and recording their output.
Examples: ``` # Run two commands $ terminhtml “echo woo > something.txt” “cat something.txt”
# Output results to a file $ terminhtml -o output.html “echo woo”
# Run a script my-script.sh $ terminhtml “$(<my-script.sh)”
# Run setup commands before the animated session $ terminhtml “cat woo.txt” -s “echo a > woo.txt && echo b >> woo.txt”
# Output partial HTML $ terminhtml -p “echo woo”
# Allow longer-running commands $ terminhtml -t 20 “sleep 15 && echo woo”
# Animate commands that prompt for user input $ terminhtml -m “] ” -i “woo” “read -p ‘[value?] ‘ varname && echo $varname”
# Run commands in a specific directory rather than a temporary directory $ terminhtml -c .. “ls -l”
# Echo the commands to stdout $ terminhtml -e “echo foo”
# Turn off forcing color output, use the terminal’s color setting $ terminhtml -n “man grep | grep grep” ```
- Return type:
terminhtml.cli_docs module¶
terminhtml.demo_output module¶
terminhtml.exc module¶
- exception terminhtml.exc.IncorrectCommandSpecificationException[source]¶
Bases:
TerminHTMLUserException
Raised if the command specification is incorrect.
- exception terminhtml.exc.TerminHTMLUserException[source]¶
Bases:
TerminHTMLException
Base class for all expected exceptions in TerminHTML.
- exception terminhtml.exc.UserCommandException(message, output, context)[source]¶
Bases:
TerminHTMLUserException
Exception for user commands.
terminhtml.main module¶
- class terminhtml.main.CommandResults(**data)[source]¶
Bases:
BaseModel
- results: List[CommandResult]¶
- class terminhtml.main.TerminHTML(**data)[source]¶
Bases:
BaseModel
- command_results: CommandResults¶
- classmethod from_commands(commands, setup_commands=None, input=None, allow_exceptions=False, prompt_matchers=None, command_timeout=10, cwd=None, echo=False, force_color=True)[source]¶
Create a TerminHTML object from a list of commands.
- Parameters:
setup_commands¶ (
Optional
[List
[str
]]) – A command to run before the commands, the output of these commands will not show.input¶ (
Union
[List
[str
],str
,None
]) – A list of strings to send to the commands. The input element will be matched with the command by index. If a single string is passed, it will be converted into a single-element list so that it will be passed to the first command.allow_exceptions¶ (
bool
) – If True, exceptions will be raised.prompt_matchers¶ (
Optional
[List
[str
]]) – A list of regex strings to match the prompt of the command. If a prompt is matched, it will be provided the matched input.command_timeout¶ (
int
) – The timeout in seconds for each command. If a command times out, the process will fail.cwd¶ (
Optional
[Path
]) – The working directory to run the commands in. Defaults to a temporary directory when None is passed.echo¶ (
bool
) – If True, the output of the commands will be echoed to the console.force_color¶ (
bool
) – If True, will try to emulate a terminal with support for ANSI 8-bit color. If False, will allow the terminal settings to pass through from the terminhtml caller.
- Return type:
- Returns:
A TerminHTML object.
terminhtml.output module¶
- class terminhtml.output.LineEnding(value)[source]¶
-
An enumeration.
- CR = '\r'¶
- CRLF = '\r\n'¶
- LF = '\n'¶
- class terminhtml.output.LineOutput(**data)[source]¶
Bases:
BaseModel
- line_ending: LineEnding¶
- prompt_output: Optional[PromptOutput]¶
- class terminhtml.output.Output(**data)[source]¶
Bases:
BaseModel
- lines: List[LineOutput]¶