github.com/kolbycrouch/elvish@v0.14.1-0.20210614162631-215b9ac1c423/pkg/cli/mode/stub.go (about) 1 package mode 2 3 import ( 4 "src.elv.sh/pkg/cli/term" 5 "src.elv.sh/pkg/cli/tk" 6 ) 7 8 // Stub is a mode that just shows a modeline and keeps the focus on the code 9 // area. It is mainly useful to apply some special non-default bindings. 10 type Stub interface { 11 tk.Widget 12 } 13 14 // StubSpec specifies the configuration for the stub mode. 15 type StubSpec struct { 16 // Key bindings. 17 Bindings tk.Bindings 18 // Name to show in the modeline. 19 Name string 20 } 21 22 type stub struct { 23 StubSpec 24 } 25 26 func (w stub) Render(width, height int) *term.Buffer { 27 buf := term.NewBufferBuilder(width). 28 WriteStyled(modeLine(w.Name, false)).SetDotHere().Buffer() 29 buf.TrimToLines(0, height) 30 return buf 31 } 32 33 func (w stub) Handle(event term.Event) bool { 34 return w.Bindings.Handle(w, event) 35 } 36 37 func (w stub) Focus() bool { 38 return false 39 } 40 41 // NewStub creates a new Stub mode. 42 func NewStub(cfg StubSpec) Stub { 43 if cfg.Bindings == nil { 44 cfg.Bindings = tk.DummyBindings{} 45 } 46 return stub{cfg} 47 }