You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following simplified example I try to draw a colored frame at the edges of the screen area.
Clearing the screen and drawing the frame before entering the event-loop as the tutorial suggests creates the frame (the characters are displayed) but the top line and the first cell in the second line loos their style. Moving the clearing and frame drawing inside the resize event shows initially the expected behavior. But if I resize the terminal-window (gnome-terminal, vim-terminal) by making the window smaller the problem seems to reoccur for every second line the window gets smaller. Making the window larger shows always the expected behavior.
package main
import (
"log"
"os"
"github.com/gdamore/tcell/v2"
)
func main() {
defStyle := tcell.StyleDefault.Background(
tcell.ColorBlack).Foreground(tcell.ColorWhite)
frmStyle := tcell.StyleDefault.Background(
tcell.ColorWhite).Foreground(tcell.ColorBlack)
scr, err := tcell.NewScreen()
if err != nil {
log.Fatalf("%+v", err)
}
if err := scr.Init(); err != nil {
log.Fatalf("%+v", err)
}
scr.SetStyle(defStyle)
quit := func() {
scr.Fini()
os.Exit(0)
}
frame := func() {
w, h := scr.Size()
for x, y := 0, 0; x < w; x++ {
scr.SetContent(x, y, 't', nil, frmStyle)
}
for x, y := 0, h-1; x < w; x++ {
scr.SetContent(x, y, 'b', nil, frmStyle)
}
for x, y := 0, 1; y < h-1; y++ {
scr.SetContent(x, y, 'l', nil, frmStyle)
}
for x, y := w-1, 1; y < h-1; y++ {
scr.SetContent(x, y, 'r', nil, frmStyle)
}
}
// BUG the first line and the first cell of the second line loose
// their style; comment the following clearing and frame drawing out
// and uncomment it in the resize event to see the expected behavior
scr.Clear()
frame()
for {
// Update screen
scr.Show()
// Poll event
ev := scr.PollEvent()
// Process event
switch ev.(type) {
case *tcell.EventResize:
// BUG uncomment the following clearing and frame drawing
// while the above clearing and frame drawing is comment out,
// to see the expected initial behavior. But resizing the
// terminal window by making it smaller still shows this problem.
// scr.Clear()
// frame()
scr.Sync()
case *tcell.EventKey:
quit()
}
}
}
The text was updated successfully, but these errors were encountered:
So this does appear to be a subtle bug, but I'm still trying to figure it out.
A simple workaround exists however:
In your event handler, do the following:
scr.Clear()
scr.Sync()
scr.frame()
Something weird happens if you swap the scr.Sync() and scr.Clear() -- the colors of the frame are lost and it goes to the default.
scr.Clear() resets the backing colors, but those should be changed by the call to frame() above. Something doesn't make sense to me. I think it's probably the automargin code that is messing things up.
Thank you for your Work!
In the following simplified example I try to draw a colored frame at the edges of the screen area.
Clearing the screen and drawing the frame before entering the event-loop as the tutorial suggests creates the frame (the characters are displayed) but the top line and the first cell in the second line loos their style. Moving the clearing and frame drawing inside the resize event shows initially the expected behavior. But if I resize the terminal-window (gnome-terminal, vim-terminal) by making the window smaller the problem seems to reoccur for every second line the window gets smaller. Making the window larger shows always the expected behavior.
The text was updated successfully, but these errors were encountered: