~ghost08/tcell-term

63304a52333b9c6a932c9115a2b78a004637d86c — Tim Culverhouse 1 year, 2 months ago 210932f
view: remove unused screen calls and prevent panics

Prevent panics when calling references to view when it is nil.

Also, remove logging in csi handler

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2 files changed, 15 insertions(+), 5 deletions(-)

M terminal.go
M termutil/csi.go
M terminal.go => terminal.go +13 -2
@@ 20,8 20,7 @@ type Terminal struct {
	curStyle tcell.CursorStyle
	curVis   bool

	screen tcell.Screen
	view   views.View
	view views.View

	close bool



@@ 77,11 76,16 @@ func (t *Terminal) Close() {
	t.term.Pty().Close()
}

// SetView sets the view for the terminal to draw to. This must be set before
// calling Draw
func (t *Terminal) SetView(view views.View) {
	t.view = view
}

func (t *Terminal) Size() (int, int) {
	if t.view == nil {
		return 0, 0
	}
	return t.view.Size()
}



@@ 104,6 108,9 @@ func (t *Terminal) HandleEvent(e tcell.Event) bool {
}

func (t *Terminal) Draw() {
	if t.view == nil {
		return
	}
	buf := t.term.GetActiveBuffer()
	w, h := t.view.Size()
	for viewY := 0; viewY < h; viewY++ {


@@ 148,7 155,11 @@ func convertColor(c color.Color, defaultColor tcell.Color) tcell.Color {
	return tcell.NewRGBColor(int32(r), int32(g), int32(b))
}

// Resize resizes the terminal to the dimensions of the terminals view
func (t *Terminal) Resize() {
	if t.view == nil {
		return
	}
	w, h := t.view.Size()
	t.term.SetSize(uint16(h), uint16(w))
}

M termutil/csi.go => termutil/csi.go +2 -3
@@ 2,7 2,6 @@ package termutil

import (
	"fmt"
	"log"
	"strconv"
	"strings"



@@ 128,7 127,7 @@ func (t *Terminal) handleCSI(readChan chan MeasuredRune) (renderRequired bool) {
	// if this is an unknown CSI sequence, write it to stdout as we can't handle it?
	//_ = t.writeToRealStdOut(append([]rune{0x1b, '['}, raw...)...)
	_ = raw
	log.Printf("UNKNOWN CSI P(%s) I(%s) %c", strings.Join(params, ";"), string(intermediate), final)
	// log.Printf("UNKNOWN CSI P(%s) I(%s) %c", strings.Join(params, ";"), string(intermediate), final)
	return false
}



@@ 788,7 787,7 @@ func (t *Terminal) csiSetMode(modes string, enabled bool) bool {
		case "?80":
			// t.activeBuffer.modes.SixelScrolling = enabled
		default:
			log.Printf("Unsupported CSI mode %s = %t", modeStr, enabled)
			// log.Printf("Unsupported CSI mode %s = %t", modeStr, enabled)
		}
	}
	return false