yet another tui rfc reader
olexsmir.xyz/rfcr
1package main
2
3import (
4 "fmt"
5 "io"
6 "strings"
7
8 "github.com/charmbracelet/bubbles/list"
9 tea "github.com/charmbracelet/bubbletea"
10 "github.com/charmbracelet/lipgloss"
11)
12
13var (
14 itemStyle = lipgloss.NewStyle().PaddingLeft(4)
15 selectedItemStyle = lipgloss.NewStyle().
16 PaddingLeft(2).
17 Foreground(lipgloss.Color("170"))
18)
19
20type item string
21
22func (i item) FilterValue() string {
23 return string(i)
24}
25
26type itemDelegate struct{}
27
28func (d itemDelegate) Height() int {
29 return 1
30}
31
32func (d itemDelegate) Spacing() int {
33 return 0
34}
35
36func (d itemDelegate) Update(_ tea.Msg, _ *list.Model) tea.Cmd {
37 return nil
38}
39
40func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
41 // todo: print rfc title along with it's number
42
43 i, ok := listItem.(item)
44 if !ok {
45 return
46 }
47
48 fn := itemStyle.Render
49 if index == m.Index() {
50 fn = func(s ...string) string {
51 return selectedItemStyle.Render("> " + strings.Join(s, " "))
52 }
53 }
54
55 fmt.Fprint(w, fn(string(i)))
56}