More work on shell

This commit is contained in:
Kovid Goyal
2022-10-07 10:42:26 +05:30
parent fd36435262
commit 9f2b2eac85
5 changed files with 134 additions and 29 deletions

View File

@@ -42,6 +42,8 @@ const (
ActionMoveToEndOfDocument
ActionCursorLeft
ActionCursorRight
ActionEndInput
ActionAcceptInput
)
type Readline struct {
@@ -78,12 +80,32 @@ func New(loop *loop.Loop, r RlInit) *Readline {
return ans
}
func (self *Readline) ChangeLoopAndResetText(lp *loop.Loop) {
self.loop = lp
self.lines = []string{""}
self.cursor = Position{}
self.cursor_y = 0
}
func (self *Readline) Start() {
self.loop.SetCursorShape(loop.BAR_CURSOR, true)
self.loop.StartBracketedPaste()
self.Redraw()
}
func (self *Readline) End() {
self.loop.SetCursorShape(loop.BLOCK_CURSOR, true)
self.loop.EndBracketedPaste()
self.loop.QueueWriteString("\r\n")
if self.mark_prompts {
self.loop.QueueWriteString(PROMPT_MARK + "C" + ST)
}
}
func MarkOutputStart() string {
return PROMPT_MARK + "C" + ST
}
func (self *Readline) Redraw() {
self.loop.StartAtomicUpdate()
self.RedrawNonAtomic()
@@ -94,15 +116,6 @@ func (self *Readline) RedrawNonAtomic() {
self.redraw()
}
func (self *Readline) End() {
self.loop.EndBracketedPaste()
self.loop.QueueWriteString("\r\n")
self.loop.SetCursorShape(loop.BLOCK_CURSOR, true)
if self.mark_prompts {
self.loop.QueueWriteString(PROMPT_MARK + "C" + ST)
}
}
func (self *Readline) OnKeyEvent(event *loop.KeyEvent) error {
err := self.handle_key_event(event)
if err == ErrCouldNotPerformAction {
@@ -117,6 +130,14 @@ func (self *Readline) OnText(text string, from_key_event bool, in_bracketed_past
return nil
}
func (self *Readline) PerformAction(ac Action, repeat_count uint) bool {
return self.perform_action(ac, repeat_count)
func (self *Readline) TextBeforeCursor() string {
return self.text_upto_cursor_pos()
}
func (self *Readline) TextAfterCursor() string {
return self.text_after_cursor_pos()
}
func (self *Readline) AllText() string {
return self.all_text()
}