Skip to content

Commit

Permalink
tui: minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Apr 27, 2023
1 parent 87a1435 commit 5592a32
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions internal/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,9 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
cmds = append(cmds, cmd)
}
switch msg := msg.(type) {
// TODO: not using useHighPerformanceRenderer
case tea.WindowSizeMsg:
if !m.IsReady {
m.progress = progress.New(
progress.WithGradient("#696969", "#D3D3D3"),
progress.WithoutPercentage(),
progress.WithWidth(msg.Width/5),
)
m.list = list.New(
getItems(m.RawContent),
itemDelegate{},
msg.Width,
msg.Height-1,
)
m.list.KeyMap = DefaultListKeyMap
m.list.SetShowTitle(false)
m.list.DisableQuitKeybindings()
m.Viewport = viewport.Model{
Width: msg.Width,
Height: msg.Height - 1,
KeyMap: DefaultViewportKeyMap,
// HighPerformanceRendering: true,
}
m.Initialize(msg)
m.IsReady = true
} else {
if m.onLinkScreen {
Expand All @@ -134,11 +114,8 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
}
case tea.KeyMsg:
if m.onLinkScreen {
// disables rest of the keybinding if we are filtering
if m.list.FilterState() == list.Filtering {
break
}
switch {
case m.list.FilterState() == list.Filtering:
case key.Matches(msg, DefaultKeyMap.LinksView, DefaultKeyMap.Quit):
m.onLinkScreen = false
case key.Matches(msg, DefaultKeyMap.LinksOpenXDG):
Expand Down Expand Up @@ -201,3 +178,28 @@ func isScrolling(msg tea.KeyMsg) bool {
DefaultViewportKeyMap.PageUp,
DefaultViewportKeyMap.PageDown)
}

func (m *Model) Initialize(msg tea.WindowSizeMsg) {
m.Viewport = viewport.Model{
Width: msg.Width,
Height: msg.Height - 1,
KeyMap: DefaultViewportKeyMap,
// HighPerformanceRendering: true,
}

m.progress = progress.New(
progress.WithGradient("#696969", "#D3D3D3"),
progress.WithoutPercentage(),
progress.WithWidth(msg.Width/5),
)

m.list = list.New(
getItems(m.RawContent),
itemDelegate{},
msg.Width,
msg.Height-1,
)
m.list.KeyMap = DefaultListKeyMap
m.list.SetShowTitle(false)
m.list.DisableQuitKeybindings()
}

0 comments on commit 5592a32

Please sign in to comment.