Subject: [sup-talk] nonblocking_getch

From: [email-masked] (Daniel Hilton)
Date: Wed, 20 Feb 2008 21:43:55 -0700

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

---

From: [email-masked] (William Morgan)
Date: Mon, 25 Feb 2008 09:38:28 -0800

>       repeat = Ncurses.getch until repeat != c

Thanks, I'm going to play around with this. If you feel like learning
git-format-patch (the wiki has some instructions), you can get your name
in the commit log (ooohhh!).

> 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.

Yeah, the entire ncurses setup is completely cargo-cult programming. I
have no idea why it works, and changing any bit of it breaks everything
in weird ways.

-- 
William <wmorgan-sup at masanjin.net>