2 unstable releases
0.2.0 | Sep 9, 2023 |
---|---|
0.1.0 | Sep 7, 2020 |
#2200 in Parser implementations
55KB
676 lines
Yew ANSI
ANSI escape code rendering for the web.
Currently this library only covers SGR parameters (i.e. the character appearance part).
Supported SGR parameters:
- bold
- italic
- underline
- foreground and background colours:
- 3/4 bit (named colours with "bright" modifier)
- 8-bit (256-color palette)
- 24-bit (full RGB)
Features
- "yew" (default feature) - Activate the Yew components. Without this feature this crate is just an ANSI escape code parser.
Examples
See the examples directory.
lib.rs
:
ANSI escape code rendering for the web
Yew
html! {
<AnsiStatic text="Hello \u{001b}[32mWorld\u{001b}[39;1m!" />
}
This will generate the following output (whitespace added for clarity):
<pre style="font-family: monospace">
<span>Hello </span>
<span style="color:#00ff00;">World</span>
<span style="font-weight:bold;">!</span>
</pre>
Refer to AnsiRenderer
and AnsiProps
for more details.
Parsing
If you want to parse text containing ANSI escape codes you can use get_sgr_segments
to iterate over text segments along with their SgrEffect
.
If you need more control, use get_markers
to iterate over the raw Escape
codes in the text.
Dependencies
~11–20MB
~268K SLoC