Skip to content

Commit

Permalink
Merge pull request ihabunek#450 from lexiwinter/autoopen-cw
Browse files Browse the repository at this point in the history
add an option to automatically expand content warnings
  • Loading branch information
ihabunek authored Jan 4, 2024
2 parents b4cbeee + 1ed129f commit fda498d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion toot/cli/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@
type=click.Choice(VISIBILITY_CHOICES),
help="Default visibility when posting new toots; overrides the server-side preference"
)
@click.option(
"-S", "--always-show-sensitive",
is_flag=True,
help="Expand toots with content warnings automatically"
)
@pass_context
def tui(
ctx: Context,
colors: Optional[int],
media_viewer: Optional[str],
always_show_sensitive: bool,
relative_datetimes: bool,
default_visibility: Optional[str]
):
Expand All @@ -45,7 +51,8 @@ def tui(
colors=colors,
media_viewer=media_viewer,
relative_datetimes=relative_datetimes,
default_visibility=default_visibility
default_visibility=default_visibility,
always_show_sensitive=always_show_sensitive,
)
tui = TUI.create(ctx.app, ctx.user, options)
tui.run()
1 change: 1 addition & 0 deletions toot/tui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
class TuiOptions(NamedTuple):
colors: int
media_viewer: Optional[str]
always_show_sensitive: bool
relative_datetimes: bool
default_visibility: Optional[bool]

Expand Down
6 changes: 5 additions & 1 deletion toot/tui/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ class StatusDetails(urwid.Pile):
def __init__(self, timeline: Timeline, status: Optional[Status]):
self.status = status
self.followed_accounts = timeline.tui.followed_accounts
self.options = timeline.tui.options

reblogged_by = status.author if status and status.reblog else None
widget_list = list(self.content_generator(status.original, reblogged_by)
Expand All @@ -343,9 +344,12 @@ def content_generator(self, status, reblogged_by):
yield ("pack", urwid.Divider())

# Show content warning
if status.data["spoiler_text"] and not status.show_sensitive:
if status.data["spoiler_text"] and not status.show_sensitive and not self.options.always_show_sensitive:
yield ("pack", urwid.Text(("content_warning", "Marked as sensitive. Press S to view.")))
else:
if status.data["spoiler_text"]:
yield ("pack", urwid.Text(("content_warning", "Marked as sensitive.")))

content = status.original.translation if status.original.show_translation else status.data["content"]
widgetlist = html_to_widgets(content)

Expand Down

0 comments on commit fda498d

Please sign in to comment.