src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/cli/app_spec.go (about) 1 package cli 2 3 import ( 4 "src.elv.sh/pkg/cli/tk" 5 "src.elv.sh/pkg/ui" 6 ) 7 8 // AppSpec specifies the configuration and initial state for an App. 9 type AppSpec struct { 10 TTY TTY 11 MaxHeight func() int 12 RPromptPersistent func() bool 13 BeforeReadline []func() 14 AfterReadline []func(string) 15 16 Highlighter Highlighter 17 Prompt Prompt 18 RPrompt Prompt 19 20 GlobalBindings tk.Bindings 21 CodeAreaBindings tk.Bindings 22 QuotePaste func() bool 23 24 SimpleAbbreviations func(f func(abbr, full string)) 25 CommandAbbreviations func(f func(abbr, full string)) 26 SmallWordAbbreviations func(f func(abbr, full string)) 27 28 CodeAreaState tk.CodeAreaState 29 State State 30 } 31 32 // Highlighter represents a code highlighter whose result can be delivered 33 // asynchronously. 34 type Highlighter interface { 35 // Get returns the highlighted code and any tips. 36 Get(code string) (ui.Text, []ui.Text) 37 // LateUpdates returns a channel for delivering late updates. 38 LateUpdates() <-chan struct{} 39 } 40 41 // A Highlighter implementation that always returns plain text. 42 type dummyHighlighter struct{} 43 44 func (dummyHighlighter) Get(code string) (ui.Text, []ui.Text) { 45 return ui.T(code), nil 46 } 47 48 func (dummyHighlighter) LateUpdates() <-chan struct{} { return nil } 49 50 // Prompt represents a prompt whose result can be delivered asynchronously. 51 type Prompt interface { 52 // Trigger requests a re-computation of the prompt. The force flag is set 53 // when triggered for the first time during a ReadCode session or after a 54 // SIGINT that resets the editor. 55 Trigger(force bool) 56 // Get returns the current prompt. 57 Get() ui.Text 58 // LastUpdates returns a channel for notifying late updates. 59 LateUpdates() <-chan struct{} 60 } 61 62 // NewConstPrompt returns a Prompt that always shows the given text. 63 func NewConstPrompt(t ui.Text) Prompt { 64 return constPrompt{t} 65 } 66 67 type constPrompt struct{ Content ui.Text } 68 69 func (constPrompt) Trigger(force bool) {} 70 func (p constPrompt) Get() ui.Text { return p.Content } 71 func (constPrompt) LateUpdates() <-chan struct{} { return nil }