blob: 06841c2d04f7f2c0c3aaecaa37c88d8e1c0b1224 [file] [log] [blame]
Serge Bazanskid735a3c2024-09-05 13:51:44 +02001package tconsole
2
3import (
4 "time"
5
6 "github.com/gdamore/tcell/v2"
7)
8
9// draw button at coordinates containing text, with the left side of the button
10// at (x, y). The number of columns used up by the button is returned.
11func (c *Console) button(x, y int, caption string, selected bool, sty tcell.Style) int {
12 fg, bg, _ := sty.Decompose()
13 styInv := sty.Background(fg).Foreground(bg)
14
15 xi := 1
16 if selected {
17 c.screen.SetContent(x+xi, y, tcell.RuneBlock, nil, sty)
18 xi += 1
19 xi += c.drawText(x+xi, y, caption, styInv)
20 c.screen.SetContent(x+xi, y, tcell.RuneBlock, nil, sty)
21 xi += 1
22 } else {
23 c.screen.SetContent(x+xi, y, ' ', nil, sty)
24 xi += 1
25 xi += c.drawText(x+xi, y, caption, sty)
26 c.screen.SetContent(x+xi, y, ' ', nil, sty)
27 xi += 1
28 }
29 return xi
30}
31
32// statusBar draw the main status bar at the bottom of the screen, containing
33// page switching buttons and a clock.
34func (c *Console) statusBar(active int, opts ...string) {
35 sty1 := tcell.StyleDefault.Background(c.color(colorBlue)).Foreground(c.color(colorBlack))
36 sty2 := tcell.StyleDefault.Background(c.color(colorPink)).Foreground(c.color(colorBlack))
37 x := 0
38 x += c.drawText(x, c.height-1, " Page (tab to switch): ", sty1)
39 for i, opt := range opts {
40 x += c.button(x, c.height-1, opt, i == active, sty2)
41 }
42
43 c.drawText(c.width-len(time.DateTime)-1, c.height-1, time.Now().Format(time.DateTime), sty1)
44}