SSHScript and Pytermgui
Pytermgui is an excellent Python TUI framework. This example shows that it can get data from the remote console easily by sshscript. And the difference is only one line (connecting or not) between getting data from localhost or remote host.
file: demopytermgui.spy
import pytermgui as ptg
# comment-out the next line to get free memory of localhost
$.connect('user@host-a')
def macro_freememory(fmt: str) -> str:
# We do not need to call $hostname every time.
# It is here just for proving that it is actually executing on remote host.
$ hostname
hostname = $.stdout.strip()
# collect data of free memory by "vmstat"
$ vmstat 1 1
amount = $.stdout.split("\n")[2].split()[3]
return f'host "{hostname}" has free memory {amount}'
ptg.tim.define("!freememory", macro_freememory)
with ptg.WindowManager() as manager:
manager.layout.add_slot("Body")
manager.add(
ptg.Window("[bold]The free memory is:[/]\n\n[!freememory 75]%c", box="EMPTY")
)
execution examples
$sshscript demopytermgui.spy
$sshscript demopytermgui.spy --verbose
$sshscript demopytermgui.spy --debug