Crates.io | to-html |
lib.rs | to-html |
version | |
source | src |
created_at | 2020-11-15 05:43:47.032619 |
updated_at | 2024-11-29 19:01:31.993654 |
description | Render a terminal with ANSI colors as HTML |
homepage | https://github.com/Aloso/to-html |
repository | https://github.com/Aloso/to-html |
max_upload_size | |
id | 312497 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Terminal wrapper for rendering a terminal on a website by converting ANSI escape sequences to HTML. Works with many shells, including bash, fish, ksh and zsh.
The changelog can be found here.
How to install to-html is explained on the releases page.
Execute a command:
to-html 'echo "Hello world"'
Execute several commands:
to-html 'echo "Hello "' 'echo world' ls
Commands can contain shell syntax, including pipes and redirections:
to-html "echo Hello world! | grep 'H' > somefile.txt"
By default, it uses the same shell you are using. If it doesn't recognize the shell, it defaults to bash. Use --shell
/-s
to use a different shell:
to-html -sfish "../" "ls" # executed with fish
By default, to-html emits a <pre>
tag. Use --doc
/-d
to generate a whole HTML document (including CSS):
to-html -d "ls --color" > output.html
By default, to-html only displays an arrow (>
) as prompt. To display the current working directory, pass --cwd
/-c
:
to-html -c "cd .." "ls"
Example output:
~/Develop/to-html/crates $ cd .. ~/Develop/to-html $ ls Cargo.lock CHANGELOG.md docs README.md target Cargo.toml crates LICENSE src ~/Develop/to-html $
(colors can't be shown on GitHub)
You can create a configuration file named config.toml
:
$XDG_CONFIG_HOME/to-html/config.toml
or ~/.config/to-html/config.toml
$HOME/Library/Application Support/to-html/config.toml
Example file with defaults:
[shell]
program = "bash" # override with --shell <PROGRAM>
[output]
cwd = false # override with --cwd
full_document = false # override with --doc
highlight = [] # override with --highlight <COMMANDS>
css_prefix = "" # override with --prefix <PREFIX>
to-html
only supports SGR parameters (text style and colors). However, programs that overwrite their output, like for progress bars, seem to "just work". Please correct me if I'm wrong.
If you need more advanced terminal features on your website, may I suggest to use xterm.js.
Include this on your website to get syntax highlighting for the prompt:
.terminal {
background-color: #141414;
overflow: auto;
color: white;
line-height: 120%;
}
.terminal .shell {
color: #32d132;
user-select: none;
pointer-events: none;
}
.terminal .cmd {
color: #419df3;
}
.terminal .hl {
color: #00ffff;
font-weight: bold;
}
.terminal .arg {
color: white;
}
.terminal .str {
color: #ffba24;
}
.terminal .pipe,
.terminal .punct {
color: #a2be00;
}
.terminal .flag {
color: #ff7167;
}
.terminal .esc {
color: #d558f5;
font-weight: bold;
}
.terminal .caret {
background-color: white;
user-select: none;
}
The default terminal colors can be overridden with CSS classes, for example:
.terminal {
--red: #f44;
--bright-red: #f88;
}
You can specify a custom prefix, e.g. with --prefix 'foo-'
, used by all the CSS classes and variables. For example, .terminal
then becomes .foo-terminal
, and --red
becomes --foo-red
.
> to-html 'cargo test' "to-html 'cargo test'"
In the Gnome terminal, you can define a key binding to copy terminal content as HTML.
Please be friendly and respectful to others. This should be a place where everyone can feel safe, therefore I intend to enforce the Rust code of conduct.
I appreciate your help! The easiest way to help is to file bug reports or suggest new features in the issue tracker.
If you want to create a pull request, make sure the following requirements are met:
Also, to pass continuous integration, the code must
That's it! If you have any questions, feel free to create an issue.