You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+55-1Lines changed: 55 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,19 @@ Default size of the virtual terminal window is 120x40 (cols by rows), which can
65
65
be changed with `--size` argument. For example: `ht --size 80x24`. The window
66
66
size can also be dynamically changed - see [resize command](#resize) below.
67
67
68
+
### Style Support
69
+
70
+
ht supports capturing and returning terminal styling information (colors, bold, italic, etc.). Use the
71
+
`--style-mode` option to enable styled output:
72
+
73
+
-`--style-mode plain` (default) - Returns only plain text in snapshots
74
+
-`--style-mode styled` - Includes styling information in snapshots
75
+
76
+
Example:
77
+
```sh
78
+
ht --style-mode styled --subscribe snapshot
79
+
```
80
+
68
81
Run `ht -h` or `ht --help` to see all available options.
69
82
70
83
## Live terminal preview
@@ -205,6 +218,18 @@ specifying new width (`cols`) and height (`rows`).
205
218
206
219
This command triggers `resize` event.
207
220
221
+
#### setStyleMode
222
+
223
+
`setStyleMode` command allows changing the style mode during runtime to enable or
224
+
disable styled output in snapshots.
225
+
226
+
```json
227
+
{ "type": "setStyleMode", "mode": "styled" }
228
+
{ "type": "setStyleMode", "mode": "plain" }
229
+
```
230
+
231
+
This command doesn't trigger any event but affects subsequent snapshots.
232
+
208
233
### WebSocket API
209
234
210
235
The WebSocket API currently provides 2 endpoints:
@@ -280,6 +305,36 @@ Event data is an object with the following fields:
280
305
-`text` - plain text snapshot as multi-line string, where each line represents a terminal row
281
306
-`seq` - a raw sequence of characters, which when printed to a blank terminal puts it in the same state as [ht's virtual terminal](https://github.com/asciinema/avt)
282
307
308
+
When color mode is set to `styled`, additional fields are included:
309
+
310
+
-`charMap` - 2D array of characters, where `charMap[row][col]` gives the character at that position
311
+
-`styleMap` - 2D array of style IDs, where `styleMap[row][col]` gives the style ID for the character at that position
312
+
-`styles` - object mapping style IDs to style definitions with `fg`, `bg`, and `attrs` fields
313
+
314
+
Example styled snapshot for `$ ls foo/b*` where `baz.sh` is styled differently than `bar.txt`:
ht is aimed at programmatic use given its JSON-based API, however one can play
@@ -303,7 +358,6 @@ TODO: either pull those into this repo or fork them into their own `htlib` repo.
303
358
304
359
## Possible future work
305
360
306
-
* update the interface to return the view with additional color and style information (text color, background, bold/italic/etc) also in a simple JSON format (so no dealing with color-related escape sequence either), and the frontend could render this using HTML (e.g. with styled pre/span tags, similar to how asciinema-player does it) or with SVG.
307
361
* support subscribing to view updates, to avoid needing to poll (see [issue #9](https://github.com/andyk/ht/issues/9))
308
362
* native integration with asciinema for recording terminal sessions (see [issue #8](https://github.com/andyk/ht/issues/8))
0 commit comments