Skip to content

Commit

Permalink
Merge pull request #33 from zMoooooritz/fullscreenReader
Browse files Browse the repository at this point in the history
Add keybind (f) to open the reader in fullscreen view
  • Loading branch information
zMoooooritz authored Nov 18, 2023
2 parents 6e3496f + 8541501 commit 08d6104
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 20 deletions.
28 changes: 17 additions & 11 deletions pkg/tui/keybinds.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ type KeyMap struct {
quit key.Binding
right key.Binding
left key.Binding
next key.Binding
up key.Binding
down key.Binding
prev key.Binding
next key.Binding
full key.Binding
start key.Binding
end key.Binding
open key.Binding
Expand Down Expand Up @@ -40,14 +41,6 @@ func GetKeyMap() KeyMap {
key.WithKeys("k", "up"),
key.WithHelp("↑/k", "up"),
),
start: key.NewBinding(
key.WithKeys("g", "home"),
key.WithHelp("g/home", "start"),
),
end: key.NewBinding(
key.WithKeys("G", "end"),
key.WithHelp("G/end", "end"),
),
next: key.NewBinding(
key.WithKeys("tab"),
key.WithHelp("tab", "next"),
Expand All @@ -56,6 +49,18 @@ func GetKeyMap() KeyMap {
key.WithKeys("shift+tab"),
key.WithHelp("shift+tab", "prev"),
),
full: key.NewBinding(
key.WithKeys("f"),
key.WithHelp("f", "full"),
),
start: key.NewBinding(
key.WithKeys("g", "home"),
key.WithHelp("g/home", "start"),
),
end: key.NewBinding(
key.WithKeys("G", "end"),
key.WithHelp("G/end", "end"),
),
open: key.NewBinding(
key.WithKeys("o"),
key.WithHelp("o", "open"),
Expand Down Expand Up @@ -85,10 +90,11 @@ func (k KeyMap) FullHelp() [][]key.Binding {
{k.right},
{k.up},
{k.down},
{k.start},
{k.end},
{k.next},
{k.prev},
{k.full},
{k.start},
{k.end},
{k.open},
{k.video},
{k.shortNews},
Expand Down
23 changes: 16 additions & 7 deletions pkg/tui/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ const (
)

type Reader struct {
style config.Style
isFocused bool
toplineText string
dateText string
viewport viewport.Model
style config.Style
isFocused bool
isFullScreen bool
toplineText string
dateText string
viewport viewport.Model
}

func NewReader(s config.Style) Reader {
Expand All @@ -47,6 +48,14 @@ func (r *Reader) IsFocused() bool {
return r.isFocused
}

func (r *Reader) SetFullScreen(isFullScreen bool) {
r.isFullScreen = isFullScreen
}

func (r *Reader) IsFullScreen() bool {
return r.isFullScreen
}

func (r *Reader) SetDims(w, h int) {
r.viewport.Width = w
r.viewport.Height = h - lipgloss.Height(r.headerView()) - lipgloss.Height(r.footerView())
Expand Down Expand Up @@ -81,7 +90,7 @@ func (r Reader) headerView() string {
titleStyle := r.style.ReaderTitleInactiveStyle
lineStyle := r.style.InactiveStyle
dateStyle := r.style.ReaderInfoInactiveStyle
if r.isFocused {
if r.isFocused || r.isFullScreen {
titleStyle = r.style.ReaderTitleActiveStyle
lineStyle = r.style.ActiveStyle
dateStyle = r.style.ReaderInfoActiveStyle
Expand All @@ -97,7 +106,7 @@ func (r Reader) headerView() string {
func (r Reader) footerView() string {
infoStyle := r.style.ReaderInfoInactiveStyle
lineStyle := r.style.InactiveStyle
if r.isFocused {
if r.isFocused || r.isFullScreen {
infoStyle = r.style.ReaderInfoActiveStyle
lineStyle = r.style.ActiveStyle
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/tui/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Selector struct {
listsActiveIndeces []int
activeListIndex int
isFocused bool
isVisible bool
fullWidth int
headerWidth int
height int
Expand All @@ -33,6 +34,7 @@ func NewSelector(s config.Style) Selector {
listsActiveIndeces: []int{},
activeListIndex: 0,
isFocused: true,
isVisible: true,
}
}

Expand Down Expand Up @@ -82,6 +84,10 @@ func (s *Selector) SetFocused(isFocused bool) {
s.isFocused = isFocused
}

func (s *Selector) SetVisible(isVisible bool) {
s.isVisible = isVisible
}

func (s *Selector) SetDims(w, h int) {
s.fullWidth = w
s.headerWidth = w - 4
Expand Down Expand Up @@ -117,6 +123,10 @@ func (s Selector) Update(msg tea.Msg) (Selector, tea.Cmd) {
}

func (s Selector) View() string {
if !s.isVisible {
return ""
}

listHeader := s.listView([]string{nationalHeaderText, regionalHeaderText}, s.activeListIndex)
listStyle := s.style.ListActiveStyle
if !s.isFocused {
Expand Down
15 changes: 13 additions & 2 deletions pkg/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, m.keymap.prev):
m.selector.PrevList()
m.setFocus(false)
case key.Matches(msg, m.keymap.full):
m.reader.SetFullScreen(!m.reader.IsFullScreen())
m.updateSizes(m.width, m.height)
m.updateDisplayedArticle()
case key.Matches(msg, m.keymap.start):
if m.reader.IsFocused() {
m.reader.GotoTop()
Expand Down Expand Up @@ -142,7 +146,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Batch(cmds...)
}

if m.reader.IsFocused() {
if m.reader.IsFocused() || m.reader.IsFullScreen() {
m.reader, cmd = m.reader.Update(msg)
cmds = append(cmds, cmd)
} else {
Expand Down Expand Up @@ -181,7 +185,14 @@ func (m *Model) updateSizes(width, height int) {
m.selector.SetDims(m.width/3, m.height-m.helperHeight()-5)
m.selector.ResizeLists()

m.reader.SetDims(m.width-m.width/3-6, m.height-m.helperHeight())
if m.reader.IsFullScreen() {
m.selector.SetVisible(false)
m.reader.SetDims(m.width, m.height-m.helperHeight())
} else {
m.selector.SetVisible(true)
m.reader.SetDims(m.width-m.width/3-6, m.height-m.helperHeight())
}

m.help.Width = m.width
}

Expand Down

0 comments on commit 08d6104

Please sign in to comment.