Skip to content

Commit 69d28b9

Browse files
authored
Merge pull request #21 from liamg/liamg-fix-rendering-osx
Fix rendering on osx and intellij
2 parents 041be8b + 2af5cf5 commit 69d28b9

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

pkg/proxy/csi.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ func (p *Proxy) handleCSI(pty chan byte) (output []byte, original []byte, redraw
2020
'l': p.csiResetModeHandler,
2121
'J': p.csiEraseInDisplayHandler,
2222
'r': p.csiSetMarginHandler,
23+
's': p.csiSavePositionHandler,
24+
'u': p.csiRestorePositionHandler,
2325
}
2426

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

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

159161
switch n {
160162
case "2", "3":
161-
row, col := p.HandleCoordinates(0, 0)
162-
return []byte(fmt.Sprintf("\033[%d;%dH", row+1, col+1)), true, ErrorCommandNotSupported
163+
row, col := p.HandleCoordinates(1, 1)
164+
return []byte(fmt.Sprintf("\033[%d;%dH", row, col)), true, ErrorCommandNotSupported
163165
}
164166

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

214216
return nil, redraw, ErrorCommandNotSupported
215217
}
218+
219+
// CSI Ps s
220+
func (p *Proxy) csiSavePositionHandler(params []string, intermediate string) (output []byte, redraw bool, err error) {
221+
p.pauseDrawing = true
222+
return nil, false, ErrorCommandNotSupported
223+
}
224+
225+
// CSI Ps u
226+
func (p *Proxy) csiRestorePositionHandler(params []string, intermediate string) (output []byte, redraw bool, err error) {
227+
p.pauseDrawing = false
228+
return nil, false, ErrorCommandNotSupported
229+
}

pkg/proxy/proxy.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Proxy struct {
2727
realCols uint16
2828
canRender bool
2929
redrawChan chan struct{}
30+
pauseDrawing bool
3031
}
3132

3233
// NewProxy creates a new proxy instance
@@ -220,19 +221,19 @@ func (p *Proxy) requestRedraw() {
220221
func (p *Proxy) redraw() {
221222
p.decMutex.Lock()
222223
defer p.decMutex.Unlock()
223-
if !p.canRender {
224+
if !p.canRender || p.pauseDrawing {
224225
return
225226
}
226227
//save cursor pos
227-
p.writeOutput([]byte("\x1b[s"))
228+
p.writeOutput([]byte("\x1b7"))
228229
for _, decorator := range p.decorators {
229230
if !decorator.IsVisible() {
230231
continue
231232
}
232233
decorator.Draw(p.realRows, p.realCols, p.writeOutput)
233234
}
234235
// restore cursor position
235-
p.writeOutput([]byte(fmt.Sprintf("\x1b[u")))
236+
p.writeOutput([]byte(fmt.Sprintf("\x1b8")))
236237
}
237238

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

0 commit comments

Comments
 (0)