-
Notifications
You must be signed in to change notification settings - Fork 2
/
help.go
83 lines (70 loc) · 2.68 KB
/
help.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"restman/components/config"
"restman/components/overlay"
"restman/components/popup"
"restman/utils"
"github.com/charmbracelet/bubbles/help"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
var general = lipgloss.NewStyle().
UnsetAlign().
Padding(1, 2).
Border(lipgloss.RoundedBorder()).
Foreground(config.COLOR_FOREGROUND).
BorderForeground(config.COLOR_HIGHLIGHT)
type Help struct {
overlay popup.Overlay
help help.Model
keys config.KeyMap
bgRaw string
}
func NewHelp(bgRaw string, width int) Help {
help := help.New()
help.ShowAll = true
return Help{
help: help,
keys: config.Keys,
overlay: popup.NewOverlay(bgRaw, width, 20),
bgRaw: bgRaw,
}
}
func (c Help) Init() tea.Cmd {
return nil
}
func (c Help) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmds []tea.Cmd
switch msg := msg.(type) {
case tea.WindowSizeMsg:
c.help.Width = msg.Width
case tea.KeyMsg:
switch msg.Type {
case tea.KeyCtrlC, tea.KeyEsc:
return c, func() tea.Msg { return popup.ClosePopupMsg{} }
}
}
return c, tea.Batch(cmds...)
}
func (c Help) View() string {
icon := `██████╗ ███████╗███████╗████████╗███╗ ███╗ █████╗ ███╗ ██╗
██╔══██╗██╔════╝██╔════╝╚══██╔══╝████╗ ████║██╔══██╗████╗ ██║
██████╔╝█████╗ ███████╗ ██║ ██╔████╔██║███████║██╔██╗ ██║
██╔══██╗██╔══╝ ╚════██║ ██║ ██║╚██╔╝██║██╔══██║██║╚██╗██║
██║ ██║███████╗███████║ ██║ ██║ ╚═╝ ██║██║ ██║██║ ╚████║
╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝
`
helpView := c.help.View(c.keys)
iconStyle := lipgloss.NewStyle().Foreground(config.COLOR_HIGHLIGHT)
ui := iconStyle.Render(lipgloss.JoinVertical(
lipgloss.Center,
icon,
" https://github.com/jackMort/Restman, version: "+version,
"",
general.Width(c.overlay.Width()-2).Render(helpView)),
)
dialog := lipgloss.Place(c.overlay.Width(), c.overlay.Height(), lipgloss.Left, lipgloss.Top, ui)
startCol, startRow := utils.GetStartColRow(dialog, c.bgRaw)
return overlay.PlaceOverlay(startCol, startRow, dialog, c.bgRaw)
// return c.overlay.WrapView(dialog)
}