gizak / gizak/termui

Why is my rendering messy?

Open
#269 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
13.6k
Forks
819
PR merge metrics
No merged PRs in 30d

Description

this is my code.
```go
func main() {
var path string
flag.StringVar(&path, "p", "D:\\test", "路径,默认为当前路径")
flag.Parse()

if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
defer ui.Close()

//
p := widgets.NewParagraph()
p.Title = "Atom Parsing"
p.Text = " starting..."
p.SetRect(0, 0, 50, 3)
p.TextStyle.Fg = ui.ColorWhite
p.BorderStyle.Fg = ui.ColorGreen
p.TitleStyle.Fg = ui.ColorGreen

//
g1 := widgets.NewGauge()
g1.Title = "进度"
g1.Percent = 0
g1.SetRect(50, 0, 100, 3)
g1.BarColor = ui.ColorGreen
g1.LabelStyle = ui.NewStyle(ui.ColorYellow)
g1.TitleStyle.Fg = ui.ColorMagenta
g1.BorderStyle.Fg = ui.ColorYellow

//
l := widgets.NewList()
listData := make([]string, 0, 10)
l.Title = "Error"
l.TitleStyle.Fg = ui.ColorRed
l.Rows = listData
l.SetRect(0, 4, 100, 10)
l.TextStyle.Fg = ui.ColorBlue
l.BorderStyle.Fg = ui.ColorWhite

draw := func() {
ui.Render(p, g1, l)
}
draw()

time.Sleep(1 * time.Second)
//
go func() {
for {
select {
case d := <-terminal.GaugeChan:
g1.Percent = d
case text := <-terminal.TitleChan:
p.Text = text
case s, ok := <-terminal.ProblemChan:
if ok {
listData = append(listData, fmt.Sprintf(" [%d] %s", len(listData), s))
l.Rows = listData
}
}
}
}()

//
go func() {
err1 := parsing.XmlParsing(path)
if err1 != nil {
log.Fatal(err1)
}
}()

uiEvents := ui.PollEvents()
ticker := time.NewTicker(100 * time.Millisecond).C
for {
select {
case e := <-uiEvents:
switch e.ID {
case "q", "":
return
}
case <-ticker:
draw()
}
}
}
```
![1F41BF99-5176-4BDB-8921-887036A26DA3](https://user-images.githubusercontent.com/33178517/84216311-afbaf580-aafb-11ea-9d60-eb9b013da74a.png)

Contributor guide

No contributing guide indexed for this repository

Research direction

No repository file or test is named. Start by running the shown Go program with the displayed terminal layout and inspect the paragraph, gauge, and list rendering around their SetRect and style configuration; the issue needs a reproducible mismatch and expected rendering before completion can be judged.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.