1

I am trying to write a file manager using Python and Curses. A feature I want to have is by pressing enter over an executable, said executable will be run within the terminal. What is happening is that the program runs, but input does not work and newlines aren't returning to the left side of the screen. I think this is because Curses is still trying to format the output of the run program and blocking input. How can I temporarily stop curses from making these changes to the terminal?

I have tried putting

curses.nocbreak()
stdscr.keypad(False)
curses.echo()

before calling os.system, to no avail. I also tried the same code with subprocess.call to the same result

Enderbyte09
  • 409
  • 1
  • 5
  • 11
  • It really depends on what the executable is trying to do; if it sends its own control characters it will inevitably mess things up, and since you are using `os.system` you have even less control over that. Better to trap all the stdout/stderr using [`subprocess.Popen`](https://docs.python.org/3/library/subprocess.html#replacing-os-system). Once you trap that, you can then have control over how it outputs in your application, [relevant thread](https://stackoverflow.com/questions/48697482/python-using-ncurses-when-underlying-library-logs-to-stdout/). – metatoaster Oct 13 '22 at 03:38

1 Answers1

1

nocbreak, keypad, echo only modify the settings used by curses in program mode. If you want to run a non-curses application, you'll have to revert (temporarily) to shell mode:

curses.reset_prog_mode()

Restore the terminal to “program” mode, as previously saved by def_prog_mode().

curses.reset_shell_mode()

Restore the terminal to “shell” mode, as previously saved by def_shell_mode().

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105