github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/cmds/elvish/edit/eddefs/editor.go (about) 1 package eddefs 2 3 import ( 4 "github.com/u-root/u-root/cmds/elvish/edit/ui" 5 "github.com/u-root/u-root/cmds/elvish/eval" 6 "github.com/u-root/u-root/cmds/elvish/parse" 7 ) 8 9 // Editor is the interface for the Elvish line editor. 10 type Editor interface { 11 // ReadLine reads a line interactively. 12 ReadLine() (string, error) 13 // Close releases resources used by the editor. 14 Close() 15 16 // Evaler returns the Evaler associated with the Editor. 17 Evaler() *eval.Evaler 18 19 // Buffer returns the current content and dot position of the buffer. 20 Buffer() (string, int) 21 // SetBuffer sets the current content and dot position of the buffer. 22 SetBuffer(buffer string, dot int) 23 // ParsedBuffer returns the node from parsing the buffer. 24 ParsedBuffer() *parse.Chunk 25 // InsertAtDot inserts text at the dot and moves the dot after it. 26 InsertAtDot(text string) 27 28 // SetPrompt sets the prompt of the editor. 29 SetPrompt(prompt Prompt) 30 // SetPrompt sets the rprompt of the editor. 31 SetRPrompt(rprompt Prompt) 32 33 // SetMode sets the current mode of the Editor. 34 SetMode(m Mode) 35 // SetModeInsert sets the current mode of the Editor to insert mode. 36 SetModeInsert() 37 // SetModeListing sets the current mode of the Editor to listing mode with 38 // the supplied binding and provider. 39 SetModeListing(b BindingMap, p ListingProvider) 40 // RefreshListing refreshes the listing mode, recalculating the listing 41 // items. It is useful when the underlying listing provider has been 42 // changed. If the editor is not in listing mode, it does nothing. 43 RefreshListing() 44 45 // AddTip adds a message to the tip area. 46 AddTip(format string, args ...interface{}) 47 // Notify writes out a message in a way that does not interrupt the editor 48 // display. When the editor is not active, it simply writes the message to 49 // the terminal. When the editor is active, it appends the message to the 50 // notification queue, which will be written out during the update cycle. It 51 // can be safely used concurrently. 52 Notify(format string, args ...interface{}) 53 54 // LastKey returns the last key received from the user. It is useful mainly 55 // in keybindings. 56 LastKey() ui.Key 57 58 // SetAction sets the action to execute after the key binding has finished. 59 SetAction(a Action) 60 61 // AddAfterReadline adds a hook function that runs after readline ends. 62 AddAfterReadline(func(string)) 63 }