Skip to content

Commit

Permalink
style: common style for author name highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Apr 28, 2023
1 parent 3bb015e commit a66abcc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
14 changes: 6 additions & 8 deletions internal/discourse/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand All @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions internal/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 9 additions & 3 deletions internal/hackernews/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/reddit/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ 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"

"github.com/dustin/go-humanize"
"github.com/fatih/color"
)

const AuthorColor = color.FgYellow

var reMarkdownLink = regexp.MustCompile(`\[([^\]]+)\]\(([^\)]+)\)`)
var reHTTPLink = regexp.MustCompile(`[^\[^\(^m]http[s]?://[^\s^\[^\(^\[]+`)

Expand All @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions internal/vichan/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down

0 comments on commit a66abcc

Please sign in to comment.