-1

I'm writing a program on python curses and I was wondering if there is a way to block terminal resizing in order to prevent curses' crashing both on Linux and Windows. This is what happens.. Can I prevent this? Under Windows this does not happen cause window resizing doesn't influence prompt proportions... http://alessio.ragno.info/Before%20Resize.png http://alessio.ragno.info/After%20Resize.png

`

import curses
screenTest = curses.initscr()
boxTest = curses.newwin(24,80,0,0)
boxTest.box()
curses.noecho()
curses.cbreak()
curses.start_color()
screenTest.keypad(1)
curses.init_pair(1,curses.COLOR_BLACK, curses.COLOR_CYAN)
curses.init_pair(2,curses.COLOR_YELLOW, curses.A_NORMAL)
boxTest.border(0)
boxTest.addstr(1,1,78*"_")
boxTest.addstr(10,10,"Press ESC to quit...")
boxTest.refresh()
x = screenTest.getch()
while x != 27:
    boxTest.addstr(1,1,78*"_")
    boxTest.addstr(10,10,"Press ESC to quit...")
    boxTest.refresh()
    x = screenTest.getch()

curses.endwin()
exit()

`

Alessio Ragno
  • 476
  • 1
  • 6
  • 20

1 Answers1

1

Terminals are going to resize because users do that. There is no general way to prevent that: suppressing window decorations to eliminate the resize grips is a partial solution which is not portable. You may find occasional comments about different aspects of this, but no comprehensive solutions. Here are a few links:

In curses/ncurses (not in PDCurses), the library pays attention to the environment variables LINES and COLUMNS unless disabled with the use_env function. ncurses adds a signal handler for SIGWINCH during initialization which it uses to detect (and respond to) window-resizing (see resizeterm, for example). If these environment variables set, ncurses will not respond. However (see below) changing this special case will not make Python stop crashing, because Python has more problems than that.

ncurses has handled resizing of windows for almost 20 years; there are applications which fail to work with this. Without some specific test program to discuss, there is no way to determine the cause of a program's crashing.

Regarding the test program added early June 2:

Running your test-program with valgrind, I see a number of errors which are almost all in Python itself (2.6.6 and 2.7.9 on Debian 6 and 8), and a small fraction where Python is freeing memory owned by ncurses. In each case, Python is freeing memory which was already freed. It does this even without resizing (though some of the incorrect frees are related to resizing). I ran this several times, and at least once none of the errors detected were in ncurses. According to valgrind, there are a few dozen points in Python which produce these errors, a few of those account for 2/3 of the more than 400 occurrences it detected. So the question is misphrased. (I could suggest some improvements to the test program itself, but it seems the real problem is Python).

Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • is there a way to disable terminal resizing or to not influence the columns and rows when resizing like in the windows command prompt? because if i resize the terminal window curses crashes. – Alessio Ragno Jun 01 '15 at 21:46
  • http://alessio.ragno.info/Before%20Resize.png http://alessio.ragno.info/After%20Resize.png – Alessio Ragno Jun 01 '15 at 21:57
  • There's no program which someone could test, no useful information. – Thomas Dickey Jun 01 '15 at 22:37
  • I've written a little program just for you. Now. Try to launch it and after launched resize the terminal window... Can i prevent this? – Alessio Ragno Jun 02 '15 at 07:00
  • It seems that you just want to criticise others' questions... Think about givin good answers and not complaining ;) – Alessio Ragno Jun 03 '15 at 13:16
  • Not really: you asked a question for which there was no attractive answer, but mentioned some problems which required analysis to see whose bug underlies the question. – Thomas Dickey Jun 03 '15 at 22:52
  • I was looking to detect terminal resize, thanks, `SIGWINCH` worked like a charm. – exebook Mar 17 '19 at 00:20