repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
7f4090c
parent
5b0ef24
author
Eric Bower
date
2024-05-17 18:08:12 +0000 UTC
styles(tui): md word wrapping
4 files changed,  +13, -12
M pico/cli.go
+2, -2
 1@@ -52,12 +52,12 @@ func (c *Cmd) help() {
 2 }
 3 
 4 func (c *Cmd) plus() {
 5-	view := plus.PlusView(c.User.Name)
 6+	view := plus.PlusView(c.User.Name, 80)
 7 	c.output(view)
 8 }
 9 
10 func (c *Cmd) notifications() error {
11-	md := notifications.NotificationsView(c.Dbpool, c.User.ID)
12+	md := notifications.NotificationsView(c.Dbpool, c.User.ID, 80)
13 	c.output(md)
14 	return nil
15 }
M tui/notifications/notifications.go
+5, -3
 1@@ -11,7 +11,7 @@ import (
 2 	"github.com/picosh/pico/tui/pages"
 3 )
 4 
 5-func NotificationsView(dbpool db.DB, userID string) string {
 6+func NotificationsView(dbpool db.DB, userID string, w int) string {
 7 	pass, err := dbpool.UpsertToken(userID, "pico-rss")
 8 	if err != nil {
 9 		return err.Error()
10@@ -42,6 +42,7 @@ Create a feeds file (e.g. pico.txt):`, url)
11 	r, _ := glamour.NewTermRenderer(
12 		// detect background color and pick either the default dark or light theme
13 		glamour.WithAutoStyle(),
14+		glamour.WithWordWrap(w-20),
15 	)
16 	out, err := r.Render(md)
17 	if err != nil {
18@@ -70,10 +71,11 @@ func headerWidth(w int) int {
19 
20 func NewModel(shared common.SharedModel) Model {
21 	hh := headerHeight(shared)
22-	viewport := viewport.New(headerWidth(shared.Width), shared.Height-hh)
23+	ww := headerWidth(shared.Width)
24+	viewport := viewport.New(ww, shared.Height-hh)
25 	viewport.YPosition = hh
26 	if shared.User != nil {
27-		viewport.SetContent(NotificationsView(shared.Dbpool, shared.User.ID))
28+		viewport.SetContent(NotificationsView(shared.Dbpool, shared.User.ID, ww))
29 	}
30 
31 	return Model{
M tui/plus/plus.go
+5, -3
 1@@ -11,7 +11,7 @@ import (
 2 	"github.com/picosh/pico/tui/pages"
 3 )
 4 
 5-func PlusView(username string) string {
 6+func PlusView(username string, w int) string {
 7 	paymentLink := "https://auth.pico.sh/checkout"
 8 	url := fmt.Sprintf("%s/%s", paymentLink, url.QueryEscape(username))
 9 	md := fmt.Sprintf(`Signup to get premium access
10@@ -58,6 +58,7 @@ we plan on continuing to include more services as we build them.`, url)
11 	r, _ := glamour.NewTermRenderer(
12 		// detect background color and pick either the default dark or light theme
13 		glamour.WithAutoStyle(),
14+		glamour.WithWordWrap(w-20),
15 	)
16 	out, _ := r.Render(md)
17 	return out
18@@ -80,9 +81,10 @@ func headerWidth(w int) int {
19 // NewModel returns a new username model in its initial state.
20 func NewModel(shared common.SharedModel) Model {
21 	hh := headerHeight(shared)
22-	viewport := viewport.New(headerWidth(shared.Width), shared.Height-hh)
23+	ww := headerWidth(shared.Width)
24+	viewport := viewport.New(ww, shared.Height-hh)
25 	if shared.User != nil {
26-		viewport.SetContent(PlusView(shared.User.Name))
27+		viewport.SetContent(PlusView(shared.User.Name, ww))
28 	}
29 
30 	return Model{
M tui/ui.go
+1, -4
 1@@ -173,11 +173,8 @@ func (m *UI) View() string {
 2 		s += m.pages[m.activePage].View()
 3 	}
 4 
 5-	maxWidth := 100
 6 	width := m.shared.Width - m.shared.Styles.App.GetHorizontalFrameSize()
 7-	if width < maxWidth {
 8-		maxWidth = width
 9-	}
10+	maxWidth := width
11 	str := wrap.String(
12 		wordwrap.String(s, maxWidth),
13 		maxWidth,