Preventing cursor flickering in ncurses applications

48 Views Asked by At

I recently wrote an application in ncurses. In most of it, the cursor is disabled, but one part of it includes an editor (using forms), and the cursor is enabled for this (with visibility 2).

I have some different panes (really multiple windows, composing the screen) in the application, including a status bar at the bottom, and whenever the row changes in one window, I update the status bar (part of a different window) to reflect the new line number. The windows are all non-overlapping.

Occasionally, but not always, I notice the cursor briefly visible at the end of the repainted window in the status bar. For the most part, I batch up screen updates using wnoutrefresh, and this is always the case when updating the status bar. The window where the cursor should be is a pad, and doupdate() is only called when the pad is updated.

Ideally, I would only notice the cursor moving around the window where it is originally, and the side-effects of updating other windows would not cause the cursor to be briefly visible there, causing a brief, but distracting, flash. I'm a bit stuck on why this is happening currently and how I could prevent it, given all the window updates are being batched in the manner described above. To experiment, I tried both:

  • saving the original cursor position prior to updating the status bar and re-enabling it after, so that the cursor position is restored after that window is updated
  • disabling the cursor before updating the status bar and re-enabling it after. I didn't really expect this to work, since the status bar is updated using wnoutrefresh already, and indeed it doesn't make any difference.

I thought the first approach would work, as there is another "bug" currently where if the status bar is updated in the background and doupdate() is called immediately, the cursor will be left at the end of the new text there until something happens in the window where the cursor is to cause the cursor to move back to the right place. This behavior makes sense to me, which is why I'm a bit puzzled at the different behavior of the other case.

Is there anything else I could do to ensure the cursor doesn't get moved around like this? I suppose one way would be writing to a window without moving the cursor, but not sure if that is the best/only way.

0

There are 0 best solutions below