fix back hint in help views
This commit is contained in:
parent
a92ea6df48
commit
e8361766b3
12 changed files with 61 additions and 117 deletions
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
@ -66,19 +65,7 @@ func NewInstallation(root components.RootModel, parent tea.Model, installationDa
|
|||
model.list.Styles = utils.ListStyles
|
||||
model.list.SetSize(model.list.Width(), model.list.Height())
|
||||
model.list.StatusMessageLifetime = time.Second * 3
|
||||
model.list.DisableQuitKeybindings()
|
||||
|
||||
model.list.AdditionalShortHelpKeys = func() []key.Binding {
|
||||
return []key.Binding{
|
||||
key.NewBinding(key.WithHelp("q", "back")),
|
||||
}
|
||||
}
|
||||
|
||||
model.list.AdditionalFullHelpKeys = func() []key.Binding {
|
||||
return []key.Binding{
|
||||
key.NewBinding(key.WithHelp("q", "back")),
|
||||
}
|
||||
}
|
||||
model.list.KeyMap.Quit.SetHelp("q", "back")
|
||||
|
||||
return model
|
||||
}
|
||||
|
|
|
@ -28,12 +28,10 @@ func NewInstallations(root components.RootModel, parent tea.Model) tea.Model {
|
|||
l.Styles = utils.ListStyles
|
||||
l.SetSize(l.Width(), l.Height())
|
||||
l.KeyMap.Quit.SetHelp("q", "back")
|
||||
l.DisableQuitKeybindings()
|
||||
|
||||
l.AdditionalShortHelpKeys = func() []key.Binding {
|
||||
return []key.Binding{
|
||||
key.NewBinding(key.WithHelp("q", "back")),
|
||||
key.NewBinding(key.WithHelp("n", "new installation")),
|
||||
key.NewBinding(key.WithKeys("n"), key.WithHelp("n", "new installation")),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,9 +49,6 @@ func (m installations) Init() tea.Cmd {
|
|||
}
|
||||
|
||||
func (m installations) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
// List enables its own keybindings when they were previously disabled
|
||||
m.list.DisableQuitKeybindings()
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
if m.list.SettingFilter() {
|
||||
|
|
|
@ -42,8 +42,6 @@ func NewInstalledMods(root components.RootModel, parent tea.Model) tea.Model {
|
|||
l.Title = "Installed Mods"
|
||||
l.Styles = utils.ListStyles
|
||||
l.SetSize(l.Width(), l.Height())
|
||||
l.KeyMap.Quit.SetHelp("q", "back")
|
||||
l.DisableQuitKeybindings()
|
||||
|
||||
l.AdditionalShortHelpKeys = func() []key.Binding {
|
||||
return []key.Binding{
|
||||
|
@ -160,8 +158,7 @@ func (m installedModsList) LoadModData() {
|
|||
}
|
||||
|
||||
func (m installedModsList) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
// List enables its own keybindings when they were previously disabled
|
||||
m.list.DisableQuitKeybindings()
|
||||
m.list.KeyMap.Quit.SetHelp("q", "back")
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
|
|
|
@ -127,7 +127,6 @@ func NewMainMenu(root components.RootModel) tea.Model {
|
|||
model.list.SetFilteringEnabled(false)
|
||||
model.list.Title = "Main Menu"
|
||||
model.list.Styles = utils.ListStyles
|
||||
model.list.DisableQuitKeybindings()
|
||||
|
||||
return model
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package scenes
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
@ -101,21 +100,8 @@ func NewModMenu(root components.RootModel, parent tea.Model, mod utils.Mod) tea.
|
|||
model.list.Title = mod.Name
|
||||
model.list.Styles = utils.ListStyles
|
||||
model.list.SetSize(model.list.Width(), model.list.Height())
|
||||
model.list.KeyMap.Quit.SetHelp("q", "back")
|
||||
model.list.StatusMessageLifetime = time.Second * 3
|
||||
model.list.DisableQuitKeybindings()
|
||||
|
||||
model.list.AdditionalShortHelpKeys = func() []key.Binding {
|
||||
return []key.Binding{
|
||||
key.NewBinding(key.WithHelp("q", "back")),
|
||||
}
|
||||
}
|
||||
|
||||
model.list.AdditionalFullHelpKeys = func() []key.Binding {
|
||||
return []key.Binding{
|
||||
key.NewBinding(key.WithHelp("q", "back")),
|
||||
}
|
||||
}
|
||||
model.list.KeyMap.Quit.SetHelp("q", "back")
|
||||
|
||||
return model
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package scenes
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
@ -67,21 +66,8 @@ func NewModVersion(root components.RootModel, parent tea.Model, mod utils.Mod) t
|
|||
model.list.Title = mod.Name
|
||||
model.list.Styles = utils.ListStyles
|
||||
model.list.SetSize(model.list.Width(), model.list.Height())
|
||||
model.list.KeyMap.Quit.SetHelp("q", "back")
|
||||
model.list.StatusMessageLifetime = time.Second * 3
|
||||
model.list.DisableQuitKeybindings()
|
||||
|
||||
model.list.AdditionalShortHelpKeys = func() []key.Binding {
|
||||
return []key.Binding{
|
||||
key.NewBinding(key.WithHelp("q", "back")),
|
||||
}
|
||||
}
|
||||
|
||||
model.list.AdditionalFullHelpKeys = func() []key.Binding {
|
||||
return []key.Binding{
|
||||
key.NewBinding(key.WithHelp("q", "back")),
|
||||
}
|
||||
}
|
||||
model.list.KeyMap.Quit.SetHelp("q", "back")
|
||||
|
||||
return model
|
||||
}
|
||||
|
|
|
@ -63,8 +63,6 @@ func NewMods(root components.RootModel, parent tea.Model) tea.Model {
|
|||
l.Title = modsTitle
|
||||
l.Styles = utils.ListStyles
|
||||
l.SetSize(l.Width(), l.Height())
|
||||
l.KeyMap.Quit.SetHelp("q", "back")
|
||||
l.DisableQuitKeybindings()
|
||||
|
||||
l.AdditionalShortHelpKeys = func() []key.Binding {
|
||||
return []key.Binding{
|
||||
|
@ -167,8 +165,6 @@ func NewMods(root components.RootModel, parent tea.Model) tea.Model {
|
|||
sortFieldList.Title = modsTitle
|
||||
sortFieldList.Styles = utils.ListStyles
|
||||
sortFieldList.SetSize(l.Width(), l.Height())
|
||||
sortFieldList.KeyMap.Quit.SetHelp("q", "back")
|
||||
sortFieldList.DisableQuitKeybindings()
|
||||
|
||||
sortOrderList := list.New([]list.Item{
|
||||
utils.SimpleItemExtra[modsList, ficsit.ModsModsGetModsModsMod]{
|
||||
|
@ -200,8 +196,6 @@ func NewMods(root components.RootModel, parent tea.Model) tea.Model {
|
|||
sortOrderList.Title = modsTitle
|
||||
sortOrderList.Styles = utils.ListStyles
|
||||
sortOrderList.SetSize(l.Width(), l.Height())
|
||||
sortOrderList.KeyMap.Quit.SetHelp("q", "back")
|
||||
sortOrderList.DisableQuitKeybindings()
|
||||
|
||||
m := &modsList{
|
||||
root: root,
|
||||
|
@ -281,8 +275,7 @@ func (m modsList) Init() tea.Cmd {
|
|||
}
|
||||
|
||||
func (m modsList) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
// List enables its own keybindings when they were previously disabled
|
||||
m.list.DisableQuitKeybindings()
|
||||
m.list.KeyMap.Quit.SetHelp("q", "back")
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
|
|
|
@ -43,8 +43,6 @@ func NewNewInstallation(root components.RootModel, parent tea.Model) tea.Model {
|
|||
l.Styles = utils.ListStyles
|
||||
l.SetSize(l.Width(), l.Height())
|
||||
l.KeyMap.Quit.SetHelp("esc", "back")
|
||||
l.DisableQuitKeybindings()
|
||||
l.SetShowHelp(false)
|
||||
l.SetShowStatusBar(false)
|
||||
|
||||
model := newInstallation{
|
||||
|
@ -149,7 +147,8 @@ func (m newInstallation) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
}
|
||||
|
||||
func (m newInstallation) View() string {
|
||||
inputView := lipgloss.NewStyle().Padding(1, 2).Render(m.input.View())
|
||||
style := lipgloss.NewStyle().Padding(1, 2)
|
||||
inputView := style.Render(m.input.View())
|
||||
|
||||
mandatory := lipgloss.JoinVertical(lipgloss.Left, m.root.View(), m.title, inputView)
|
||||
|
||||
|
@ -157,19 +156,18 @@ func (m newInstallation) View() string {
|
|||
return lipgloss.JoinVertical(lipgloss.Left, mandatory, m.error.View())
|
||||
}
|
||||
|
||||
if len(m.dirList.Items()) > 0 {
|
||||
m.dirList.SetSize(m.dirList.Width(), m.root.Size().Height-lipgloss.Height(mandatory)-1)
|
||||
return lipgloss.JoinVertical(lipgloss.Left, mandatory, m.dirList.View())
|
||||
if len(m.dirList.Items()) == 0 {
|
||||
infoBox := lipgloss.NewStyle().
|
||||
BorderStyle(lipgloss.ThickBorder()).
|
||||
BorderForeground(lipgloss.Color("39")).
|
||||
Padding(0, 1).
|
||||
Margin(0, 0, 0, 2).
|
||||
Render("Enter the path to the satisfactory installation")
|
||||
mandatory = lipgloss.JoinVertical(lipgloss.Left, mandatory, infoBox)
|
||||
}
|
||||
|
||||
infoBox := lipgloss.NewStyle().
|
||||
BorderStyle(lipgloss.ThickBorder()).
|
||||
BorderForeground(lipgloss.Color("39")).
|
||||
Padding(0, 1).
|
||||
Margin(0, 0, 0, 2).
|
||||
Render("Enter the path to the satisfactory installation")
|
||||
|
||||
return lipgloss.JoinVertical(lipgloss.Left, mandatory, infoBox)
|
||||
m.dirList.SetSize(m.dirList.Width(), m.root.Size().Height-lipgloss.Height(mandatory)-1)
|
||||
return lipgloss.JoinVertical(lipgloss.Left, mandatory, style.Render(m.dirList.View()))
|
||||
}
|
||||
|
||||
// I know this is awful, but beats re-implementing the entire list model
|
||||
|
|
|
@ -3,6 +3,8 @@ package scenes
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/bubbles/help"
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
@ -13,12 +15,30 @@ import (
|
|||
|
||||
var _ tea.Model = (*newProfile)(nil)
|
||||
|
||||
type keyMap struct {
|
||||
Back key.Binding
|
||||
Quit key.Binding
|
||||
Enter key.Binding
|
||||
}
|
||||
|
||||
func (k keyMap) ShortHelp() []key.Binding {
|
||||
return []key.Binding{k.Enter, k.Back}
|
||||
}
|
||||
|
||||
func (k keyMap) FullHelp() [][]key.Binding {
|
||||
return [][]key.Binding{
|
||||
{k.Enter, k.Back}, // second column
|
||||
}
|
||||
}
|
||||
|
||||
type newProfile struct {
|
||||
input textinput.Model
|
||||
root components.RootModel
|
||||
parent tea.Model
|
||||
error *components.ErrorComponent
|
||||
title string
|
||||
help help.Model
|
||||
keys keyMap
|
||||
}
|
||||
|
||||
func NewNewProfile(root components.RootModel, parent tea.Model) tea.Model {
|
||||
|
@ -27,6 +47,20 @@ func NewNewProfile(root components.RootModel, parent tea.Model) tea.Model {
|
|||
parent: parent,
|
||||
input: textinput.New(),
|
||||
title: utils.NonListTitleStyle.Render("New Profile"),
|
||||
help: help.New(),
|
||||
keys: keyMap{
|
||||
Back: key.NewBinding(
|
||||
key.WithKeys(KeyEscape, KeyControlC),
|
||||
key.WithHelp(KeyEscape, "back"),
|
||||
),
|
||||
Enter: key.NewBinding(
|
||||
key.WithKeys(KeyEnter),
|
||||
key.WithHelp(KeyEnter, "create"),
|
||||
),
|
||||
Quit: key.NewBinding(
|
||||
key.WithKeys(KeyControlC),
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
model.input.Focus()
|
||||
|
@ -42,12 +76,12 @@ func (m newProfile) Init() tea.Cmd {
|
|||
func (m newProfile) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
switch keypress := msg.String(); keypress {
|
||||
case KeyControlC:
|
||||
switch {
|
||||
case key.Matches(msg, m.keys.Quit):
|
||||
return m, tea.Quit
|
||||
case KeyEscape:
|
||||
case key.Matches(msg, m.keys.Back):
|
||||
return m.parent, nil
|
||||
case KeyEnter:
|
||||
case key.Matches(msg, m.keys.Enter):
|
||||
if _, err := m.root.GetGlobal().Profiles.AddProfile(m.input.Value()); err != nil {
|
||||
errorComponent, cmd := components.NewErrorComponent(err.Error(), time.Second*5)
|
||||
m.error = errorComponent
|
||||
|
@ -74,7 +108,8 @@ func (m newProfile) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
}
|
||||
|
||||
func (m newProfile) View() string {
|
||||
inputView := lipgloss.NewStyle().Padding(1, 2).Render(m.input.View())
|
||||
style := lipgloss.NewStyle().Padding(1, 2)
|
||||
inputView := style.Render(m.input.View())
|
||||
|
||||
if m.error != nil {
|
||||
return lipgloss.JoinVertical(lipgloss.Left, m.root.View(), m.title, m.error.View(), inputView)
|
||||
|
@ -87,5 +122,5 @@ func (m newProfile) View() string {
|
|||
Margin(0, 0, 0, 2).
|
||||
Render("Enter the name of the profile")
|
||||
|
||||
return lipgloss.JoinVertical(lipgloss.Left, m.root.View(), m.title, inputView, infoBox)
|
||||
return lipgloss.JoinVertical(lipgloss.Left, m.root.View(), m.title, inputView, infoBox, style.Render(m.help.View(m.keys)))
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
@ -78,19 +77,7 @@ func NewProfile(root components.RootModel, parent tea.Model, profileData *cli.Pr
|
|||
model.list.Styles = utils.ListStyles
|
||||
model.list.SetSize(model.list.Width(), model.list.Height())
|
||||
model.list.StatusMessageLifetime = time.Second * 3
|
||||
model.list.DisableQuitKeybindings()
|
||||
|
||||
model.list.AdditionalShortHelpKeys = func() []key.Binding {
|
||||
return []key.Binding{
|
||||
key.NewBinding(key.WithHelp("q", "back")),
|
||||
}
|
||||
}
|
||||
|
||||
model.list.AdditionalFullHelpKeys = func() []key.Binding {
|
||||
return []key.Binding{
|
||||
key.NewBinding(key.WithHelp("q", "back")),
|
||||
}
|
||||
}
|
||||
model.list.KeyMap.Quit.SetHelp("q", "back")
|
||||
|
||||
return model
|
||||
}
|
||||
|
|
|
@ -28,12 +28,10 @@ func NewProfiles(root components.RootModel, parent tea.Model) tea.Model {
|
|||
l.Styles = utils.ListStyles
|
||||
l.SetSize(l.Width(), l.Height())
|
||||
l.KeyMap.Quit.SetHelp("q", "back")
|
||||
l.DisableQuitKeybindings()
|
||||
|
||||
l.AdditionalShortHelpKeys = func() []key.Binding {
|
||||
return []key.Binding{
|
||||
key.NewBinding(key.WithHelp("q", "back")),
|
||||
key.NewBinding(key.WithHelp("n", "new profile")),
|
||||
key.NewBinding(key.WithKeys("n"), key.WithHelp("n", "new profile")),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,9 +49,6 @@ func (m profiles) Init() tea.Cmd {
|
|||
}
|
||||
|
||||
func (m profiles) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
// List enables its own keybindings when they were previously disabled
|
||||
m.list.DisableQuitKeybindings()
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
if m.list.SettingFilter() {
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
"github.com/charmbracelet/bubbles/spinner"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
@ -36,19 +35,6 @@ func NewModVersionList(root components.RootModel, parent tea.Model, mod utils.Mo
|
|||
l.Styles = utils.ListStyles
|
||||
l.SetSize(l.Width(), l.Height())
|
||||
l.KeyMap.Quit.SetHelp("q", "back")
|
||||
l.DisableQuitKeybindings()
|
||||
|
||||
l.AdditionalShortHelpKeys = func() []key.Binding {
|
||||
return []key.Binding{
|
||||
key.NewBinding(key.WithHelp("q", "back")),
|
||||
}
|
||||
}
|
||||
|
||||
l.AdditionalFullHelpKeys = func() []key.Binding {
|
||||
return []key.Binding{
|
||||
key.NewBinding(key.WithHelp("q", "back")),
|
||||
}
|
||||
}
|
||||
|
||||
m := &selectModVersionList{
|
||||
root: root,
|
||||
|
|
Loading…
Reference in a new issue