Skip to content

style disappears #509

@slukits

Description

@slukits

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.

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()
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions