Я хочу написать что-то вроде терминальной версии dmenu, которую можно использовать для поиска файла, а затем передать местоположение файла другой программе в конвейере, например:
my_script | xargs vim # search for a file and open in vim
Я пытался сделать это на питоне с перенаправлением вывода, но, похоже, это не работает с проклятиями.
import sys
import curses
prev_out = sys.stdout
print("1:", sys.stdout)
sys.stdout = open("/dev/tty", "w")
print("2:", sys.stdout)
window = curses.initscr()
window.addstr(1, 1, "testing")
window.getch()
curses.endwin()
sys.stdout = prev_out
print("3:", sys.stdout)
Когда я называю это так:
myscript > /dev/pts/1 # redirect output to another tty
print ведет себя так, как я ожидал (2 в исходном tty, 1 и 3 в другом), но пользовательский интерфейс curses отображается в /dev/pts/1.
Итак, мой вопрос: есть ли способ перенаправить вывод curses обратно в /dev/tty или есть другой способ отобразить текстовый графический интерфейс, который можно перенаправить, изменив sys.stdout?