From f223e0417c96e8e545c1266a76e4f7983875ca03 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Sat, 17 Aug 2024 03:49:17 +0100 Subject: [PATCH] fix: view the summary of a status View the status' summary/spoiler/content warning text if it exists. --- internal/executor/executors.go | 2 +- internal/model/status.go | 4 ++-- internal/printer/printer.go | 10 ++++++++++ internal/printer/status.go | 13 +++++++++++++ schema/enbas_cli_schema.json | 2 +- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/internal/executor/executors.go b/internal/executor/executors.go index bbcd689..8e0cbb8 100644 --- a/internal/executor/executors.go +++ b/internal/executor/executors.go @@ -184,7 +184,7 @@ func NewCreateExecutor( exe.BoolVar(&exe.pollHidesVoteCounts, "poll-hides-vote-counts", false, "Set to true to hide the vote count until the poll is closed") exe.Var(&exe.pollOptions, "poll-option", "A poll option. Use this multiple times to set multiple options") exe.Var(&exe.sensitive, "sensitive", "Set to true if the status should be marked as sensitive") - exe.StringVar(&exe.spoilerText, "spoiler-text", "", "The text to display as the status' warning or subject") + exe.StringVar(&exe.spoilerText, "spoiler-text", "", "The subject, summary or content warning for the status") exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") exe.StringVar(&exe.visibility, "visibility", "", "The visibility of the posted status") diff --git a/internal/model/status.go b/internal/model/status.go index 057e64a..4939947 100644 --- a/internal/model/status.go +++ b/internal/model/status.go @@ -28,7 +28,7 @@ type Status struct { ReblogsCount int `json:"reblogs_count"` RepliesCount int `json:"replies_count"` Sensitive bool `json:"sensitive"` - SpolierText string `json:"spoiler_text"` + SpoilerText string `json:"spoiler_text"` Tags []Tag `json:"tags"` Text string `json:"text"` URI string `json:"uri"` @@ -83,7 +83,7 @@ type StatusReblogged struct { RebloggsCount int `json:"reblogs_count"` RepliesCount int `json:"replies_count"` Sensitive bool `json:"sensitive"` - SpolierText string `json:"spoiler_text"` + SpoilerText string `json:"spoiler_text"` Tags []Tag `json:"tags"` Text string `json:"text"` URI string `json:"uri"` diff --git a/internal/printer/printer.go b/internal/printer/printer.go index 0ec5951..c2eadc0 100644 --- a/internal/printer/printer.go +++ b/internal/printer/printer.go @@ -27,6 +27,7 @@ const ( type theme struct { reset string + bold string boldblue string boldmagenta string green string @@ -53,6 +54,7 @@ func NewPrinter( ) *Printer { theme := theme{ reset: "\033[0m", + bold: "\033[1m", boldblue: "\033[34;1m", boldmagenta: "\033[35;1m", green: "\033[32m", @@ -115,6 +117,14 @@ func (p Printer) fieldFormat(text string) string { return p.theme.green + text + p.theme.reset } +func (p Printer) bold(text string) string { + if p.noColor { + return text + } + + return p.theme.bold + text + p.theme.reset +} + func (p Printer) fullDisplayNameFormat(displayName, acct string) string { // use this pattern to remove all emoji strings pattern := regexp.MustCompile(`\s:[A-Za-z0-9_]*:`) diff --git a/internal/printer/status.go b/internal/printer/status.go index d083e21..8e7a2d9 100644 --- a/internal/printer/status.go +++ b/internal/printer/status.go @@ -18,6 +18,12 @@ func (p Printer) PrintStatus(status model.Status, userAccountID string) { builder.WriteString("\n\n" + p.headerFormat("STATUS ID:")) builder.WriteString("\n" + status.ID) + // The subject, summary of content warning of the status + if status.SpoilerText != "" { + builder.WriteString("\n\n" + p.headerFormat("SUMMARY:")) + builder.WriteString("\n" + status.SpoilerText) + } + // The content of the status. builder.WriteString("\n\n" + p.headerFormat("CONTENT:")) builder.WriteString(p.convertHTMLToText(status.Content, true)) @@ -97,6 +103,7 @@ func (p Printer) statusList(list model.StatusList, userAccountID string) string content := status.Content poll := status.Poll mediaAttachments := status.MediaAttachments + summary := status.SpoilerText switch { case status.Reblog != nil: @@ -115,6 +122,8 @@ func (p Printer) statusList(list model.StatusList, userAccountID string) string content = status.Reblog.Content poll = status.Reblog.Poll mediaAttachments = status.Reblog.MediaAttachments + summary = status.Reblog.SpoilerText + case status.InReplyToID != "": builder.WriteString("\n" + p.wrapLines( p.fullDisplayNameFormat(status.Account.DisplayName, status.Account.Acct)+ @@ -127,6 +136,10 @@ func (p Printer) statusList(list model.StatusList, userAccountID string) string builder.WriteString("\n" + p.fullDisplayNameFormat(status.Account.DisplayName, status.Account.Acct) + " posted:") } + if summary != "" { + builder.WriteString("\n\n" + p.bold(p.wrapLines(summary, 0))) + } + builder.WriteString("\n" + p.convertHTMLToText(content, true)) if poll != nil { diff --git a/schema/enbas_cli_schema.json b/schema/enbas_cli_schema.json index a99d290..2294609 100644 --- a/schema/enbas_cli_schema.json +++ b/schema/enbas_cli_schema.json @@ -174,7 +174,7 @@ }, "spoiler-text": { "type": "string", - "description": "The text to display as the status' warning or subject" + "description": "The subject, summary or content warning for the status" }, "status-id": { "type": "string",