Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
* [sup-talk] nonblocking_getch
@ 2008-02-21  4:43 Daniel Hilton
  2008-02-25 17:38 ` William Morgan
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Hilton @ 2008-02-21  4:43 UTC (permalink / raw)


First of all, kudos to all who have contributed to sup (especially
William!).  Its the bees knees.

One issue:
At least on my slow computer, the time it takes to dispatch even a simple
action (like cursor_down) is a bit longer than my keyboard's repeat
interval.
So, when I hold down 'j' to scroll through several messages, it continues to
scroll for a few seconds after I release the key, causing me to overshoot my
target every time.

I've got a solution that works on my system, adding
'Ncurses.stdscr.nodelay1' to start_cursing, and modifying
nonblocking_getch as follows:

  def nonblocking_getch
    if IO.select([$stdin], nil, nil, 1)
      repeat = c = Ncurses.getch
      repeat = Ncurses.getch until repeat != c
      c
    else
      nil
    end
  end

This effectively discards the extra keystrokes that accumulate while the
action is taking place, and makes the UI seem more responsive (even though
it isn't actually any faster).

As a side note: having added nodelay, there doesn't seem to be any real
reason we would need to keep the IO.select... but in my brief
experimentation I found various unpleasant side-effects when I tried to
remove it. I guess it doesn't hurt anything to leave it in.

There may also be side-effects that I haven't noticed from using nodelay,
but everything seems to work as it should.

Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/sup-talk/attachments/20080220/0c1c9318/attachment.html 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-02-25 17:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-21  4:43 [sup-talk] nonblocking_getch Daniel Hilton
2008-02-25 17:38 ` William Morgan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox