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
Same as `Display` but also returns the terminal character-cell dimensions the rendered image occupies. Use this instead of `Display` + a separate size calculation to avoid decoding the image twice.
Cell pixel dimensions are read from the terminal via `TIOCGWINSZ`; fallback is 8×16 px/cell.
47
+
48
+
## `termimage.Clear`
49
+
50
+
```go
51
+
func Clear(w io.Writer, proto Protocol, rows int) error
52
+
```
53
+
54
+
Erases a previously rendered image.
55
+
56
+
| Protocol | Behaviour |
57
+
|----------|-----------|
58
+
| `Kitty` | Sends `\x1b_Ga=d,d=A\x1b\\` (delete all visible placements). `rows` is ignored. |
59
+
| `Sixel`, `HalfBlock` | Moves cursor up `rows` lines then erases to end of screen (`\x1b[{rows}A\x1b[J`). Cursor must be on the last row of the image before calling. |
60
+
61
+
Pass the `rows` value returned by `DisplayWithSize`.
32
62
33
63
## `termimage.Options`
34
64
@@ -42,11 +72,15 @@ type Options struct {
42
72
43
73
| Field | Default | Description |
44
74
|-------|---------|-------------|
45
-
|`MaxWidth`| terminal pixel width | Max output width in pixels|
46
-
|`MaxHeight`| terminal pixel height × 2| Max output height in pixels|
75
+
|`MaxWidth`| terminal cols (character cells) | Max pixel width. For HalfBlock: 1 px = 1 character column.|
76
+
|`MaxHeight`|`(terminal rows − 2) × 2` for HalfBlock; `(terminal rows − 2) × cell height px` for Kitty/Sixel | Max pixel height. Minus 2 rows leaves headroom for the shell prompt.|
|`Sandboxed`|`false`| Run decode in isolated subprocess |
49
79
80
+
**Aspect ratio:**`MaxWidth` and `MaxHeight` are independent upper bounds. `resize.Fit` computes `scale = min(MaxWidth/srcW, MaxHeight/srcH)` and applies it uniformly — the image fills whichever dimension is the tighter constraint. When only one dimension is set explicitly, the other comes from terminal detection.
81
+
82
+
**HalfBlock and text layout:** HalfBlock renders using real terminal character cells (`▀` U+2580). Unlike Kitty or Sixel, the output occupies rows × cols cells in the scroll buffer. Cursor save/restore (`\x1b[s` / `\x1b[u`) does **not** undo cell content. TUIs that need pixel-layer rendering should use Kitty or Sixel: call `detect.Best()` first and handle the case where it returns `HalfBlock`.
83
+
50
84
## `termimage.MaybeRunWorker`
51
85
52
86
```go
@@ -66,4 +100,4 @@ image, writes raw RGBA to stdout, and calls `os.Exit(0)`.
0 commit comments