From c8892a653591f62e90f3e2b740b24dc3fd623e00 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Thu, 27 Jun 2024 09:10:18 +0100 Subject: [PATCH] feat: show user's actions on a status Show whether the user has liked, boosted or bookmarked a status within both the status and status list views. --- internal/printer/account.go | 4 ++-- internal/printer/list.go | 4 ++-- internal/printer/poll.go | 4 ++-- internal/printer/printer.go | 46 +++++++++++++++++++------------------ internal/printer/status.go | 27 +++++++++++++++++++++- 5 files changed, 56 insertions(+), 29 deletions(-) diff --git a/internal/printer/account.go b/internal/printer/account.go index 4cb83a6..cbb6496 100644 --- a/internal/printer/account.go +++ b/internal/printer/account.go @@ -125,11 +125,11 @@ func (p Printer) PrintAccountList(list model.AccountList) { if list.Type == model.AccountListBlockedAccount { for ind := range list.Accounts { - builder.WriteString("\n" + p.bullet + " " + list.Accounts[ind].Acct + " (" + list.Accounts[ind].ID + ")") + builder.WriteString("\n" + symbolBullet + " " + list.Accounts[ind].Acct + " (" + list.Accounts[ind].ID + ")") } } else { for ind := range list.Accounts { - builder.WriteString("\n" + p.bullet + " " + p.fullDisplayNameFormat(list.Accounts[ind].DisplayName, list.Accounts[ind].Acct)) + builder.WriteString("\n" + symbolBullet + " " + p.fullDisplayNameFormat(list.Accounts[ind].DisplayName, list.Accounts[ind].Acct)) } } diff --git a/internal/printer/list.go b/internal/printer/list.go index bd16734..8695a90 100644 --- a/internal/printer/list.go +++ b/internal/printer/list.go @@ -23,7 +23,7 @@ func (p Printer) PrintList(list model.List) { if len(list.Accounts) > 0 { for acct, name := range list.Accounts { - builder.WriteString("\n" + p.bullet + " " + p.fullDisplayNameFormat(name, acct)) + builder.WriteString("\n" + symbolBullet + " " + p.fullDisplayNameFormat(name, acct)) } } else { builder.WriteString("\n" + "None") @@ -40,7 +40,7 @@ func (p Printer) PrintLists(lists []model.List) { builder.WriteString("\n" + p.headerFormat("LISTS")) for i := range lists { - builder.WriteString("\n" + p.bullet + " " + lists[i].Title + " (" + lists[i].ID + ")") + builder.WriteString("\n" + symbolBullet + " " + lists[i].Title + " (" + lists[i].ID + ")") } builder.WriteString("\n") diff --git a/internal/printer/poll.go b/internal/printer/poll.go index b8a34e6..cd24da1 100644 --- a/internal/printer/poll.go +++ b/internal/printer/poll.go @@ -85,10 +85,10 @@ func (p Printer) pollMeter(votage float64) string { } } - meter := "\n" + voteBlockColor + strings.Repeat(p.pollMeterSymbol, numVoteBlocks) + p.theme.reset + meter := "\n" + voteBlockColor + strings.Repeat(symbolPollMeter, numVoteBlocks) + p.theme.reset if !p.noColor { - meter += backgroundBlockColor + strings.Repeat(p.pollMeterSymbol, numBackgroundBlocks) + p.theme.reset + meter += backgroundBlockColor + strings.Repeat(symbolPollMeter, numBackgroundBlocks) + p.theme.reset } return meter diff --git a/internal/printer/printer.go b/internal/printer/printer.go index 2411558..a63fc9f 100644 --- a/internal/printer/printer.go +++ b/internal/printer/printer.go @@ -13,8 +13,20 @@ import ( ) const ( - minTerminalWidth = 40 - noMediaDescription = "This media attachment has no description." + minTerminalWidth = 40 + noMediaDescription = "This media attachment has no description." + symbolBullet = "\u2022" + symbolPollMeter = "\u2501" + symbolSuccess = "\u2714" + symbolFailure = "\u2717" + symbolImage = "\uf03e" + symbolLiked = "\uf51f" + symbolNotLiked = "\uf41e" + symbolBookmarked = "\uf47a" + symbolNotBookmarked = "\uf461" + symbolBoosted = "\u2BAD" + dateFormat = "02 Jan 2006" + dateTimeFormat = "02 Jan 2006, 15:04 (MST)" ) type theme struct { @@ -26,6 +38,8 @@ type theme struct { grey string red string boldred string + yellow string + boldyellow string } type Printer struct { @@ -34,13 +48,6 @@ type Printer struct { maxTerminalWidth int pager string statusSeparator string - bullet string - pollMeterSymbol string - successSymbol string - failureSymbol string - dateFormat string - dateTimeFormat string - imageIcon string } func NewPrinter( @@ -57,6 +64,8 @@ func NewPrinter( grey: "\033[90m", red: "\033[31m", boldred: "\033[31;1m", + yellow: "\033[33m", + boldyellow: "\033[33;1m", } if maxTerminalWidth < minTerminalWidth { @@ -69,29 +78,22 @@ func NewPrinter( maxTerminalWidth: maxTerminalWidth, pager: pager, statusSeparator: strings.Repeat("\u2501", maxTerminalWidth), - bullet: "\u2022", - pollMeterSymbol: "\u2501", - successSymbol: "\u2714", - failureSymbol: "\u2717", - dateFormat: "02 Jan 2006", - dateTimeFormat: "02 Jan 2006, 15:04 (MST)", - imageIcon: "\uf03e", } } func (p Printer) PrintSuccess(text string) { - success := p.theme.boldgreen + p.successSymbol + p.theme.reset + success := p.theme.boldgreen + symbolSuccess + p.theme.reset if p.noColor { - success = p.successSymbol + success = symbolSuccess } printToStdout(success + " " + text + "\n") } func (p Printer) PrintFailure(text string) { - failure := p.theme.boldred + p.failureSymbol + p.theme.reset + failure := p.theme.boldred + symbolFailure + p.theme.reset if p.noColor { - failure = p.failureSymbol + failure = symbolFailure } printToStderr(failure + " " + text + "\n") @@ -135,11 +137,11 @@ func (p Printer) fullDisplayNameFormat(displayName, acct string) string { } func (p Printer) formatDate(date time.Time) string { - return date.Local().Format(p.dateFormat) + return date.Local().Format(dateFormat) } func (p Printer) formatDateTime(date time.Time) string { - return date.Local().Format(p.dateTimeFormat) + return date.Local().Format(dateTimeFormat) } func (p Printer) print(text string) { diff --git a/internal/printer/status.go b/internal/printer/status.go index fe74971..f993a58 100644 --- a/internal/printer/status.go +++ b/internal/printer/status.go @@ -59,6 +59,12 @@ func (p Printer) PrintStatus(status model.Status) { builder.WriteString("\n" + p.fieldFormat("Likes: ") + strconv.Itoa(status.FavouritesCount)) builder.WriteString("\n" + p.fieldFormat("Replies: ") + strconv.Itoa(status.RepliesCount)) + // The user's actions on the status + builder.WriteString("\n\n" + p.headerFormat("YOUR ACTIONS:")) + builder.WriteString("\n" + p.fieldFormat("Boosted: ") + strconv.FormatBool(status.Reblogged)) + builder.WriteString("\n" + p.fieldFormat("Liked: ") + strconv.FormatBool(status.Favourited)) + builder.WriteString("\n" + p.fieldFormat("Bookmarked: ") + strconv.FormatBool(status.Bookmarked)) + // Status visibility builder.WriteString("\n\n" + p.headerFormat("VISIBILITY:")) builder.WriteString("\n" + status.Visibility.String()) @@ -104,7 +110,7 @@ func (p Printer) PrintStatusList(list model.StatusList) { } for _, media := range mediaAttachments { - builder.WriteString("\n\n" + p.imageIcon + " Media attachment: " + media.ID) + builder.WriteString("\n\n" + symbolImage + " Media attachment: " + media.ID) builder.WriteString("\n Media type: " + media.Type + "\n ") description := media.Description @@ -115,6 +121,25 @@ func (p Printer) PrintStatusList(list model.StatusList) { builder.WriteString(utilities.WrapLines(description, "\n ", p.maxTerminalWidth-3)) } + boosted := symbolBoosted + if status.Reblogged { + boosted = p.theme.boldyellow + symbolBoosted + p.theme.reset + } + + liked := symbolNotLiked + if status.Favourited { + liked = p.theme.boldyellow + symbolLiked + p.theme.reset + } + + bookmarked := symbolNotBookmarked + if status.Bookmarked { + bookmarked = p.theme.boldyellow + symbolBookmarked + p.theme.reset + } + + builder.WriteString("\n\n" + boosted + " " + p.fieldFormat("boosted:") + " " + strconv.FormatBool(status.Bookmarked)) + builder.WriteString("\n" + liked + " " + p.fieldFormat("liked:") + " " + strconv.FormatBool(status.Favourited)) + builder.WriteString("\n" + bookmarked + " " + p.fieldFormat("bookmarked:") + " " + strconv.FormatBool(status.Bookmarked)) + builder.WriteString( "\n\n" + p.fieldFormat("Status ID:") + " " + statusID + "\t" +