File: app_spec.go

package info (click to toggle)
elvish 0.21.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,372 kB
  • sloc: javascript: 236; sh: 130; python: 104; makefile: 88; xml: 9
file content (71 lines) | stat: -rw-r--r-- 2,076 bytes parent folder | download | duplicates (2)
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
package cli

import (
	"src.elv.sh/pkg/cli/tk"
	"src.elv.sh/pkg/ui"
)

// AppSpec specifies the configuration and initial state for an App.
type AppSpec struct {
	TTY               TTY
	MaxHeight         func() int
	RPromptPersistent func() bool
	BeforeReadline    []func()
	AfterReadline     []func(string)

	Highlighter Highlighter
	Prompt      Prompt
	RPrompt     Prompt

	GlobalBindings   tk.Bindings
	CodeAreaBindings tk.Bindings
	QuotePaste       func() bool

	SimpleAbbreviations    func(f func(abbr, full string))
	CommandAbbreviations   func(f func(abbr, full string))
	SmallWordAbbreviations func(f func(abbr, full string))

	CodeAreaState tk.CodeAreaState
	State         State
}

// Highlighter represents a code highlighter whose result can be delivered
// asynchronously.
type Highlighter interface {
	// Get returns the highlighted code and any tips.
	Get(code string) (ui.Text, []ui.Text)
	// LateUpdates returns a channel for delivering late updates.
	LateUpdates() <-chan struct{}
}

// A Highlighter implementation that always returns plain text.
type dummyHighlighter struct{}

func (dummyHighlighter) Get(code string) (ui.Text, []ui.Text) {
	return ui.T(code), nil
}

func (dummyHighlighter) LateUpdates() <-chan struct{} { return nil }

// Prompt represents a prompt whose result can be delivered asynchronously.
type Prompt interface {
	// Trigger requests a re-computation of the prompt. The force flag is set
	// when triggered for the first time during a ReadCode session or after a
	// SIGINT that resets the editor.
	Trigger(force bool)
	// Get returns the current prompt.
	Get() ui.Text
	// LastUpdates returns a channel for notifying late updates.
	LateUpdates() <-chan struct{}
}

// NewConstPrompt returns a Prompt that always shows the given text.
func NewConstPrompt(t ui.Text) Prompt {
	return constPrompt{t}
}

type constPrompt struct{ Content ui.Text }

func (constPrompt) Trigger(force bool)           {}
func (p constPrompt) Get() ui.Text               { return p.Content }
func (constPrompt) LateUpdates() <-chan struct{} { return nil }