diff --git a/src/views/mastoapi.nim b/src/views/mastoapi.nim index faec186..5abe66f 100644 --- a/src/views/mastoapi.nim +++ b/src/views/mastoapi.nim @@ -1,10 +1,26 @@ # SPDX-License-Identifier: AGPL-3.0-only -import strutils, strformat, options, json, sequtils, times +import strutils, strformat, options, json, sequtils, times, math import ".."/[types, formatters, utils] proc formatTweetForMastoAPI*(tweet: Tweet, cfg: Config, prefs: Prefs): string = var content = replaceUrls(tweet.text, prefs) + if tweet.poll.isSome(): + let poll = get(tweet.poll) + content &= "\n
"
+ for i in 0 ..< poll.options.len:
+ let
+ leader = if poll.leader == i: " leader" else: ""
+ val = poll.values[i]
+ perc = if val > 0: val / poll.votes * 100 else: 0
+ percStr = (&"{perc:>3.0f}").strip(chars={'.'}) & '%'
+ barLen = round((perc / 100) * 32).int
+ bar = repeat("█", barLen)
+ notBar = repeat(" ", 32 - barLen)
+ content &= &"{poll.options[i]} ({val}, {percStr})\n{bar}{notBar}\n"
+
+ content &= &"\n{insertSep($poll.votes, ',')} votes • {poll.status}"
+
if tweet.quote.isSome():
let
quote = get(tweet.quote)