You are not logged in.
Inspired by this: https://bbs.archlinux.org/viewtopic.php … 2#p2083502
#! /usr/bin/env python3
"""A terminal emulator full of hot air."""
from subprocess import PIPE, Popen
from tkinter import END, Tk, Text, Event
from typing import Callable
def shellexec(text: Text) -> Callable[[Event], None]:
"""Run a pseudo-shell on the text input."""
def run(_: Event, shell: str = '/bin/bash') -> None:
"""Shell wrapper."""
command = text.get('end-1c linestart', 'end-1c')
if command.strip() == 'exit':
raise SystemExit()
with Popen(shell, stdin=PIPE, stdout=PIPE, stderr=PIPE) as bash:
stdout, stderr = bash.communicate(command.encode('utf-8'))
text.insert(END, stdout.strip())
text.insert(END, stderr.strip())
return run
def main(title: str = __doc__) -> None:
"""Main GUI."""
root = Tk()
root.resizable(False, False)
root.title(title)
text = Text(root, height=16)
text.bind('<Return>', shellexec(text))
text.pack()
root.mainloop()
if __name__ == '__main__':
main()
Inofficial first vice president of the Rust Evangelism Strike Force
Offline