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