3434
3535LayoutDefinition = "dict[str, Any]"
3636
37- try :
38- import uvloop
39- except ImportError :
40- pass
41- else :
42- uvloop .install ()
37+ # try:
38+ # import uvloop
39+ # except ImportError:
40+ # pass
41+ # else:
42+ # uvloop.install()
4343
4444
4545class ShutdownError (Exception ):
@@ -106,6 +106,7 @@ async def _process_messages(self) -> None:
106106 await self .add (self .view )
107107
108108 await self .post_message (events .Startup (sender = self ))
109+
109110 try :
110111 driver .start_application_mode ()
111112 except Exception :
@@ -115,23 +116,26 @@ async def _process_messages(self) -> None:
115116 await super ().process_messages ()
116117 finally :
117118 try :
118- driver .stop_application_mode ()
119- finally :
120- loop .remove_signal_handler (signal .SIGINT )
119+ if self .children :
121120
122- if self .children :
121+ async def close_all () -> None :
122+ for child in self .children :
123+ await child .close_messages ()
124+ await asyncio .gather (* (child .task for child in self .children ))
123125
124- async def close_all () -> None :
125- for child in self .children :
126- await child .close_messages ()
127- await asyncio .gather (* (child .task for child in self .children ))
126+ try :
127+ await asyncio .wait_for (close_all (), timeout = 5 )
128+ except asyncio .TimeoutError as error :
129+ raise ShutdownError (
130+ "Timeout closing messages pump(s)"
131+ ) from None
128132
129- try :
130- await asyncio . wait_for ( close_all (), timeout = 5 )
131- except asyncio . TimeoutError as error :
132- raise ShutdownError ( "Timeout closing messages pump(s)" ) from None
133-
134- self . children . clear ( )
133+ self . children . clear ()
134+ finally :
135+ try :
136+ driver . stop_application_mode ()
137+ finally :
138+ loop . remove_signal_handler ( signal . SIGINT )
135139
136140 async def add (self , child : MessagePump ) -> None :
137141 self .children .add (child )
@@ -222,31 +226,42 @@ async def action_bang(self) -> None:
222226 from logging import FileHandler
223227
224228 from .widgets .header import Header
229+ from .widgets .footer import Footer
225230 from .widgets .window import Window
226231 from .widgets .placeholder import Placeholder
227- from .scrollbar import ScrollBar
228232
229233 from rich .markdown import Markdown
230234
235+ import os
236+
231237 logging .basicConfig (
232238 level = "NOTSET" ,
233239 format = "%(message)s" ,
234240 datefmt = "[%X]" ,
235241 handlers = [FileHandler ("richtui.log" )],
236242 )
237243
238- with open ("richreadme.md" , "rt" ) as fh :
239- readme = Markdown (fh .read (), hyperlinks = True , code_theme = "fruity" )
240-
241- from rich import print
242-
243244 class MyApp (App ):
244245
245246 KEYS = {"q" : "quit" , "x" : "bang" , "ctrl+c" : "quit" , "b" : "view.toggle('left')" }
246247
247248 async def on_startup (self , event : events .Startup ) -> None :
249+ footer = Footer ()
250+ footer .add_key ("b" , "Toggle sidebar" )
251+ footer .add_key ("q" , "Quit" )
252+
253+ readme_path = os .path .join (
254+ os .path .dirname (os .path .abspath (__file__ )), "richreadme.md"
255+ )
256+
257+ with open (readme_path , "rt" ) as fh :
258+ readme = Markdown (fh .read (), hyperlinks = True , code_theme = "fruity" )
259+
248260 await self .view .mount_all (
249- header = Header (self .title ), left = ScrollBar (), body = Window (readme )
261+ header = Header (self .title ),
262+ left = Placeholder (),
263+ body = Window (readme ),
264+ footer = footer ,
250265 )
251266
252267 MyApp .run ()
0 commit comments