You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using textual to build a CLI application where the user doesn't spend the entire time in the TUI rendered by textual, but instead the TUI is only open for one step in a larger sequence of steps. When you run the application from your console, you see a few normal python print() outputs, and then a TUI fills the entire terminal where you can enter some data, and afterwards the TUI closes and the "normal" non-TUI interaction continues.
This means that I'm using app.exit not as a means of exiting the entire program, but just to get out of the TUI mode so that the rest of the application can continue. it seems like the call to app.exit usually takes just over 200ms, which might be fine in the use case where you're anyway exiting the entire program, but for my use case it does feel a bit sluggish.
Here's my code that I used to measure the delay:
importtimefromtypingimportoverridefromtextual.appimportApp, ComposeResultfromtextual.widgetsimportButton, Labeltimestamp: float|None=NoneclassMyApp(App[bool]):
@overridedefcompose(self) ->ComposeResult:
yieldLabel("Hello there")
yieldButton("Continue", action="app.continue")
defaction_continue(self) ->None:
globaltimestamptimestamp=time.time()
# return True to indicate that we want to keep running# the further steps as opposed to exiting completelyself.app.exit(True)
if__name__=="__main__":
# earlier steps happen here# ...app=MyApp()
user_wants_to_continue=app.run()
iftimestampisnotNone:
print(f"{time.time() -timestamp:.4}s")
ifuser_wants_to_continue:
# further steps happen here# ...pass
I have tried this with both textual run and textual run --dev. The dev mode seems to add an additional 20ms which I'm not concerned about. My main issue is that the non-dev mode usually prints times like 0.2046s.
To me this feels suspiciously close to always 200ms, so I wonder if there's like an event loop or something like that in the background which could be sped up.
To test if the inline mode behaves differently I just ran the calculator example unmodified, which means I don't see exact time measurements but ctrl-q does feel like it might have a similar delay.
My questions are:
Is there a different method that I could use to switch back and forth between normal stdin/stdout mode and fullscreen terminal mode, without having to create and tear down a full App instance every time?
Is there indeed a setting somewhere that I missed with which I could speed up some event loop? (I'm new to textual)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using textual to build a CLI application where the user doesn't spend the entire time in the TUI rendered by textual, but instead the TUI is only open for one step in a larger sequence of steps. When you run the application from your console, you see a few normal python
print()outputs, and then a TUI fills the entire terminal where you can enter some data, and afterwards the TUI closes and the "normal" non-TUI interaction continues.This means that I'm using
app.exitnot as a means of exiting the entire program, but just to get out of the TUI mode so that the rest of the application can continue. it seems like the call toapp.exitusually takes just over 200ms, which might be fine in the use case where you're anyway exiting the entire program, but for my use case it does feel a bit sluggish.Here's my code that I used to measure the delay:
I have tried this with both
textual runandtextual run --dev. The dev mode seems to add an additional 20ms which I'm not concerned about. My main issue is that the non-dev mode usually prints times like 0.2046s.Here's some output from running this in a loop:
To me this feels suspiciously close to always 200ms, so I wonder if there's like an event loop or something like that in the background which could be sped up.
To test if the
inlinemode behaves differently I just ran the calculator example unmodified, which means I don't see exact time measurements but ctrl-q does feel like it might have a similar delay.My questions are:
Appinstance every time?Additional info:
Beta Was this translation helpful? Give feedback.
All reactions