@@ -1078,12 +1078,39 @@ def __init__(
1078
1078
1079
1079
1080
1080
class SpoilerView (PopUpView ):
1081
- def __init__ (self , controller : Any , title : str , content : str ) -> None :
1081
+ def __init__ (
1082
+ self ,
1083
+ controller : Any ,
1084
+ title : str ,
1085
+ content : str ,
1086
+ message : Message ,
1087
+ topic_links : Dict [str , Tuple [str , int , bool ]],
1088
+ message_links : Dict [str , Tuple [str , int , bool ]],
1089
+ time_mentions : List [Tuple [str , str ]],
1090
+ spoilers : List [Tuple [int , List [Any ], List [Any ]]],
1091
+ ) -> None :
1092
+ self .message = message
1093
+ self .topic_links = topic_links
1094
+ self .message_links = message_links
1095
+ self .time_mentions = time_mentions
1096
+ self .spoilers = spoilers
1082
1097
width , _ = controller .maximum_popup_dimensions ()
1083
1098
widget = [urwid .Text (content )]
1084
1099
1085
1100
super ().__init__ (controller , widget , "MSG_INFO" , width , title )
1086
1101
1102
+ def keypress (self , size : urwid_Size , key : str ) -> str :
1103
+ if is_command_key ("EXIT_POPUP" , key ) or is_command_key ("ACTIVATE_BUTTON" , key ):
1104
+ self .controller .show_msg_info (
1105
+ msg = self .message ,
1106
+ topic_links = self .topic_links ,
1107
+ message_links = self .message_links ,
1108
+ time_mentions = self .time_mentions ,
1109
+ spoilers = self .spoilers ,
1110
+ )
1111
+ return key
1112
+ return super ().keypress (size , key )
1113
+
1087
1114
1088
1115
class AboutView (PopUpView ):
1089
1116
def __init__ (
@@ -1703,14 +1730,9 @@ def __init__(
1703
1730
popup_width = max (popup_width , topic_link_width )
1704
1731
1705
1732
if spoilers :
1706
- spoiler_buttons = []
1707
- spoiler_width = 0
1708
- for index , (header_len , header , content ) in enumerate (spoilers ):
1709
- spoiler_width = max (header_len , spoiler_width )
1710
- display_attr = None if index % 2 else "popup_contrast"
1711
- spoiler_buttons .append (
1712
- SpoilerButton (controller , header_len , header , content , display_attr )
1713
- )
1733
+ spoiler_buttons , spoiler_width = self .create_spoiler_buttons (
1734
+ controller , spoilers
1735
+ )
1714
1736
1715
1737
# slice_index = Number of labels before message links + 1 newline
1716
1738
# + 1 'Spoilers' category label.
@@ -1751,6 +1773,39 @@ def create_link_buttons(
1751
1773
1752
1774
return link_widgets , link_width
1753
1775
1776
+ def create_spoiler_buttons (
1777
+ self , controller : Any , spoilers : List [Tuple [int , List [Any ], List [Any ]]]
1778
+ ) -> Tuple [List [SpoilerButton ], int ]:
1779
+ spoiler_buttons = []
1780
+ spoiler_width = 0
1781
+
1782
+ for index , (header_len , header , content ) in enumerate (spoilers ):
1783
+ spoiler_width = max (header_len , spoiler_width )
1784
+
1785
+ display_attr = None if index % 2 else "popup_contrast"
1786
+
1787
+ processed_header = [f"{ index + 1 } : " ] + header
1788
+ processed_header_len = sum (
1789
+ len (part [1 ]) if isinstance (part , tuple ) else len (part )
1790
+ for part in processed_header
1791
+ )
1792
+
1793
+ spoiler_buttons .append (
1794
+ SpoilerButton (
1795
+ controller ,
1796
+ processed_header_len ,
1797
+ processed_header ,
1798
+ header + ["\n \n " ] + content ,
1799
+ self .msg ,
1800
+ self .topic_links ,
1801
+ self .message_links ,
1802
+ self .time_mentions ,
1803
+ self .spoilers ,
1804
+ display_attr ,
1805
+ )
1806
+ )
1807
+ return spoiler_buttons , spoiler_width
1808
+
1754
1809
def keypress (self , size : urwid_Size , key : str ) -> str :
1755
1810
if is_command_key ("EDIT_HISTORY" , key ) and self .show_edit_history_label :
1756
1811
self .controller .show_edit_history (
0 commit comments