Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: virtual terminal #8

Closed
milahu opened this issue Apr 6, 2022 · 4 comments
Closed

Feature: virtual terminal #8

milahu opened this issue Apr 6, 2022 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@milahu
Copy link
Contributor

milahu commented Apr 6, 2022

Feature

add a virtual terminal widget, so we can show the live stdout and stderr of the run function

Is your feature request related to a problem? Please describe

problem: when running the app without a terminal, then stdout/stderr are not visible

Describe the solution you'd like

challenges:

example: capture stdout with io.TextIOBase
https://stackoverflow.com/questions/51527750/capture-print-output-from-multiple-threads-in-python

import threading
import time
import sys
import io

class demo_copy_stdout():

  def __init__(self):

    def run_function():
      for i in range(0, 100):
        print(*sys.argv, i)
        time.sleep(1)

    self.run_function = run_function

    def main_function_wrapper(*argv):
        sys.argv = argv # set arguments
        # note: run_function takes no arguments
        return self.run_function()

    print("main_thread create")
    self.main_thread = threading.Thread(target=main_function_wrapper, args=("toy.py", "hello",))

    class CopyStdout(io.TextIOBase):
        def __init__(self, target):
            self.target = target
            #self.stringio = io.StringIO()
        def write(self, s):
            writecount = self.target.write(s)
            written = s[:writecount]
            #self.stringio.write(written)
            # TODO send to GUI
            with open("stdout.txt", "a") as f:
                f.write(written)
            return writecount
    print("copying stdout to tee.txt")
    original_stdout = sys.stdout
    sys.stdout = CopyStdout(sys.stdout)

    print("main_thread start")
    self.main_thread.start() # run

    if True:
        print("main_thread wait ...")
        self.main_thread.join() # wait
        print("main_thread done")
        sys.stdout = original_stdout # stop copying stdout

x = demo_copy_stdout()

Describe alternatives you've considered

Additional context

@milahu milahu added the enhancement New feature or request label Apr 6, 2022
@milahu
Copy link
Contributor Author

milahu commented Apr 8, 2022

ps. im working on this : )

Screenshot_2022-04-08_13-12-09 cli2gui terminal

the input tab is the old interface with all the input elements, to set arguments

the output tab is a fully-featured bash terminal (todo: on windows run busybox-w32)

when the user hits start, the GUI switches to the output tab
and shows all output from the process

@milahu milahu mentioned this issue Apr 8, 2022
4 tasks
@FredHappyface
Copy link
Member

Wow that looks awesome thanks for making a start on it. I was going to add it to the backlog as there's a couple other projects I'm focusing on right now

I'm assuming this is compatible with pysimplegui?

Cheers 😊

@milahu
Copy link
Contributor Author

milahu commented Apr 8, 2022

I'm assuming this is compatible with pysimplegui?

yes, this is implemented in psg

@FredHappyface
Copy link
Member

Closing for the following reasons:

  1. Challenges implementing this in a cross-platform way add terminal widget [DRAFT] #9 (comment)
  2. Probably out of scope. I'd encourage an end user to use their fav terminal to start the process in the first place (though there are drawbacks to this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants