-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrender_state.go
More file actions
103 lines (83 loc) · 3.41 KB
/
render_state.go
File metadata and controls
103 lines (83 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package libghostty
// Render state for creating high-performance renderers.
// Wraps the GhosttyRenderState C APIs (excluding row/cell iterators).
/*
#include <ghostty/vt.h>
*/
import "C"
// RenderState holds the state required to render a visible screen
// (viewport) of a terminal instance. It is stateful and optimized
// for repeated updates from a single terminal, only updating dirty
// regions of the screen.
//
// Basic usage:
// 1. Create an empty render state with NewRenderState.
// 2. Update it from a terminal via Update whenever needed.
// 3. Read from the render state to get data for drawing.
//
// C: GhosttyRenderState
type RenderState struct {
ptr C.GhosttyRenderState
}
// RenderStateDirty describes the dirty state after an update.
// C: GhosttyRenderStateDirty
type RenderStateDirty int
const (
// RenderStateDirtyFalse means not dirty; rendering can be skipped.
RenderStateDirtyFalse RenderStateDirty = C.GHOSTTY_RENDER_STATE_DIRTY_FALSE
// RenderStateDirtyPartial means some rows changed; renderer can
// redraw incrementally.
RenderStateDirtyPartial RenderStateDirty = C.GHOSTTY_RENDER_STATE_DIRTY_PARTIAL
// RenderStateDirtyFull means global state changed; renderer should
// redraw everything.
RenderStateDirtyFull RenderStateDirty = C.GHOSTTY_RENDER_STATE_DIRTY_FULL
)
// CursorVisualStyle describes the visual style of the cursor.
// C: GhosttyRenderStateCursorVisualStyle
type CursorVisualStyle int
const (
// CursorVisualStyleBar is a bar cursor (DECSCUSR 5, 6).
CursorVisualStyleBar CursorVisualStyle = C.GHOSTTY_RENDER_STATE_CURSOR_VISUAL_STYLE_BAR
// CursorVisualStyleBlock is a block cursor (DECSCUSR 1, 2).
CursorVisualStyleBlock CursorVisualStyle = C.GHOSTTY_RENDER_STATE_CURSOR_VISUAL_STYLE_BLOCK
// CursorVisualStyleUnderline is an underline cursor (DECSCUSR 3, 4).
CursorVisualStyleUnderline CursorVisualStyle = C.GHOSTTY_RENDER_STATE_CURSOR_VISUAL_STYLE_UNDERLINE
// CursorVisualStyleBlockHollow is a hollow block cursor.
CursorVisualStyleBlockHollow CursorVisualStyle = C.GHOSTTY_RENDER_STATE_CURSOR_VISUAL_STYLE_BLOCK_HOLLOW
)
// RenderStateColors holds all color information from a render state,
// retrieved in a single call via the sized-struct API.
// C: GhosttyRenderStateColors
type RenderStateColors struct {
// Background is the default/current background color.
Background ColorRGB
// Foreground is the default/current foreground color.
Foreground ColorRGB
// Cursor is the cursor color when explicitly set by terminal state.
// Only valid when CursorHasValue is true.
Cursor ColorRGB
// CursorHasValue is true when Cursor contains a valid explicit
// cursor color value.
CursorHasValue bool
// Palette is the active 256-color palette.
Palette Palette
}
// NewRenderState creates a new empty render state.
func NewRenderState() (*RenderState, error) {
var ptr C.GhosttyRenderState
if err := resultError(C.ghostty_render_state_new(nil, &ptr)); err != nil {
return nil, err
}
return &RenderState{ptr: ptr}, nil
}
// Close frees the underlying render state handle. After this call,
// the render state must not be used.
func (rs *RenderState) Close() {
C.ghostty_render_state_free(rs.ptr)
}
// Update updates the render state from a terminal instance. This
// consumes terminal/screen dirty state. The terminal must not be
// used concurrently during this call.
func (rs *RenderState) Update(t *Terminal) error {
return resultError(C.ghostty_render_state_update(rs.ptr, t.ptr))
}