Skip to content

Commit

Permalink
Merge pull request #21 from liamg/liamg-fix-rendering-osx
Browse files Browse the repository at this point in the history
Fix rendering on osx and intellij
  • Loading branch information
liamg authored Aug 19, 2020
2 parents 041be8b + 2af5cf5 commit 69d28b9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
22 changes: 18 additions & 4 deletions pkg/proxy/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func (p *Proxy) handleCSI(pty chan byte) (output []byte, original []byte, redraw
'l': p.csiResetModeHandler,
'J': p.csiEraseInDisplayHandler,
'r': p.csiSetMarginHandler,
's': p.csiSavePositionHandler,
'u': p.csiRestorePositionHandler,
}

var final byte
Expand Down Expand Up @@ -140,8 +142,8 @@ func (p *Proxy) csiLinePositionAbsolute(params []string, intermediate string) (o
// CSI Pt Pb r
func (p *Proxy) csiSetMarginHandler(params []string, intermediate string) (output []byte, redraw bool, err error) {
// pass through command, and inject reset position afterwards
row, col := p.HandleCoordinates(0, 0)
return []byte(fmt.Sprintf("\033[%d;%dH", row+1, col+1)), true, ErrorCommandNotSupported
row, col := p.HandleCoordinates(1, 1)
return []byte(fmt.Sprintf("\033[%d;%dH", row, col)), true, ErrorCommandNotSupported
}

// CSI Ps J
Expand All @@ -158,8 +160,8 @@ func (p *Proxy) csiEraseInDisplayHandler(params []string, intermediate string) (

switch n {
case "2", "3":
row, col := p.HandleCoordinates(0, 0)
return []byte(fmt.Sprintf("\033[%d;%dH", row+1, col+1)), true, ErrorCommandNotSupported
row, col := p.HandleCoordinates(1, 1)
return []byte(fmt.Sprintf("\033[%d;%dH", row, col)), true, ErrorCommandNotSupported
}

return nil, false, ErrorCommandNotSupported
Expand Down Expand Up @@ -213,3 +215,15 @@ func (p *Proxy) csiSetMode(modeStr string, enabled bool) (output []byte, redraw

return nil, redraw, ErrorCommandNotSupported
}

// CSI Ps s
func (p *Proxy) csiSavePositionHandler(params []string, intermediate string) (output []byte, redraw bool, err error) {
p.pauseDrawing = true
return nil, false, ErrorCommandNotSupported
}

// CSI Ps u
func (p *Proxy) csiRestorePositionHandler(params []string, intermediate string) (output []byte, redraw bool, err error) {
p.pauseDrawing = false
return nil, false, ErrorCommandNotSupported
}
7 changes: 4 additions & 3 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Proxy struct {
realCols uint16
canRender bool
redrawChan chan struct{}
pauseDrawing bool
}

// NewProxy creates a new proxy instance
Expand Down Expand Up @@ -220,19 +221,19 @@ func (p *Proxy) requestRedraw() {
func (p *Proxy) redraw() {
p.decMutex.Lock()
defer p.decMutex.Unlock()
if !p.canRender {
if !p.canRender || p.pauseDrawing {
return
}
//save cursor pos
p.writeOutput([]byte("\x1b[s"))
p.writeOutput([]byte("\x1b7"))
for _, decorator := range p.decorators {
if !decorator.IsVisible() {
continue
}
decorator.Draw(p.realRows, p.realCols, p.writeOutput)
}
// restore cursor position
p.writeOutput([]byte(fmt.Sprintf("\x1b[u")))
p.writeOutput([]byte(fmt.Sprintf("\x1b8")))
}

func (p *Proxy) writeOutput(data []byte) {
Expand Down

0 comments on commit 69d28b9

Please sign in to comment.