Skip to content

Commit

Permalink
Display score info
Browse files Browse the repository at this point in the history
  • Loading branch information
xwjdsh committed Dec 9, 2017
1 parent d4aab4e commit 64e9511
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 27 deletions.
33 changes: 30 additions & 3 deletions cui.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
package main

import tui "github.com/marcusolsson/tui-go"
import (
"bytes"
"fmt"

func newUI() {
scoreBox := tui.NewVBox()
figure "github.com/common-nighthawk/go-figure"
tui "github.com/marcusolsson/tui-go"
)

func newUI(game *Game) {

grid := tui.NewGrid(0, 0)

homeBuf := new(bytes.Buffer)
figure.Write(homeBuf, figure.NewFigure(game.HomeScore.(string), "slant", true))
visitBuf := new(bytes.Buffer)
figure.Write(visitBuf, figure.NewFigure(game.VisitScore.(string), "slant", true))

homeLabel := tui.NewLabel(homeBuf.String())
visitLabel := tui.NewLabel(visitBuf.String())
homeLabel.SetStyleName("score")
visitLabel.SetStyleName("score")

grid.AppendRow(tui.NewHBox(homeLabel, visitLabel))

scoreBox := tui.NewVBox(grid)
scoreBox.SetTitle(fmt.Sprintf("%s VS %s", game.HomeTeam, game.VisitTeam))
scoreBox.SetBorder(true)

liveBox := tui.NewVBox()
liveBox.SetTitle("直播")
liveBox.SetBorder(true)
liveBox.SetSizePolicy(tui.Maximum, tui.Expanding)

theme := tui.NewTheme()
theme.SetStyle("label.score", tui.Style{Fg: tui.ColorCyan, Bold: true})

root := tui.NewVBox(scoreBox, liveBox)
ui := tui.New(root)
ui.SetTheme(theme)
ui.SetKeybinding("Esc", func() { ui.Quit() })

if err := ui.Run(); err != nil {
Expand Down
18 changes: 10 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package main

import (
"log"
"os"

"github.com/fatih/color"
)

const (
SUCCESS = "\u2714"
ERROR = "\u2716"
)

func main() {
games, err := getGames()
if err != nil {
color.Red("\u2716 获取比赛数据错误:", err.Error())
color.Red("%s 获取比赛数据错误:%s", ERROR, err.Error())
return
}

if len(games) == 0 {
color.Green("\u2714 暂无比赛数据")
color.Green("%s 暂无比赛数据", SUCCESS)
return
}

Expand All @@ -37,8 +39,8 @@ func main() {
//}
i, err := newSelect(games)
if err != nil {
os.Exit(1)
color.Red("%s 选择比赛错误:%s", ERROR, err.Error())
return
}
log.Println(i)
newUI()
newUI(games[i])
}
30 changes: 14 additions & 16 deletions models.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package main

type Game struct {
ID string `json:"id"`
Sdate string `json:"sdate"`
Time string `json:"time"`
URL string `json:"url"`
Type string `json:"type"`
Start string `json:"start"`
HomeTeam string `json:"home_team"`
VisitTeam string `json:"visit_team"`
HomeScore string `json:"home_score"`
HomeScoreNum int `json:"home_score"`
VisitScore string `json:"visit_score"`
VisitScoreNum int `json:"visit_score"`
PeriodCn string `json:"period_cn"`
From string `json:"from"`
Code string `json:"code"`
Update string `json:"update"`
ID string `json:"id"`
Sdate string `json:"sdate"`
Time string `json:"time"`
URL string `json:"url"`
Type string `json:"type"`
Start string `json:"start"`
HomeTeam string `json:"home_team"`
VisitTeam string `json:"visit_team"`
HomeScore interface{} `json:"home_score"`
VisitScore interface{} `json:"visit_score"`
PeriodCn string `json:"period_cn"`
From string `json:"from"`
Code string `json:"code"`
Update string `json:"update"`
//BigScore1 string `json:"big_score_1"`
//BigScore2 string `json:"big_score_2"`
}
Expand Down

0 comments on commit 64e9511

Please sign in to comment.