mirror of
https://github.com/gdamore/tcell.git
synced 2025-04-29 13:49:10 +08:00
An attempt to speed up tcell screen rendering. (#247)
This commit is contained in:
parent
48f88019c3
commit
ec71b09872
32
tscreen.go
32
tscreen.go
@ -74,6 +74,8 @@ type tScreen struct {
|
|||||||
cells CellBuffer
|
cells CellBuffer
|
||||||
in *os.File
|
in *os.File
|
||||||
out *os.File
|
out *os.File
|
||||||
|
buffering bool // true if we are collecting writes to buf instead of sending directly to out
|
||||||
|
buf bytes.Buffer
|
||||||
curstyle Style
|
curstyle Style
|
||||||
style Style
|
style Style
|
||||||
evch chan Event
|
evch chan Event
|
||||||
@ -614,7 +616,7 @@ func (t *tScreen) drawCell(x, y int) int {
|
|||||||
width = 1
|
width = 1
|
||||||
str = " "
|
str = " "
|
||||||
}
|
}
|
||||||
io.WriteString(t.out, str)
|
t.writeString(str)
|
||||||
t.cx += width
|
t.cx += width
|
||||||
t.cells.SetDirty(x, y, false)
|
t.cells.SetDirty(x, y, false)
|
||||||
if width > 1 {
|
if width > 1 {
|
||||||
@ -649,8 +651,26 @@ func (t *tScreen) showCursor() {
|
|||||||
t.cy = y
|
t.cy = y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// writeString sends a string to the terminal. The string is sent as-is and
|
||||||
|
// this function does not expand inline padding indications (of the form
|
||||||
|
// $<[delay]> where [delay] is msec). In order to have these expanded, use
|
||||||
|
// TPuts. If the screen is "buffering", the string is collected in a buffer,
|
||||||
|
// with the intention that the entire buffer be sent to the terminal in one
|
||||||
|
// write operation at some point later.
|
||||||
|
func (t *tScreen) writeString(s string) {
|
||||||
|
if t.buffering {
|
||||||
|
io.WriteString(&t.buf, s)
|
||||||
|
} else {
|
||||||
|
io.WriteString(t.out, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (t *tScreen) TPuts(s string) {
|
func (t *tScreen) TPuts(s string) {
|
||||||
t.ti.TPuts(t.out, s, t.baud)
|
if t.buffering {
|
||||||
|
t.ti.TPuts(&t.buf, s, t.baud)
|
||||||
|
} else {
|
||||||
|
t.ti.TPuts(t.out, s, t.baud)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tScreen) Show() {
|
func (t *tScreen) Show() {
|
||||||
@ -686,6 +706,12 @@ func (t *tScreen) draw() {
|
|||||||
t.cx = -1
|
t.cx = -1
|
||||||
t.cy = -1
|
t.cy = -1
|
||||||
|
|
||||||
|
t.buf.Reset()
|
||||||
|
t.buffering = true
|
||||||
|
defer func() {
|
||||||
|
t.buffering = false
|
||||||
|
}()
|
||||||
|
|
||||||
// hide the cursor while we move stuff around
|
// hide the cursor while we move stuff around
|
||||||
t.hideCursor()
|
t.hideCursor()
|
||||||
|
|
||||||
@ -710,6 +736,8 @@ func (t *tScreen) draw() {
|
|||||||
|
|
||||||
// restore the cursor
|
// restore the cursor
|
||||||
t.showCursor()
|
t.showCursor()
|
||||||
|
|
||||||
|
t.buf.WriteTo(t.out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tScreen) EnableMouse() {
|
func (t *tScreen) EnableMouse() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user