Skip to content

Commit

Permalink
feat: fullscreen rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelroses committed Jun 6, 2024
1 parent 94f9ce8 commit 8038b15
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 54 deletions.
2 changes: 2 additions & 0 deletions cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func (m Model) handleKeys(msg tea.KeyMsg) (Model, tea.Cmd) {
m = m.loadHome()
m.table.SetCursor(m.feed.ID)
}
m.viewport.SetYOffset(0)

case key.Matches(msg, m.keys.Open):
switch m.context {
Expand All @@ -179,6 +180,7 @@ func (m Model) handleKeys(msg tea.KeyMsg) (Model, tea.Cmd) {
default:
m = m.loadContent(m.table.Cursor())
m.table.SetCursor(0)
m.viewport.SetYOffset(0)
}

case key.Matches(msg, m.keys.Search):
Expand Down
19 changes: 0 additions & 19 deletions cmd/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,5 @@ func (m Model) loadNewTable(columns []table.Column, rows []table.Row) Model {
t.SetColumns(columns)
t.SetRows(rows)

// reset the cursor and how far down the viewport is
m.viewport.SetYOffset(0)

return m
}

func (m Model) loadReader() Model {
id := m.table.Cursor()
post := m.feed.Posts[id]
post.ID = id

m.context = "reader"
m.post = post
m.viewport.YPosition = 0 // reset the viewport position

// render the post
content := lib.RenderMarkdown(post.Content)
m.viewport.SetContent(content)

return m
}
7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/glamour"
"github.com/charmbracelet/lipgloss"

"github.com/isabelroses/izrss/lib"
Expand Down Expand Up @@ -49,6 +50,12 @@ func (m Model) handleWindowSize(msg tea.WindowSizeMsg) Model {
if err != nil {
log.Fatalf("could not read tracking file: %v", err)
}

m.glam, _ = glamour.NewTermRenderer(
glamour.WithEnvironmentConfig(),
glamour.WithWordWrap(width),
)

m = m.loadHome()

m.ready = true
Expand Down
2 changes: 2 additions & 0 deletions cmd/modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/charmbracelet/bubbles/textinput"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/glamour"
"github.com/charmbracelet/lipgloss"

"github.com/isabelroses/izrss/lib"
Expand All @@ -23,6 +24,7 @@ type Model struct {
feed lib.Feed
table table.Model
ready bool
glam *glamour.TermRenderer
}

// Init sets the initial state of the model
Expand Down
33 changes: 33 additions & 0 deletions cmd/render.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cmd

import (
"log"

tomd "github.com/JohannesKaufmann/html-to-markdown"
)

var htom = tomd.NewConverter("", true, nil)

func (m Model) loadReader() Model {
id := m.table.Cursor()
post := m.feed.Posts[id]
post.ID = id

m.context = "reader"
m.post = post
m.viewport.YPosition = 0 // reset the viewport position

// render the post
fromMd, err := htom.ConvertString(post.Content)
if err != nil {
log.Fatalf("could not convert html to markdown: %v", err)
}

out, err := m.glam.Render(fromMd)
if err != nil {
log.Fatalf("could not render markdown: %v", err)
}
m.viewport.SetContent(out)

return m
}
35 changes: 0 additions & 35 deletions lib/render.go

This file was deleted.

0 comments on commit 8038b15

Please sign in to comment.