Python3 curses behavior

V

Vlasov Vitaly

Hello.

I found strange behavior of curses module, that i can't understand. I initialize screen with curses.initscr(), then i create subwin of screen with screen.subwin(my_subwin_sizes). After that i fill subwin with my_char in for-loop. On last char in last line subwin.addch() raises exception.

This is my problem. Why? How to fix it?

(If i will ignore exception, then last char will be displayed)

Here simple example:
http://pastebin.com/SjyMsHZB

Thank You!
 
C

Chris Angelico

Hello.

I found strange behavior of curses module, that i can't understand. I initialize screen with curses.initscr(), then i create subwin of screen with screen.subwin(my_subwin_sizes). After that i fill subwin with my_char in for-loop. On last char in last line subwin.addch() raises exception.

This is my problem. Why? How to fix it?

(If i will ignore exception, then last char will be displayed)

Here simple example:
http://pastebin.com/SjyMsHZB

What exception is being raised? That's kinda the most important part here :)

ChrisA
 
V

Vlasov Vitaly

Ñуббота, 9 Ñ„ÐµÐ²Ñ€Ð°Ð»Ñ 2013 г., 15:28:51 UTC+4 пользователь Chris Angelico напиÑал:
What exception is being raised? That's kinda the most important part here:)



ChrisA

curses.error <-- all curses-related exception
Exception text: curses.error: 'addch() returned ERR'
 
V

Vlasov Vitaly

Ñуббота, 9 Ñ„ÐµÐ²Ñ€Ð°Ð»Ñ 2013 г., 15:28:51 UTC+4 пользователь Chris Angelico напиÑал:
What exception is being raised? That's kinda the most important part here:)



ChrisA

curses.error <-- all curses-related exception
Exception text: curses.error: 'addch() returned ERR'
 
T

Terry Reedy

Hello.

I found strange behavior of curses module, that i can't understand. I
initialize screen with curses.initscr(), then i create subwin of
screen with screen.subwin(my_subwin_sizes). After that i fill subwin
with my_char in for-loop. On last char in last line subwin.addch()
raises exception.

I have never used curses but I have used text screens. I suspect that
addch moves the cursor to the position beyond where the character is
added, but there is no such position. I remember having problems writing
to the last char of a 24x80 screen without getting either a scroll or
beep if scrolling was disabled.
This is my problem. Why? How to fix it?

Perhaps this will help:
window.leaveok(yes)
If yes is 1, cursor is left where it is on update, instead of being at
“cursor position.†This reduces cursor movement where possible. If
possible the cursor will be made invisible.
(If i will ignore exception, then last char will be displayed)

Otherwise, just catch the exception, as you already discovered.
 
V

Vlasov Vitaly

Ñуббота, 9 Ñ„ÐµÐ²Ñ€Ð°Ð»Ñ 2013 г., 23:22:47 UTC+4 пользователь Terry Reedy напиÑал:
I have never used curses but I have used text screens. I suspect that

addch moves the cursor to the position beyond where the character is

added, but there is no such position. I remember having problems writing

to the last char of a 24x80 screen without getting either a scroll or

beep if scrolling was disabled.






Perhaps this will help:

window.leaveok(yes)

If yes is 1, cursor is left where it is on update, instead of being at

“cursor position.†This reduces cursor movement where possible. If

possible the cursor will be made invisible.






Otherwise, just catch the exception, as you already discovered.

Thank you.

I tried everything in my test script.
win.leaveok() - no effect
curses.cur_vis() - no effect
win.scrollok() - start newline and place cursor on it

It's only one last option:
on last line last char try/except with pass.
 
V

Vlasov Vitaly

Ñуббота, 9 Ñ„ÐµÐ²Ñ€Ð°Ð»Ñ 2013 г., 23:22:47 UTC+4 пользователь Terry Reedy напиÑал:
I have never used curses but I have used text screens. I suspect that

addch moves the cursor to the position beyond where the character is

added, but there is no such position. I remember having problems writing

to the last char of a 24x80 screen without getting either a scroll or

beep if scrolling was disabled.






Perhaps this will help:

window.leaveok(yes)

If yes is 1, cursor is left where it is on update, instead of being at

“cursor position.†This reduces cursor movement where possible. If

possible the cursor will be made invisible.






Otherwise, just catch the exception, as you already discovered.

Thank you.

I tried everything in my test script.
win.leaveok() - no effect
curses.cur_vis() - no effect
win.scrollok() - start newline and place cursor on it

It's only one last option:
on last line last char try/except with pass.
 
D

Dan Stromberg

Sent from my android phone.
ÓÕÂÂÏÔÁ, 9 ÆÅ×ÒÁÌÑ 2013 Ç., 23:22:47 UTC+4 ÐÏÌØÚÏ×ÁÔÅÌØ Terry Reedy ÎÁÐÉÓÁÌ:

Thank you.

I tried everything in my test script.
win.leaveok() - no effect
curses.cur_vis() - no effect
win.scrollok() - start newline and place cursor on it

It's only one last option:
on last line last char try/except with pass.

I doubt this is a Python 2 or Python 3 problem; historically some terminal
types curses supports could not fill the lower right-most character cell
without causing an undesired scroll of the screen by one line. So portable
curses programs avoid filling that spot with anything.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,126
Latest member
FastBurnketoIngredients
Top