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):
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
}

View File

@ -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)
}

View File

@ -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 {