diff --git a/internal/discourse/format.go b/internal/discourse/format.go index 50c4aae..e0ba191 100644 --- a/internal/discourse/format.go +++ b/internal/discourse/format.go @@ -5,15 +5,9 @@ import ( "strings" "github.com/azimut/cli-view/internal/format" - "github.com/charmbracelet/lipgloss" "github.com/dustin/go-humanize" ) -var authorStyle = lipgloss.NewStyle(). - Bold(true). - Background(lipgloss.Color("8")). - Foreground(lipgloss.Color("0")) - func (t Thread) String() (ret string) { ret += fmt.Sprint(t.op) for _, comment := range t.comments { @@ -30,7 +24,11 @@ func (o Op) String() (ret string) { "\n%s\n\n", format.FormatHtml2Text(o.message, o.thread.Width, o.thread.LeftPadding), ) - ret += fmt.Sprintf("%s - %s \n\n\n", authorStyle.Render(o.author), humanize.Time(o.createdAt)) + ret += fmt.Sprintf( + "%s - %s \n\n\n", + format.AuthorStyle.Render(o.author), + humanize.Time(o.createdAt), + ) return } @@ -44,7 +42,7 @@ func (c Comment) String() (ret string) { if c.thread.ShowAuthor { ret += " " if c.author == c.thread.op.author { - ret += authorStyle.Render(c.author) + ret += format.AuthorStyle.Render(c.author) } else { ret += c.author } diff --git a/internal/format/format.go b/internal/format/format.go index 8c684ad..21957de 100644 --- a/internal/format/format.go +++ b/internal/format/format.go @@ -4,11 +4,16 @@ import ( "strings" text "github.com/MichaelMure/go-term-text" + "github.com/charmbracelet/lipgloss" "github.com/fatih/color" "github.com/jaytaylor/html2text" ) var green = color.New(color.FgGreen) +var AuthorStyle = lipgloss.NewStyle(). + Bold(true). + Background(lipgloss.Color("8")). + Foreground(lipgloss.Color("0")) // GreenTextIt makes green the lines in `text` that start with ">" func GreenTextIt(text string) string { diff --git a/internal/hackernews/printer.go b/internal/hackernews/printer.go index 0eb4ab4..9004f65 100644 --- a/internal/hackernews/printer.go +++ b/internal/hackernews/printer.go @@ -31,7 +31,7 @@ func (o Op) String() (ret string) { } ret += fmt.Sprintf( "\n%s(%d) - %s - %d Comments\n", - o.user, + format.AuthorStyle.Render(o.user), o.score, humanize.Time(o.date), o.ncomments, @@ -46,10 +46,16 @@ func (c Comment) String() (ret string) { if c.indent > 0 { arrow = ">> " } + + author := c.user + if c.user == c.thread.op.user { + author = format.AuthorStyle.Render(c.user) + } + if c.thread.ShowDate { - ret += strings.Repeat(" ", indent) + arrow + c.user + " - " + humanize.Time(c.date) + ret += strings.Repeat(" ", indent) + arrow + author + " - " + humanize.Time(c.date) } else { - ret += strings.Repeat(" ", indent) + arrow + c.user + ret += strings.Repeat(" ", indent) + arrow + author } ret += "\n" return diff --git a/internal/reddit/format.go b/internal/reddit/format.go index cd23512..dbb5bf5 100644 --- a/internal/reddit/format.go +++ b/internal/reddit/format.go @@ -7,6 +7,7 @@ import ( "time" markdown "github.com/MichaelMure/go-term-markdown" + "github.com/azimut/cli-view/internal/format" md "github.com/gomarkdown/markdown" "github.com/gomarkdown/markdown/parser" @@ -14,8 +15,6 @@ import ( "github.com/fatih/color" ) -const AuthorColor = color.FgYellow - var reMarkdownLink = regexp.MustCompile(`\[([^\]]+)\]\(([^\)]+)\)`) var reHTTPLink = regexp.MustCompile(`[^\[^\(^m]http[s]?://[^\s^\[^\(^\[]+`) @@ -36,7 +35,7 @@ func (op Op) String() (ret string) { ) ret += "\n" ret += fmt.Sprintf("%s(%d) - %s - %d Comment(s)\n\n\n", - color.New(AuthorColor).Sprint(op.author), + format.AuthorStyle.Render(op.author), op.upvotes, relativeFromUnix(op.createdUTC), op.nComments) @@ -52,9 +51,10 @@ func (comment Comment) String() (ret string) { maxWidth, commentLeftPadding, ) + author := comment.author if comment.author == comment.thread.op.author { - author = color.New(AuthorColor).Sprint(comment.author) + author = format.AuthorStyle.Render(comment.author) } ret += strings.Repeat(" ", int(comment.depth)*leftPadding) diff --git a/internal/vichan/format.go b/internal/vichan/format.go index a76bc4d..74e3213 100644 --- a/internal/vichan/format.go +++ b/internal/vichan/format.go @@ -40,10 +40,10 @@ func (op Op) String() (ret string) { ) ret += "\n\n" } - ret += " " + humanize.Time(op.createdAt) if op.thread.ShowAuthor { - ret += " by " + op.author + ret += format.AuthorStyle.Render(op.author) } + ret += " " + humanize.Time(op.createdAt) ret += "\n\n\n" return } @@ -64,7 +64,12 @@ func (comment Comment) String() (ret string) { ret += " " + humanize.Time(comment.createdAt) } if comment.thread.ShowAuthor { - ret += " " + comment.author + ret += " " + if comment.author == comment.thread.op.author { + ret += format.AuthorStyle.Render(comment.author) + } else { + ret += comment.author + } } if comment.thread.ShowId { ret += " " + fmt.Sprintf("%d", comment.id)