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