import sys import uuid import logging import panel as pn pn.extension('terminal') terminal = pn.widgets.Terminal( "Welcome to the Panel Terminal!\nI'm based on xterm.js\n\n", options={"cursorBlink": True}, height=300, sizing_mode='stretch_width' ) terminal terminal.write("This is written directly to the terminal.\n") terminal.write("Danish Characters: æøåÆØÅ\n") terminal.write("Emoji: Python 🐍 Panel ❤️ 😊 \n") terminal.write("Links: https://panel.holoviz.org\n") sys.stdout = terminal print("This print statement is redirected from stdout to the Panel Terminal") sys.stdout = sys.__stdout__ print("This print statement is again redirected to the server console") logger = logging.getLogger("terminal") logger.setLevel(logging.DEBUG) stream_handler = logging.StreamHandler(terminal) # NOTE THIS stream_handler.terminator = " \n" formatter = logging.Formatter("%(asctime)s [%(levelname)s]: %(message)s") stream_handler.setFormatter(formatter) stream_handler.setLevel(logging.DEBUG) logger.addHandler(stream_handler) logger.info("Hello Info Logger") for i in range(0, 50): logger.info(uuid.uuid4()) terminal.subprocess.run("ls", "-l") terminal terminal.clear() subprocess_terminal = pn.widgets.Terminal( options={"cursorBlink": True}, height=300, sizing_mode='stretch_width' ) run_python = pn.widgets.Button(name="Run Python", button_type="success") run_python.on_click( lambda x: subprocess_terminal.subprocess.run("python") ) kill = pn.widgets.Button(name="Kill Python", button_type="danger") kill.on_click( lambda x: subprocess_terminal.subprocess.kill() ) pn.Column( pn.Row(run_python, kill, subprocess_terminal.subprocess.param.running), subprocess_terminal, sizing_mode='stretch_both', min_height=500 )