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 right-anchor settings.
51type BarConfig struct {
52 TopRight string
53 BottomRight string
54 Interval time.Duration
55}
56
57// CopyConfig contains copy-mode selection and mouse motion settings.
58type CopyConfig struct {
59 WordSeparators string
60 ReduceMotion bool
61}
62
63// PaletteConfig contains palette placement settings. A false AnchorSet uses the
64// adaptive automatic placement.
65type PaletteConfig struct {
66 Anchor Anchor
67 AnchorSet bool
68}
69
70// FloatingConfig contains launch and sizing settings for per-tab floating panes.
71type FloatingConfig struct {
72 Command string
73 Width int
74 Height int
75}
76
77// NavConfig contains directional navigation overflow settings.
78type NavConfig struct {
79 OverflowTabs bool
80 OverflowSessions bool
81}
82
83// TabsConfig contains tab label display settings.
84type TabsConfig struct {
85 // TerminalTitle includes the focused pane's OSC terminal title in tab
86 // labels (top bar and session picker). The process name always shows.
87 TerminalTitle bool
88}
89
90// EphemeralConfig contains numbered-session lifetime settings.
91type EphemeralConfig struct {
92 // CloseOnExit removes an ephemeral session once its last attachment ends
93 // definitively: a closed client process (Detach{Closed}), or an expired
94 // park or suspension. A user detach keeps it.
95 CloseOnExit bool
96}
97
98// KeyboardConfig contains outer-terminal keyboard settings.
99type KeyboardConfig struct {
100 // KittyProtocol enables the kitty keyboard protocol on outer terminals
101 // that support it, which makes Ctrl+1..9 recent-session switching work.
102 KittyProtocol bool
103}
104
105// TerminalConfig contains client-side outer-terminal settings. It is read by
106// each client at startup and never applied by the daemon, so a change takes
107// effect on the next client process.
108type TerminalConfig struct {
109 // Colors is the forced color mode when ColorsSet is true. A false
110 // ColorsSet (terminal.colors = auto, the default) uses detection.
111 Colors terminalcap.ColorMode
112 ColorsSet bool
113}
114
115// ScrollbackConfig is vev's per-pane retention policy. The terminal library
116// only enforces these application-selected limits. Zero megabytes disables
117// history; zero lines removes the additional line ceiling.
118type ScrollbackConfig struct {
119 Megabytes uint64
120 Lines int
121}
122
123const DefaultScrollbackMegabytes uint64 = 50
124const DefaultScrollbackLines = 10_000
125const MaxScrollbackMegabytes uint64 = 4096
126const MaxScrollbackLines = 1_000_000
127
128func DefaultScrollbackConfig() ScrollbackConfig {
129 return ScrollbackConfig{Megabytes: DefaultScrollbackMegabytes, Lines: DefaultScrollbackLines}
130}
131
132func (c ScrollbackConfig) Valid() bool {
133 return c.Megabytes <= MaxScrollbackMegabytes && c.Lines >= 0 && c.Lines <= MaxScrollbackLines
134}
135
136// Config is the user-editable vev configuration after parsing. Unknown binding
137// keys are preserved here (in BindingEntries, in file order) so the usecase
138// layer can decide which actions it understands.
139type Config struct {
140 WebListen string
141 WebOrigin string
142 Theme ThemeMode
143 ThemePalette bool
144 ThemeAccent ThemeAccent
145 Bar BarConfig
146 BindingEntries []ConfigEntry
147 Codes map[string]string
148 Snapshot SnapshotConfig
149 Copy CopyConfig
150 Palette PaletteConfig
151 Floating FloatingConfig
152 Nav NavConfig
153 Tabs TabsConfig
154 Ephemeral EphemeralConfig
155 Keyboard KeyboardConfig
156 Terminal TerminalConfig
157 Scrollback ScrollbackConfig
158}
159
160// Warning describes a non-fatal config problem. Parsers and reloaders should
161// warn and continue with defaults rather than aborting startup.
162type Warning struct {
163 Line int
164 Msg string
165}
166
167// Defaults returns vev's default configuration.
168func Defaults() Config {
169 return Config{
170 Theme: ThemeAuto,
171 ThemePalette: true,
172 ThemeAccent: ThemeAccent{Mode: ThemeAccentAuto},
173 Bar: BarConfig{
174 Interval: 5 * time.Second,
175 },
176 BindingEntries: []ConfigEntry{},
177 Codes: map[string]string{},
178 Snapshot: SnapshotConfig{
179 RestoreProcesses: DefaultSnapshotRestoreProcesses(),
180 },
181 Copy: CopyConfig{
182 WordSeparators: DefaultWordSeparators,
183 },
184 Palette: PaletteConfig{
185 Anchor: AnchorCenter,
186 AnchorSet: true,
187 },
188 Floating: FloatingConfig{
189 Width: 80,
190 Height: 80,
191 },
192 Tabs: TabsConfig{
193 TerminalTitle: true,
194 },
195 Ephemeral: EphemeralConfig{
196 CloseOnExit: true,
197 },
198 Keyboard: KeyboardConfig{
199 KittyProtocol: true,
200 },
201 Scrollback: DefaultScrollbackConfig(),
202 }
203}