-1

My OS is Linux. I use FISH shell with Alacritty terminal emulator. I want to write a Python code which splits the terminal in two, separating them with "|" characters, and having user be prompted on both sides. Kind of like how Tilix does it, I want it all to be text because I have old PC with Arch Linux on it and no DE or WM, just the terminal. I want to use tiling functionality there.

I have tried: os.system("fish") to prompt the user but I want to be able to manipulate the terminal output. It would be useful to somehow run the command In background using Python threading library and constantly read the command output, modify it and output it to the user. I have tried: os.popen("echo hi").read() which returns "hi\n" but when I tried os.popen("cmatrix") the program just hangs. os.popen waits for the command to finish executing. I want to get the output during its runtime.

Is it possible to achieve that? My biggest problem is reading the output of running commands. Its not required to use os library.

Voil
  • 3
  • 3

1 Answers1

1

Injecting output like that unfortunately would require you to act as the terminal.

One reason is that the application can get the size of the terminal in columns and lines, and fish uses this extensively so it can figure out how much it can print - is there space for the autosuggestion (if you print too much it'll spill onto the next line, which breaks in fun ways), where does it need to start the right prompt (if any), etc.

Another is that separate applications will need to set the terminal up separately - one thing here is the terminal modes. These are things like "which character marks the end of file" and "is flow control enabled" (this is what freezes your terminal when you press ctrl-s, disabled in fish by default). This means that these applications should have separate terminals to set up.

So, what you would have to do is use something like python's pty module. This won't be a trivial task.

With how little information you have given us about what you actually want to achieve, really the best advice we can offer you is to just use tmux - this is what tmux does. It runs in a terminal and allows you to tile the window into multiple sessions.

faho
  • 14,470
  • 2
  • 37
  • 47
  • Haha, yeah I found out about tmux couple hours after I posted this but I couldn't figure out how to take the post down. Thank you anyway for replying to my stupid question. English isn't my native language and I rarely ask questions. – Voil Apr 29 '23 at 18:54