mirror of
https://github.com/jroimartin/gocui.git
synced 2025-05-01 22:17:55 +08:00
small changes
This commit is contained in:
parent
24baf341da
commit
e4eee64f4d
16
gui.go
16
gui.go
@ -75,8 +75,6 @@ type GuiMutexes struct {
|
|||||||
tickingMutex sync.Mutex
|
tickingMutex sync.Mutex
|
||||||
|
|
||||||
ViewsMutex sync.Mutex
|
ViewsMutex sync.Mutex
|
||||||
|
|
||||||
drawMutex sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type PlayMode int
|
type PlayMode int
|
||||||
@ -936,8 +934,6 @@ func (g *Gui) drawListFooter(v *View, fgColor, bgColor Attribute) error {
|
|||||||
|
|
||||||
// flush updates the gui, re-drawing frames and buffers.
|
// flush updates the gui, re-drawing frames and buffers.
|
||||||
func (g *Gui) flush() error {
|
func (g *Gui) flush() error {
|
||||||
g.Mutexes.drawMutex.Lock()
|
|
||||||
defer g.Mutexes.drawMutex.Unlock()
|
|
||||||
|
|
||||||
// pretty sure we don't need this, but keeping it here in case we get weird visual artifacts
|
// pretty sure we don't need this, but keeping it here in case we get weird visual artifacts
|
||||||
// g.clear(g.FgColor, g.BgColor)
|
// g.clear(g.FgColor, g.BgColor)
|
||||||
@ -966,18 +962,6 @@ func (g *Gui) flush() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Gui) Draw(v *View) error {
|
|
||||||
g.Mutexes.drawMutex.Lock()
|
|
||||||
defer g.Mutexes.drawMutex.Unlock()
|
|
||||||
|
|
||||||
if err := g.draw(v); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
Screen.Show()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// draw manages the cursor and calls the draw function of a view.
|
// draw manages the cursor and calls the draw function of a view.
|
||||||
func (g *Gui) draw(v *View) error {
|
func (g *Gui) draw(v *View) error {
|
||||||
if g.suspended {
|
if g.suspended {
|
||||||
|
36
view.go
36
view.go
@ -879,11 +879,18 @@ func (v *View) draw() error {
|
|||||||
if v.Autoscroll && visibleViewLinesHeight > maxY {
|
if v.Autoscroll && visibleViewLinesHeight > maxY {
|
||||||
v.oy = visibleViewLinesHeight - maxY
|
v.oy = visibleViewLinesHeight - maxY
|
||||||
}
|
}
|
||||||
y := 0
|
|
||||||
for i, vline := range v.viewLines {
|
if len(v.viewLines) == 0 {
|
||||||
if i < v.oy {
|
return nil
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
start := v.oy
|
||||||
|
if start > len(v.viewLines)-1 {
|
||||||
|
start = len(v.viewLines) - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
y := 0
|
||||||
|
for _, vline := range v.viewLines[start:] {
|
||||||
if y >= maxY {
|
if y >= maxY {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -1112,14 +1119,6 @@ func (v *View) SetHighlight(y int, on bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func lineWidth(line []cell) (n int) {
|
|
||||||
for i := range line {
|
|
||||||
n += runewidth.RuneWidth(line[i].chr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func lineWrap(line []cell, columns int) [][]cell {
|
func lineWrap(line []cell, columns int) [][]cell {
|
||||||
if columns == 0 {
|
if columns == 0 {
|
||||||
return [][]cell{line}
|
return [][]cell{line}
|
||||||
@ -1227,3 +1226,16 @@ func (v *View) ClearTextArea() {
|
|||||||
_ = v.SetOrigin(0, 0)
|
_ = v.SetOrigin(0, 0)
|
||||||
_ = v.SetCursor(0, 0)
|
_ = v.SetCursor(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only call this function if you don't care where v.wx and v.wy end up
|
||||||
|
func (v *View) OverwriteLines(y int, content string) {
|
||||||
|
v.writeMutex.Lock()
|
||||||
|
defer v.writeMutex.Unlock()
|
||||||
|
|
||||||
|
// break by newline, then for each line, write it, then add that erase command
|
||||||
|
v.wx = 0
|
||||||
|
v.wy = y
|
||||||
|
|
||||||
|
lines := strings.Replace(content, "\n", "\x1b[K\n", -1)
|
||||||
|
v.writeString(lines)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user