...
1 package main
2
3 import (
4 "fmt"
5 "strings"
6
7 "github.com/gdamore/tcell/v2"
8 "github.com/rivo/tview"
9 )
10
11 const logo = `
12 __ _
13 / /__ __(_)__ _ __
14 / __/ | / / / _ \ | /| / /
15 / /_ | |/ / / __/ |/ |/ /
16 \__/ |___/_/\___/|__/|__/
17
18 `
19
20 const (
21 subtitle = `tview - Rich Widgets for Terminal UIs`
22 navigation = `Ctrl-N: Next slide Ctrl-P: Previous slide Ctrl-C: Exit`
23 mouse = `(or use your mouse)`
24 )
25
26
27 func Cover(nextSlide func()) (title string, content tview.Primitive) {
28
29 lines := strings.Split(logo, "\n")
30 logoWidth := 0
31 logoHeight := len(lines)
32 for _, line := range lines {
33 if len(line) > logoWidth {
34 logoWidth = len(line)
35 }
36 }
37 logoBox := tview.NewTextView().
38 SetTextColor(tcell.ColorGreen).
39 SetDoneFunc(func(key tcell.Key) {
40 nextSlide()
41 })
42 fmt.Fprint(logoBox, logo)
43
44
45 frame := tview.NewFrame(tview.NewBox()).
46 SetBorders(0, 0, 0, 0, 0, 0).
47 AddText(subtitle, true, tview.AlignCenter, tcell.ColorWhite).
48 AddText("", true, tview.AlignCenter, tcell.ColorWhite).
49 AddText(navigation, true, tview.AlignCenter, tcell.ColorDarkMagenta).
50 AddText(mouse, true, tview.AlignCenter, tcell.ColorDarkMagenta)
51
52
53 flex := tview.NewFlex().
54 SetDirection(tview.FlexRow).
55 AddItem(tview.NewBox(), 0, 7, false).
56 AddItem(tview.NewFlex().
57 AddItem(tview.NewBox(), 0, 1, false).
58 AddItem(logoBox, logoWidth, 1, true).
59 AddItem(tview.NewBox(), 0, 1, false), logoHeight, 1, true).
60 AddItem(frame, 0, 10, false)
61
62 return "Start", flex
63 }
64
View as plain text