peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations
Apache License 2.0
3.61k stars 238 forks source link

Running shell commands from TUI #351

Closed brd002 closed 2 years ago

brd002 commented 2 years ago

Hi,

What is the right way to run a bash command from user interface? For example I need to run less and see the output on a blank screen without any ui. But after process finishes, return the interface.

peterbrittain commented 2 years ago

It's up to you.

The first and the last should let you run less interactively. The middle option only works for noninteractive commands.

brd002 commented 2 years ago

Thanks for your reply! I am trying the third option. Is there any way to close the terminal without using Ctrl+C?

It's up to you.

* The simplest way is to  close the Screen, run the command then open the Screen again (and then play your TUI, or whatever you want).

* Next simple option is to run the command and save all the output to a TextBox.

* Lastly, you can do something like the terminal.py demo that pipes the output to your TUI.

The first and the last should let you run less interactively. The middle option only works for noninteractive commands.

peterbrittain commented 2 years ago

You'll need to make a small change, either to detect the end of the running process (in update) or some keypress (in process_event) and stop the application, or move to the next scene.

I've just pushed code to detect when the shell closes (see https://github.com/peterbrittain/asciimatics/commit/c01d3b442dc26050761749f6814845868a873781). You should now be able to use ctrl-D or type "exit" to stop the demo cleanly.

peterbrittain commented 2 years ago

Am assuming this solved your question. LMK if not...