AT Protocol Terminal Interface Explorer
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

more jetstream styling

+65 -14
+2
ui/app.go
··· 91 91 a.repoView.SetSize(a.w, a.h) 92 92 a.rlist.SetSize(a.w, a.h) 93 93 a.recordView.SetSize(a.w, a.h) 94 + a.jetstream.SetSize(a.w, a.h) 94 95 return tea.Batch(cmds...) 95 96 } 96 97 ··· 121 122 return a, a.search.Init() 122 123 case "ctrl+j": 123 124 a.active = a.jetstream 125 + a.jetstream.SetSize(a.w, a.h) 124 126 if a.jetstream.Running() { 125 127 return a, a.jetstream.Stop() 126 128 } else {
+63 -14
ui/jetstream.go
··· 4 4 "context" 5 5 "fmt" 6 6 "log/slog" 7 + "strings" 7 8 "time" 8 9 9 10 "github.com/bluesky-social/jetstream/pkg/models" ··· 44 45 err error 45 46 } 46 47 48 + type session struct { 49 + lastCursor *int64 50 + collections []string 51 + dids []string 52 + } 53 + 47 54 type JetStreamView struct { 48 - list list.Model 49 - jc *at.JetStreamClient 50 - ctx context.Context 51 - cancel context.CancelFunc 55 + list list.Model 56 + jc *at.JetStreamClient 57 + ctx context.Context 58 + cancel context.CancelFunc 59 + session session 52 60 } 53 61 54 62 func NewJetStreamView(jc *at.JetStreamClient) *JetStreamView { ··· 83 91 } 84 92 85 93 func (m *JetStreamView) AddEvent(evt *models.Event) tea.Cmd { 94 + m.session.lastCursor = &evt.TimeUS 86 95 item := jetEventItem{evt: evt} 87 96 return m.list.InsertItem(0, item) 88 97 } ··· 102 111 slog.Warn("JetStream client already running") 103 112 return nil 104 113 } 114 + m.session = session{ 115 + lastCursor: cursor, 116 + collections: cxs, 117 + dids: dids, 118 + } 105 119 m.ctx, m.cancel = context.WithCancel(context.Background()) 106 120 slog.Info("Starting JetStream client", "collections", cxs, "dids", dids, "cursor", cursor) 107 121 go m.jc.Start(m.ctx, cxs, dids, cursor) ··· 120 134 return nil 121 135 } 122 136 func (m *JetStreamView) SetSize(w, h int) { 123 - m.list.SetSize(w, h) 137 + headerHeight := lipgloss.Height(m.header()) 138 + m.list.SetSize(w, h-headerHeight) 124 139 } 125 140 126 141 func (m *JetStreamView) Update(msg tea.Msg) (tea.Model, tea.Cmd) { 127 142 switch msg := msg.(type) { 128 143 129 - // case jetStreamStartMsg: 130 - // return m, m.Start(msg.cxs, msg.dids, msg.cur) 131 - // 132 - // case jetStreamStopMsg: 133 - // m.Stop() 134 - // return m, nil 135 - 136 144 case jetStreamErrorMsg: 137 145 slog.Error("JetStream client error", "error", msg.err) 138 146 return m, nil ··· 148 156 return m, cmd 149 157 } 150 158 159 + var jetstreamTitleStyle = lipgloss.NewStyle(). 160 + Bold(true). 161 + Foreground(lipgloss.Color("205")). 162 + BorderStyle(lipgloss.NormalBorder()). 163 + BorderBottom(true). 164 + BorderForeground(lipgloss.Color("62")). 165 + PaddingLeft(1) 166 + 167 + func (m *JetStreamView) header() string { 168 + cxs := dimStyle.Render("all") 169 + if len(m.session.collections) > 0 { 170 + cxs = strings.Join(m.session.collections, ", ") 171 + } 172 + dids := dimStyle.Render("all") 173 + if len(m.session.dids) > 0 { 174 + dids = strings.Join(m.session.dids, ", ") 175 + } 176 + lastCursor := dimStyle.Render("live") 177 + if m.session.lastCursor != nil { 178 + t := time.Unix(0, *m.session.lastCursor*int64(time.Microsecond)) 179 + lastCursor = t.Format("2006-01-02 15:04:05") 180 + } 181 + 182 + title := jetstreamTitleStyle.Render("馃摗 JetStream Events") 183 + 184 + dot := dimStyle.Render(" 路 ") 185 + filters := lipgloss.JoinHorizontal(lipgloss.Left, 186 + dimStyle.Render(" collections: "), cxs, 187 + dot, dimStyle.Render("dids: "), dids, 188 + dot, dimStyle.Render("cursor: "), lastCursor, 189 + ) 190 + 191 + return lipgloss.JoinVertical(lipgloss.Left, title, filters) 192 + } 193 + 151 194 func (m *JetStreamView) View() string { 152 195 if m.ctx == nil { 153 - return dimStyle.Render("JetStream client not running") 196 + return lipgloss.JoinVertical(lipgloss.Left, 197 + jetstreamTitleStyle.Render("馃摗 JetStream Events"), 198 + dimStyle.Render("\n not connected 路 press ctrl+j to start"), 199 + ) 154 200 } 155 - return m.list.View() 201 + return lipgloss.JoinVertical(lipgloss.Left, 202 + m.header(), 203 + m.list.View(), 204 + ) 156 205 }