DevHeads.net

Ruby and ffi-curses?

I've been looking at ffi-curses lately (on the recommendation
of JEG2) for the purpose of wrapping it...

The functions to retrieve screen/window contents do not seem
to work for me (e.g., winchstr).

Does anyone else have experience with this? Or can someone
recommend a "better" curses lib where this does work?

Thanks,
Hal Fulton

Comments

Re: Ruby and ffi-curses?

By Eric Wong at 05/08/2015 - 16:08

Hal Fulton < ... at gmail dot com> wrote:
I use the C ext "curses" gem which was extracted from the stdlib a while
back. I don't do a whole lot with it[1], but it's enough.
The hackiness of FFI (especially regarding struct layouts) scares me off.

[1] <a href="http://bogomips.org/dtas.git/plain/bin/dtas-console" title="http://bogomips.org/dtas.git/plain/bin/dtas-console">http://bogomips.org/dtas.git/plain/bin/dtas-console</a>

Re: Ruby and ffi-curses?

By Eric Christopherson at 05/09/2015 - 15:19

On Fri, May 08, 2015, Eric Wong wrote:
Have you written anything about this hackiness? If not, would you mind
doing so? I'm curious.

Re: Ruby and ffi-curses?

By Eric Wong at 05/09/2015 - 15:42

Eric Christopherson < ... at gmail dot com> wrote:
Daniel did a while back:
<a href="http://djberg96.livejournal.com/175390.html" title="http://djberg96.livejournal.com/175390.html">http://djberg96.livejournal.com/175390.html</a>
<a href="http://djberg96.livejournal.com/179908.html" title="http://djberg96.livejournal.com/179908.html">http://djberg96.livejournal.com/179908.html</a>

I don't know if things have gotten better over the years. Unlike Daniel
(and even the FSF), I consider the inability to run on proprietary
platforms to be a feature :)

Re: Ruby and ffi-curses?

By Hal Fulton at 05/09/2015 - 10:37

Thanks for that. Agreed.

I've gone back to the regular curses gem and found it works for me
with only "moderate" modifications.

Do you use curses much in Ruby? I don't -- but I am writing my own wrapper
so that I can/will use it more.

Hal

Re: Ruby and ffi-curses?

By Eric Wong at 05/09/2015 - 18:28

Hal Fulton < ... at gmail dot com> wrote:
Nope, dtas-console is so far my only experience with curses anywhere.

I always favor reducing interactive UI components in favor of
hacker-friendly ones (data formats and protocols) as much as possible.
This lets others build UI on top of it for their personal preferences.

UI is too personal of a choice and subject to too much bikeshedding.

I made an exception for dtas-console since I needed a good way to
display the offset of the track currently playing. And when forced to
make UI decisions, I try to steal existing things such as key bindings
(from mplayer) so at least some users do not need to relearn muscle
memory.

Re: Ruby and ffi-curses?

By Matt Lawrence at 05/09/2015 - 12:35

On 05/09/2015 09:37 AM, Hal Fulton wrote:
-- Matt

Re: Ruby and ffi-curses?

By =?ISO-8859-1?Q?... at 05/09/2015 - 11:23

Hey,

I'm using curses in the daigaku gem, which is a text based interface for
learning Ruby.
However, I totally agree that curses is not really straight-forward to
use - even the method naming is not really Ruby-like and somehow
unintuitive. Maybe we should work on this to make it more usable?

I was wondering whether curses or ncurses is still the way to go for
terminal manipulation or if there is another, maybe more up-to-date,
lib. Does anyone of you know an alternative?

Paul

Am 09.05.2015 um 16:37 schrieb Hal Fulton:

Re: Ruby and ffi-curses?

By Hal Fulton at 05/12/2015 - 12:08

Paul,

I'm working (in my non-copious spare time) on a "thick" curses wrapper for
Ruby.

I think you know what I mean by a thick wrapper -- not like Sir Mix-A-Lot.
:P
The interface I have in mind would be internally based on curses (or
similar) for
feature-richness and robustness, but would *not* necessarily cater to
anyone's
old-fashioned geek baggage.

In other words, you wouldn't necessarily be at an advantage if you know
curses --
which could be a bad thing. But you also are not at a disadvantage if you
don't,
which is a good thing.

Anyway: If you (or others) have interest in working on such, let me know.
The repo
is not public yet.

Thanks,
Hal

On Sat, May 9, 2015 at 10:23 AM, Paul Götze <paul.christoph. ... at gmail dot com

Re: Ruby and ffi-curses?

By Stu at 05/12/2015 - 13:30

Hal I'd be interested in helping. Have you seen the suckless project
termbox (ha like terminfo baggage and termcap db)

Here is a link my greybearded friend:
<a href="https://code.google.com/p/termbox/" title="https://code.google.com/p/termbox/">https://code.google.com/p/termbox/</a>

Stu

Re: Ruby and ffi-curses?

By Matt Lawrence at 05/12/2015 - 12:13

I still have a copy of "Unix Curses Explained". I bought it when I was
using the old ncurses Ruby library back in 2003/2004. A totally
different and more easily understood interface would be a nice thing.

-- Matt

On 05/12/2015 11:08 AM, Hal Fulton wrote:

Re: Ruby and ffi-curses?

By Daniel Berger at 05/08/2015 - 15:08

I don't have specific knowledge of it Hal, but maybe I can help.

What platform?
What version of Ruby?
What version of FFI?

Dan

Re: Ruby and ffi-curses?

By Hal Fulton at 05/08/2015 - 15:11

As it happens --

Mac OSX (aren't you Windows?)
Ruby 2.2
ffi-curses 0.4.0 (latest?)

Hal

Re: Ruby and ffi-curses?

By Daniel Berger at 05/10/2015 - 11:09

Hal and I did learn that the arguments to the functions that he was having
trouble with were marked as :pointer, and are meant to be output buffers.
In practice, we couldn't get it to work. Passing raw FFI::Pointers caused a
segfault, and passing Ruby 0.chr buffers didn't generate meaningful data. I
wonder if they should be marked :buffer_out.

Regarding my LJ posts on FFI itself, I'd still rather use C extensions, but
I also want to be friendly to JRuby. Consequently, the majority of my libs
that used C now use FFI. In cases where I thought raw speed was important
(win32-nio, io-extra), I have left them as (or converted them back to) C
extensions.

Dan

Re: Ruby and ffi-curses?

By Bar Hofesh at 05/10/2015 - 11:51

Hi , just something to try , instead of pointer create an empty struct and pass it as the pointer , that helped me when I integrated SSH

Sent with AquaMail for Android
<a href="http://www.aqua-mail.com" title="http://www.aqua-mail.com">http://www.aqua-mail.com</a>

Hal and I did learn that the arguments to the functions that he was having trouble with were marked as :pointer, and are meant to be output buffers. In practice, we couldn't get it to work. Passing raw FFI::Pointers caused a segfault, and passing Ruby 0.chr buffers didn't generate meaningful data. I wonder if they should be marked :buffer_out.

Regarding my LJ posts on FFI itself, I'd still rather use C extensions, but I also want to be friendly to JRuby. Consequently, the majority of my libs that used C now use FFI. In cases where I thought raw speed was important (win32-nio, io-extra), I have left them as (or converted them back to) C extensions.

Dan

On Fri, May 8, 2015 at 1:11 PM, Hal Fulton < ... at gmail dot com<mailto: ... at gmail dot com>> wrote:
As it happens --

Mac OSX (aren't you Windows?)
Ruby 2.2
ffi-curses 0.4.0 (latest?)

Hal

On Fri, May 8, 2015 at 2:08 PM, Daniel Berger < ... at gmail dot com<mailto: ... at gmail dot com>> wrote:
I don't have specific knowledge of it Hal, but maybe I can help.

What platform?
What version of Ruby?
What version of FFI?

Dan

On Fri, May 8, 2015 at 11:12 AM, Hal Fulton < ... at gmail dot com<mailto: ... at gmail dot com>> wrote:
I've been looking at ffi-curses lately (on the recommendation
of JEG2) for the purpose of wrapping it...

The functions to retrieve screen/window contents do not seem
to work for me (e.g., winchstr).

Does anyone else have experience with this? Or can someone
recommend a "better" curses lib where this does work?

Thanks,
Hal Fulton