~ihabunek/toot-discuss

Display polls in command line status output, also display your own votes in toot tui poll displays v1 PROPOSED

Daniel Schwarz: 1
 Display polls in command line status output, also display your own votes in toot tui poll displays

 2 files changed, 34 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~ihabunek/toot-discuss/patches/37177/mbox | git am -3
Learn more about email & git

[PATCH] Display polls in command line status output, also display your own votes in toot tui poll displays Export this patch

These are read only enhancements to the poll display functionality.

diff --git a/toot/output.py b/toot/output.py
index 5804bb5..daee4c6 100644
--- a/toot/output.py
+++ b/toot/output.py
@@ -168,6 +168,7 @@ def print_status(status, width):
     content = reblog['content'] if reblog else status['content']
     media_attachments = reblog['media_attachments'] if reblog else status['media_attachments']
     in_reply_to = status['in_reply_to_id']
    poll = reblog['poll'] if reblog else status['poll']

     time = parse_datetime(status['created_at'])
     time = time.strftime('%Y-%m-%d %H:%M %Z')
@@ -199,6 +200,31 @@ def print_status(status, width):
             for line in wc_wrap(url, width):
                 print_out(line)

    if poll:
        print_out("")
        for idx, option in enumerate(poll["options"]):
            perc = (round(100 * option["votes_count"] / poll["votes_count"])
                if poll["votes_count"] else 0)

            if poll["voted"] and poll["own_votes"] and idx in poll["own_votes"]:
                voted_for = " <yellow>✓<yellow>"
            else:
                voted_for = ""

            print_out(option["title"] + " - {}%".format(perc) + voted_for)

        poll_footer = "Poll · {} votes".format(poll["votes_count"])

        if poll["expired"]:
            poll_footer += " · Closed"

        if poll["expires_at"]:
            expires_at = parse_datetime(poll["expires_at"]).strftime("%Y-%m-%d %H:%M")
            poll_footer += " · Closes on {}".format(expires_at)

        print_out("\n{}".format(poll_footer))


     print_out("\n{}{}{}".format(
         "ID <yellow>{}</yellow>  ".format(status['id']),
         "↲ In reply to <yellow>{}</yellow>  ".format(in_reply_to) if in_reply_to else "",
diff --git a/toot/tui/timeline.py b/toot/tui/timeline.py
index 8faafd4..faf4131 100644
--- a/toot/tui/timeline.py
+++ b/toot/tui/timeline.py
@@ -328,10 +328,16 @@ class StatusDetails(urwid.Pile):
         yield urwid.Text(("link", card["url"]))

     def poll_generator(self, poll):
        for option in poll["options"]:
        for idx, option in enumerate(poll["options"]):
             perc = (round(100 * option["votes_count"] / poll["votes_count"])
                 if poll["votes_count"] else 0)
            yield urwid.Text(option["title"])

            if poll["voted"] and poll["own_votes"] and idx in poll["own_votes"]:
                voted_for = " ✓"
            else:
                voted_for = ""

            yield urwid.Text(option["title"] + voted_for)
             yield urwid.ProgressBar("", "poll_bar", perc)

         status = "Poll · {} votes".format(poll["votes_count"])
Thanks, merged.

-- Ivan