@@ -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 , "ENTER" , width , title )
1086
1101
1102
+ def keypress (self , size : urwid_Size , key : str ) -> str :
1103
+ if is_command_key ("GO_BACK" , 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__ (
@@ -1687,14 +1714,9 @@ def __init__(
1687
1714
popup_width = max (popup_width , topic_link_width )
1688
1715
1689
1716
if spoilers :
1690
- spoiler_buttons = []
1691
- spoiler_width = 0
1692
- for index , (header_len , header , content ) in enumerate (spoilers ):
1693
- spoiler_width = max (header_len , spoiler_width )
1694
- display_attr = None if index % 2 else "popup_contrast"
1695
- spoiler_buttons .append (
1696
- SpoilerButton (controller , header_len , header , content , display_attr )
1697
- )
1717
+ spoiler_buttons , spoiler_width = self .create_spoiler_buttons (
1718
+ controller , spoilers
1719
+ )
1698
1720
1699
1721
# slice_index = Number of labels before message links + 1 newline
1700
1722
# + 1 'Spoilers' category label.
@@ -1735,6 +1757,39 @@ def create_link_buttons(
1735
1757
1736
1758
return link_widgets , link_width
1737
1759
1760
+ def create_spoiler_buttons (
1761
+ self , controller : Any , spoilers : List [Tuple [int , List [Any ], List [Any ]]]
1762
+ ) -> Tuple [List [SpoilerButton ], int ]:
1763
+ spoiler_buttons = []
1764
+ spoiler_width = 0
1765
+
1766
+ for index , (header_len , header , content ) in enumerate (spoilers ):
1767
+ spoiler_width = max (header_len , spoiler_width )
1768
+
1769
+ display_attr = None if index % 2 else "popup_contrast"
1770
+
1771
+ processed_header = [f"{ index + 1 } : " ] + header
1772
+ header_len = sum (
1773
+ len (part [1 ]) if isinstance (part , tuple ) else len (part )
1774
+ for part in processed_header
1775
+ )
1776
+
1777
+ spoiler_buttons .append (
1778
+ SpoilerButton (
1779
+ controller ,
1780
+ header_len ,
1781
+ processed_header ,
1782
+ header + ["\n \n " ] + content ,
1783
+ self .msg ,
1784
+ self .topic_links ,
1785
+ self .message_links ,
1786
+ self .time_mentions ,
1787
+ self .spoilers ,
1788
+ display_attr ,
1789
+ )
1790
+ )
1791
+ return spoiler_buttons , spoiler_width
1792
+
1738
1793
def keypress (self , size : urwid_Size , key : str ) -> str :
1739
1794
if is_command_key ("EDIT_HISTORY" , key ) and self .show_edit_history_label :
1740
1795
self .controller .show_edit_history (
0 commit comments