add bracketed paste mode support

This commit is contained in:
Liam Galvin 2018-10-23 15:10:58 +01:00
parent 5c9b78bd44
commit 88b26ce91a
3 changed files with 30 additions and 20 deletions

View File

@ -27,9 +27,7 @@ func (gui *GUI) key(w *glfw.Window, key glfw.Key, scancode int, action glfw.Acti
case modsPressed(mods, glfw.ModControl, glfw.ModShift): case modsPressed(mods, glfw.ModControl, glfw.ModShift):
switch key { switch key {
case glfw.KeyV: case glfw.KeyV:
// todo handle both these errors _ = gui.terminal.Paste([]byte(gui.window.GetClipboardString()))
_ = gui.terminal.Write([]byte(gui.window.GetClipboardString()))
case glfw.KeySemicolon: case glfw.KeySemicolon:
gui.config.Slomo = !gui.config.Slomo gui.config.Slomo = !gui.config.Slomo
} }

View File

@ -76,9 +76,7 @@ func csiSetMode(modeStr string, enabled bool, terminal *Terminal) error {
terminal.UseMainBuffer() terminal.UseMainBuffer()
} }
case "?2004": case "?2004":
if enabled { terminal.SetBracketedPasteMode(enabled)
return fmt.Errorf("Bracketed paste mode is not yet supported")
}
default: default:
return fmt.Errorf("Unsupported CSI %sl code", modeStr) return fmt.Errorf("Unsupported CSI %sl code", modeStr)
} }

View File

@ -32,20 +32,21 @@ const (
) )
type Terminal struct { type Terminal struct {
buffers []*buffer.Buffer buffers []*buffer.Buffer
activeBufferIndex uint8 activeBufferIndex uint8
lock sync.Mutex lock sync.Mutex
pty *os.File pty *os.File
logger *zap.SugaredLogger logger *zap.SugaredLogger
title string title string
size Winsize size Winsize
config *config.Config config *config.Config
titleHandlers []chan bool titleHandlers []chan bool
pauseChan chan bool pauseChan chan bool
resumeChan chan bool resumeChan chan bool
modes Modes modes Modes
mouseMode MouseMode mouseMode MouseMode
isDirty bool bracketedPasteMode bool
isDirty bool
} }
type Modes struct { type Modes struct {
@ -92,6 +93,10 @@ func New(pty *os.File, logger *zap.SugaredLogger, config *config.Config) *Termin
} }
func (terminal *Terminal) SetBracketedPasteMode(enabled bool) {
terminal.bracketedPasteMode = enabled
}
func (terminal *Terminal) CheckDirty() bool { func (terminal *Terminal) CheckDirty() bool {
d := terminal.isDirty d := terminal.isDirty
terminal.isDirty = false terminal.isDirty = false
@ -214,6 +219,15 @@ func (terminal *Terminal) Write(data []byte) error {
return err return err
} }
func (terminal *Terminal) Paste(data []byte) error {
if terminal.bracketedPasteMode {
data = []byte(fmt.Sprintf("\x1b[200~%s\x1b[201~", string(data)))
}
_, err := terminal.pty.Write(data)
return err
}
// Read needs to be run on a goroutine, as it continually reads output to set on the terminal // Read needs to be run on a goroutine, as it continually reads output to set on the terminal
func (terminal *Terminal) Read() error { func (terminal *Terminal) Read() error {