@@ -1078,12 +1078,39 @@ def __init__(
10781078
10791079
10801080class 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
10821097 width , _ = controller .maximum_popup_dimensions ()
10831098 widget = [urwid .Text (content )]
10841099
10851100 super ().__init__ (controller , widget , "MSG_INFO" , width , title )
10861101
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+
10871114
10881115class AboutView (PopUpView ):
10891116 def __init__ (
@@ -1703,14 +1730,9 @@ def __init__(
17031730 popup_width = max (popup_width , topic_link_width )
17041731
17051732 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+ )
17141736
17151737 # slice_index = Number of labels before message links + 1 newline
17161738 # + 1 'Spoilers' category label.
@@ -1751,6 +1773,39 @@ def create_link_buttons(
17511773
17521774 return link_widgets , link_width
17531775
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+
17541809 def keypress (self , size : urwid_Size , key : str ) -> str :
17551810 if is_command_key ("EDIT_HISTORY" , key ) and self .show_edit_history_label :
17561811 self .controller .show_edit_history (
0 commit comments