Skip to content
This repository was archived by the owner on Apr 13, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/gitstream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func main() {
OnKey: func(de ui.DisplayEvent, key tea.KeyMsg) tea.Cmd {
if key.String() == "o" {
if url := de.Event.URL(); url != "" {
ui.OpenURL(url)
tuikit.OpenURL(url)
}
return tuikit.Consumed()
}
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.26.1
require (
github.com/charmbracelet/bubbletea v1.3.10
github.com/charmbracelet/lipgloss v1.1.0
github.com/moneycaringcoder/tuikit-go v0.5.4
github.com/moneycaringcoder/tuikit-go v0.7.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -27,8 +27,9 @@ require (
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/rcarmo/go-te v0.1.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.3.8 // indirect
golang.org/x/text v0.34.0 // indirect
)
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2J
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
github.com/moneycaringcoder/tuikit-go v0.5.4 h1:JVd7C7k01NnT5btty6prc6oVTx3LWYJXM1HDtLnZSeU=
github.com/moneycaringcoder/tuikit-go v0.5.4/go.mod h1:NNJ8NSFnHrd4A7dqmb0DO1kA6vtk8jmdCTKYJFL+h50=
github.com/moneycaringcoder/tuikit-go v0.7.0 h1:DEI3CGNhndFfpxYHjwDvd/TkDndQfTbFrixMy/QVj3E=
github.com/moneycaringcoder/tuikit-go v0.7.0/go.mod h1:2P2MPQGh/A+vpCcrgh5Taz+XqMlrpPgAsc2cd4W8ucg=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/rcarmo/go-te v0.1.0 h1:BH9Ub+A0AVBY5Q00El4QMVaWAMbycVHgMHQI2Kz8J/o=
github.com/rcarmo/go-te v0.1.0/go.mod h1:cLsrtroxCubS+OHHwH0riB6xeNESfntaHEeI1jPAedk=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
Expand All @@ -48,8 +50,8 @@ golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
49 changes: 3 additions & 46 deletions internal/ui/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package ui

import (
"fmt"
"os/exec"
"runtime"
"time"

"github.com/moneycaringcoder/gitstream-tui/internal/github"
tuikit "github.com/moneycaringcoder/tuikit-go"
)

const flashDuration = 3 * time.Second
Expand All @@ -17,34 +16,9 @@ type DisplayEvent struct {
AddedAt time.Time
}

func relativeTime(t time.Time, now time.Time) string {
d := now.Sub(t)
if d < 0 {
d = 0
}
switch {
case d < time.Minute:
return fmt.Sprintf("%ds ago", int(d.Seconds()))
case d < time.Hour:
return fmt.Sprintf("%dm ago", int(d.Minutes()))
case d < 24*time.Hour:
return fmt.Sprintf("%dh ago", int(d.Hours()))
default:
return fmt.Sprintf("%dd ago", int(d.Hours()/24))
}
}

// osc8 wraps text in an OSC8 hyperlink escape sequence.
func osc8(url, text string) string {
if url == "" {
return text
}
return fmt.Sprintf("\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\", url, text)
}

func renderEventLine(ev github.Event, now time.Time) string {
t := ev.CreatedAt.Local().Format("15:04:05")
rel := relativeTime(ev.CreatedAt, now)
rel := tuikit.RelativeTime(ev.CreatedAt, now)
timeStr := fmt.Sprintf("%s %s", t, rel)

label := ev.Label()
Expand All @@ -55,7 +29,7 @@ func renderEventLine(ev github.Event, now time.Time) string {

detailRendered := DetailStyle.Render(detail)
if url != "" {
detailRendered = osc8(url, detailRendered)
detailRendered = tuikit.OSC8Link(url, detailRendered)
}

line := fmt.Sprintf("%s %s %s %s %s",
Expand All @@ -68,20 +42,3 @@ func renderEventLine(ev github.Event, now time.Time) string {

return line
}

// OpenURL opens a URL in the default browser.
func OpenURL(url string) {
var cmd *exec.Cmd
switch runtime.GOOS {
case "darwin":
cmd = exec.Command("open", url)
case "windows":
cmd = exec.Command("rundll32", "url.dll,FileProtocolHandler", url)
default:
cmd = exec.Command("xdg-open", url)
}
if err := cmd.Start(); err != nil {
return
}
go cmd.Wait()
}
17 changes: 5 additions & 12 deletions internal/ui/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func NewEventStream(cfg *config.Config, debugLog *DebugLog) *EventStream {
return s.renderHeader()
},
DetailFunc: func(item DisplayEvent, theme tuikit.Theme) string {
return s.renderDetailBar(item)
return s.renderDetailBar(item, theme)
},
FlashFunc: func(item DisplayEvent, now time.Time) bool {
return !item.AddedAt.IsZero() && now.Before(item.AddedAt.Add(flashDuration))
Expand Down Expand Up @@ -115,7 +115,7 @@ func (s *EventStream) Update(msg tea.Msg) (tuikit.Component, tea.Cmd) {
if msg.String() == "o" {
if item := s.listView.CursorItem(); item != nil {
if url := item.Event.URL(); url != "" {
OpenURL(url)
tuikit.OpenURL(url)
}
return s, tuikit.Consumed()
}
Expand Down Expand Up @@ -293,9 +293,9 @@ func (s *EventStream) renderHeader() string {
return lipgloss.JoinVertical(lipgloss.Left, title, repoList, status, "")
}

func (s *EventStream) renderDetailBar(de DisplayEvent) string {
func (s *EventStream) renderDetailBar(de DisplayEvent, theme tuikit.Theme) string {
ev := de.Event
divider := DividerStyle.Render(strings.Repeat("─", s.width))
divider := tuikit.Divider(s.width, theme)

repo := ev.Repo.Name
label := ev.Label()
Expand All @@ -310,14 +310,7 @@ func (s *EventStream) renderDetailBar(de DisplayEvent) string {
DetailTimeStyle.Render(t),
)

detail := ev.Detail()
maxDetail := s.width - 20
if maxDetail < 20 {
maxDetail = 20
}
if len(detail) > maxDetail {
detail = detail[:maxDetail-1] + "…"
}
detail := tuikit.Truncate(ev.Detail(), s.width-20)
urlHint := ""
if url := ev.URL(); url != "" {
urlHint = DetailTimeStyle.Render(" ↵ open")
Expand Down
Loading
Loading