Skip to content

Commit

Permalink
make helpState more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
zMoooooritz committed May 7, 2024
1 parent b8894d9 commit 3e6ce74
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions pkg/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ const (
germanDateFormat string = "15:04 02.01.06"
)

type HelpState int

const (
HS_HIDDEN HelpState = iota
HS_NORMAL
HS_ALL
)

var (
screenCentered = func(w, h int) lipgloss.Style {
return lipgloss.NewStyle().
Expand All @@ -37,7 +45,7 @@ type Model struct {
style config.Style
ready bool
help help.Model
helpMode int
helpState HelpState
selector Selector
reader Reader
imageViewer ImageViewer
Expand All @@ -50,9 +58,9 @@ type Model struct {
func InitialModel(c config.Configuration) Model {
style := config.NewsStyle(c.Theme)

helpMode := 1
helpState := HS_NORMAL
if c.Settings.HideHelpOnStartup {
helpMode = 0
helpState = HS_HIDDEN
}

m := Model{
Expand All @@ -61,7 +69,7 @@ func InitialModel(c config.Configuration) Model {
style: style,
ready: false,
help: NewHelper(style),
helpMode: helpMode,
helpState: helpState,
selector: NewSelector(style, listKeymap(c.Keys)),
reader: NewReader(style, viewportKeymap(c.Keys)),
imageViewer: NewImageViewer(style, viewportKeymap(c.Keys)),
Expand Down Expand Up @@ -108,11 +116,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, m.keymap.quit):
return m, tea.Quit
case key.Matches(msg, m.keymap.help):
m.helpMode = (m.helpMode + 1) % 3
if m.helpMode == 1 {
m.helpState = (m.helpState + 1) % 3
if m.helpState == HS_NORMAL {
m.help.ShowAll = false
}
if m.helpMode == 2 {
if m.helpState == HS_ALL {
m.help.ShowAll = true
}
m.updateSizes(m.width, m.height)
Expand Down Expand Up @@ -287,7 +295,7 @@ func (m *Model) updateSizes(width, height int) {
}

func (m Model) helperHeight() int {
if m.helpMode > 0 {
if m.helpState == HS_NORMAL || m.helpState == HS_ALL {
return 2
}
return 0
Expand All @@ -309,7 +317,7 @@ func (m Model) View() string {
}

help := ""
if m.helpMode > 0 {
if m.helpState == HS_NORMAL || m.helpState == HS_ALL {
help = "\n" + lipgloss.NewStyle().Width(m.width).AlignHorizontal(lipgloss.Center).Render(m.help.View(m.keymap))
}

Expand Down

0 comments on commit 3e6ce74

Please sign in to comment.