1package domain
2
3import (
4 "time"
5
6 "github.com/bnema/vev/internal/domain/terminalcap"
7)
8
9// MinBarInterval is the minimum supported bar refresh interval.
10const MinBarInterval = time.Second
11
12// DefaultWordSeparators matches tmux's practical shell-oriented word boundaries.
13const DefaultWordSeparators = " -_@"
14
15// ThemeMode selects how vev derives its color scheme.
16type ThemeMode int
17
18const (
19 // ThemeAuto follows the attached client's reported color scheme.
20 ThemeAuto ThemeMode = iota
21 // ThemeDark forces vev's built-in dark palette.
22 ThemeDark
23 // ThemeLight forces vev's built-in light palette.
24 ThemeLight
25)
26
27// ConfigEntry preserves one parsed config key/value in file order.
28type ConfigEntry struct {
29 Key string
30 Value string
31}
32
33// SnapshotConfig contains user-configurable snapshot restore settings.
34type SnapshotConfig struct {
35 RestoreProcesses []string
36 RestoreProcessesSet bool
37}
38
39// defaultSnapshotRestoreProcesses is the default allowlist for process restore.
40var defaultSnapshotRestoreProcesses = []string{
41 "vi", "vim", "nvim", "emacs", "man", "less", "more", "tail", "top", "htop", "btop",
42 "claude", "codex", "pi", "opencode",
43}
44
45// DefaultSnapshotRestoreProcesses returns a copy of the default process restore allowlist.
46func DefaultSnapshotRestoreProcesses() []string {
47 return append([]string(nil), defaultSnapshotRestoreProcesses...)
48}
49
50// BarConfig contains user-configurable bar settings.
51type BarConfig struct {
52 TopRight string
53 BottomRight string
54 Interval time.Duration
55 // Transparent keeps the terminal background behind the top and bottom
56 // bars instead of the theme surface color (bar.background = off).
57 Transparent bool
58}
59
60// CopyConfig contains copy-mode selection and mouse motion settings.
61type CopyConfig struct {
62 WordSeparators string
63 ReduceMotion bool
64}
65
66// PaletteConfig contains palette placement settings. A false AnchorSet uses the
67// adaptive automatic placement.
68type PaletteConfig struct {
69 Anchor Anchor
70 AnchorSet bool
71}
72
73// FloatingConfig contains launch and sizing settings for per-tab floating panes.
74type FloatingConfig struct {
75 Command string
76 Width int
77 Height int
78}
79
80// NavConfig contains directional navigation overflow settings.
81type NavConfig struct {
82 OverflowTabs bool
83 OverflowSessions bool
84}
85
86// TabsConfig contains tab label display settings.
87type TabsConfig struct {
88 // TerminalTitle includes the focused pane's OSC terminal title in tab
89 // labels (top bar and session picker). The process name always shows.
90 TerminalTitle bool
91}
92
93// EphemeralConfig contains numbered-session lifetime settings.
94type EphemeralConfig struct {
95 // CloseOnExit removes an ephemeral session once its last attachment ends
96 // definitively: a closed client process (Detach{Closed}), or an expired
97 // park or suspension. A user detach keeps it.
98 CloseOnExit bool
99}
100
101// KeyboardConfig contains outer-terminal keyboard settings.
102type KeyboardConfig struct {
103 // KittyProtocol enables the kitty keyboard protocol on outer terminals
104 // that support it, which makes Ctrl+1..9 recent-session switching work.
105 KittyProtocol bool
106}
107
108// EchoPredictMode selects when a remote attachment shows predicted local echo.
109type EchoPredictMode uint8
110
111const (
112 // EchoPredictNever disables prediction. It is the zero value, so a
113 // client composed without the user's config (virtual terminals, UI
114 // drivers) never predicts.
115 EchoPredictNever EchoPredictMode = iota
116 // EchoPredictAdaptive shows predictions only on a slow or glitchy link.
117 EchoPredictAdaptive
118 // EchoPredictAlways shows predictions whatever the link latency.
119 EchoPredictAlways
120)
121
122// EchoConfig contains client-side predictive echo settings.
123type EchoConfig struct {
124 // Predict selects when remote attachments draw typed characters before
125 // the daemon echoes them.
126 Predict EchoPredictMode
127}
128
129// TerminalConfig contains client-side outer-terminal settings. It is read by
130// each client at startup and never applied by the daemon, so a change takes
131// effect on the next client process.
132type TerminalConfig struct {
133 // Colors is the forced color mode when ColorsSet is true. A false
134 // ColorsSet (terminal.colors = auto, the default) uses detection.
135 Colors terminalcap.ColorMode
136 ColorsSet bool
137}
138
139// ScrollbackConfig is vev's per-pane retention policy. The terminal library
140// only enforces these application-selected limits. Zero megabytes disables
141// history; zero lines removes the additional line ceiling.
142type ScrollbackConfig struct {
143 Megabytes uint64
144 Lines int
145}
146
147const DefaultScrollbackMegabytes uint64 = 50
148const DefaultScrollbackLines = 10_000
149const MaxScrollbackMegabytes uint64 = 4096
150const MaxScrollbackLines = 1_000_000
151
152func DefaultScrollbackConfig() ScrollbackConfig {
153 return ScrollbackConfig{Megabytes: DefaultScrollbackMegabytes, Lines: DefaultScrollbackLines}
154}
155
156func (c ScrollbackConfig) Valid() bool {
157 return c.Megabytes <= MaxScrollbackMegabytes && c.Lines >= 0 && c.Lines <= MaxScrollbackLines
158}
159
160// Config is the user-editable vev configuration after parsing. Unknown binding
161// keys are preserved here (in BindingEntries, in file order) so the usecase
162// layer can decide which actions it understands.
163type Config struct {
164 WebListen string
165 WebOrigin string
166 Theme ThemeMode
167 ThemePalette bool
168 ThemeAccent ThemeAccent
169 Bar BarConfig
170 BindingEntries []ConfigEntry
171 Codes map[string]string
172 Snapshot SnapshotConfig
173 Copy CopyConfig
174 Palette PaletteConfig
175 Floating FloatingConfig
176 Nav NavConfig
177 Tabs TabsConfig
178 Ephemeral EphemeralConfig
179 Keyboard KeyboardConfig
180 Echo EchoConfig
181 Terminal TerminalConfig
182 Scrollback ScrollbackConfig
183}
184
185// Warning describes a non-fatal config problem. Parsers and reloaders should
186// warn and continue with defaults rather than aborting startup.
187type Warning struct {
188 Line int
189 Msg string
190}
191
192// Defaults returns vev's default configuration.
193func Defaults() Config {
194 return Config{
195 Theme: ThemeAuto,
196 ThemePalette: true,
197 ThemeAccent: ThemeAccent{Mode: ThemeAccentAuto},
198 Bar: BarConfig{
199 Interval: 5 * time.Second,
200 },
201 BindingEntries: []ConfigEntry{},
202 Codes: map[string]string{},
203 Snapshot: SnapshotConfig{
204 RestoreProcesses: DefaultSnapshotRestoreProcesses(),
205 },
206 Copy: CopyConfig{
207 WordSeparators: DefaultWordSeparators,
208 },
209 Palette: PaletteConfig{
210 Anchor: AnchorCenter,
211 AnchorSet: true,
212 },
213 Floating: FloatingConfig{
214 Width: 80,
215 Height: 80,
216 },
217 Tabs: TabsConfig{
218 TerminalTitle: true,
219 },
220 Ephemeral: EphemeralConfig{
221 CloseOnExit: true,
222 },
223 Keyboard: KeyboardConfig{
224 KittyProtocol: true,
225 },
226 Echo: EchoConfig{
227 Predict: EchoPredictAdaptive,
228 },
229 Scrollback: DefaultScrollbackConfig(),
230 }
231}