ncurses' Dark Devilry

J

Jeremy Moles

I'm working on a project using ncurses w/ Python. As an aside, I
implemented addchstr in the cursesmodule.c file in Python SVN, if anyone
wants me to try and get that made permanent.

AT ANY RATE...

I was wondering--and this is more a general curses question rather than
a Python one, but I know there are some old-timers here who have made
curses obey before--is there a way to "repaint" a portion of screen
without stealing the "cursor?" That is:

I have a focus "wheel" of sorts that allows the user to do input on
various wigets and windows and whatnot. However, if I want to quickly
call addstr somewhere else in the application I have to:

1. Store the YX coords of the cursor currently
2. Use the cursor in the "current" action
3. Restore the old cursor location

I know there are ways around this as I have seen curses apps that, for
example, have a clock that updates every second without stealing
"focus."

I tried implementing/using addchstr (mentioned above) to no success.

Any ideas? Is this just the plain wrong place to ask this? :)
 
T

Tony Nelson

Jeremy Moles said:
I'm working on a project using ncurses w/ Python. As an aside, I
implemented addchstr in the cursesmodule.c file in Python SVN, if anyone
wants me to try and get that made permanent.

AT ANY RATE...

I was wondering--and this is more a general curses question rather than
a Python one, but I know there are some old-timers here who have made
curses obey before--is there a way to "repaint" a portion of screen
without stealing the "cursor?" That is:

I have a focus "wheel" of sorts that allows the user to do input on
various wigets and windows and whatnot. However, if I want to quickly
call addstr somewhere else in the application I have to:

1. Store the YX coords of the cursor currently
2. Use the cursor in the "current" action
3. Restore the old cursor location

I know there are ways around this as I have seen curses apps that, for
example, have a clock that updates every second without stealing
"focus."

I tried implementing/using addchstr (mentioned above) to no success.

Any ideas? Is this just the plain wrong place to ask this? :)

I've only tried to read the Python Library Curses docs, but I thought
that the Window object method addstr() would do what you want.
________________________________________________________________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
 
J

Jeremy Moles

I've only tried to read the Python Library Curses docs, but I thought
that the Window object method addstr() would do what you want.

Perhaps I should have been more specific. :)

addstr (or any of it's brothers, even those bound to a subwin instance)
write values to an internal buffer/object that then gets flipped
(refreshed()) onto the physical screen.

However.

All of the routines I can find in the ncurses library want to take
control of the "cursor" object. That is: they either want to advance
it's position (addstr) or not (addchstr), but they both certainly grab
"control" of it; at least, visually.

Basically what I'm looking for is a way to refresh a portion of a
curses-controlled "window" without affecting the current location of the
cursor or having to manually move it and move it back.
 
C

Christopher Subich

All of the routines I can find in the ncurses library want to take
control of the "cursor" object. That is: they either want to advance
it's position (addstr) or not (addchstr), but they both certainly grab
"control" of it; at least, visually.

Basically what I'm looking for is a way to refresh a portion of a
curses-controlled "window" without affecting the current location of the
cursor or having to manually move it and move it back.

Why not wrap your 1-3 in a function of your own? More generally, build
a 'cursor location stack', probably using a list. Add utility functions
push_cur and pop_cur to push and pop the current location of the cursor
from that stack (pop_cur actually resets the current cursor location for
future printing). Then your "write over there" becomes:

push_cur()
move_cursor(location)
write(text)
pop_cur()

which can be pretty easily wrapped in a single function.

Mind you, I don't use curses myself, but what would prevent this from
working?
 
G

Greg Ewing

Christopher said:
Why not wrap your 1-3 in a function of your own?

It sounds like the OP is concerned about the visual effect
of the cursor moving on the screen while characters are
written.

I doubt whether curses provides any way of controlling
that. Curses was designed for glass ttys, on most of
which it is physically impossible to write characters
without the cursor moving. The best you can do is move
it back to where you want it afterwards.
 
G

Grant Edwards

It sounds like the OP is concerned about the visual effect of
the cursor moving on the screen while characters are written.

I doubt whether curses provides any way of controlling that.
Curses was designed for glass ttys, on most of which it is
physically impossible to write characters without the cursor
moving. The best you can do is move it back to where you want
it afterwards.

While you do have to move the cursor to the location where you
want to write, some terminals allow you to make the cursor
invisible. This can reduce the visual distraction when you
need to update something on the screen that isn't where the
cursor belongs (from the user's point of view).
 
M

Mike Meyer

Jeremy Moles said:
Basically what I'm looking for is a way to refresh a portion of a
curses-controlled "window" without affecting the current location of the
cursor or having to manually move it and move it back.

Have you looked into using curses window feature?

<mike
 

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

No members online now.

Forum statistics

Threads
474,273
Messages
2,571,363
Members
48,047
Latest member
prince15

Latest Threads

Top