diff --git a/gui/input.go b/gui/input.go index 0f994a7..ec75290 100644 --- a/gui/input.go +++ b/gui/input.go @@ -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): switch key { case glfw.KeyV: - // todo handle both these errors - _ = gui.terminal.Write([]byte(gui.window.GetClipboardString())) - + _ = gui.terminal.Paste([]byte(gui.window.GetClipboardString())) case glfw.KeySemicolon: gui.config.Slomo = !gui.config.Slomo } diff --git a/terminal/modes.go b/terminal/modes.go index 1b5dd09..1a95468 100644 --- a/terminal/modes.go +++ b/terminal/modes.go @@ -76,9 +76,7 @@ func csiSetMode(modeStr string, enabled bool, terminal *Terminal) error { terminal.UseMainBuffer() } case "?2004": - if enabled { - return fmt.Errorf("Bracketed paste mode is not yet supported") - } + terminal.SetBracketedPasteMode(enabled) default: return fmt.Errorf("Unsupported CSI %sl code", modeStr) } diff --git a/terminal/terminal.go b/terminal/terminal.go index c894196..6a42990 100644 --- a/terminal/terminal.go +++ b/terminal/terminal.go @@ -32,20 +32,21 @@ const ( ) type Terminal struct { - buffers []*buffer.Buffer - activeBufferIndex uint8 - lock sync.Mutex - pty *os.File - logger *zap.SugaredLogger - title string - size Winsize - config *config.Config - titleHandlers []chan bool - pauseChan chan bool - resumeChan chan bool - modes Modes - mouseMode MouseMode - isDirty bool + buffers []*buffer.Buffer + activeBufferIndex uint8 + lock sync.Mutex + pty *os.File + logger *zap.SugaredLogger + title string + size Winsize + config *config.Config + titleHandlers []chan bool + pauseChan chan bool + resumeChan chan bool + modes Modes + mouseMode MouseMode + bracketedPasteMode bool + isDirty bool } 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 { d := terminal.isDirty terminal.isDirty = false @@ -214,6 +219,15 @@ func (terminal *Terminal) Write(data []byte) error { 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 func (terminal *Terminal) Read() error {