fix: view the summary of a status
All checks were successful
REUSE Compliance Check / check (push) Successful in 6s

View the status' summary/spoiler/content warning text if it exists.
This commit is contained in:
Dan Anglin 2024-08-17 03:49:17 +01:00
parent ee13dcde00
commit f223e0417c
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
5 changed files with 27 additions and 4 deletions

View file

@ -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")

View file

@ -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"`

View file

@ -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_]*:`)

View file

@ -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 {

View file

@ -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",