The Accidental Rubyist

invalid byte sequence in UTF-8

Archive for the ‘ncurses’ Category

rbcurse-extras 0.0.0 released

with 9 comments

Finally managed to release rbcurse-extras initial version with a small tweak to vimsplit. I also did some work on Actions for widgets so using ":" or "M-:" could pop up a menu for the current widget. Applications can add to this. This led to upgrades in rbcurse-core, so i’ve released rbcurse-core-0.0.3 with those changes.

I’ve tested out only editable lists and tables (the old programs) in rbcurse-extras, not everything.

The previous version of rbcurse (0.0.2), allows the user to see key-bindings for the current widget/control by pressing "M-?" or "?". It allows user to edit a textbox in vim or EDITOR and also "save as" using the ":"/"M-:" menu. It also introduced History to Field (optional at present), so you need to extend the Field object. History can be popped up using "M-h". I’ve used this in the shell-output dialog.

I’ve done some changes to ncurses settings (cbreak and half-delay) as i found that pressing C-c repeatedly quickly was crashing the app (see earlier posts), Hope this holds up in all cases.

Advertisements

Written by totalrecall

January 5, 2012 at 1:35 pm

Posted in ncurses, rbcurse, ruby

ruby ffi-ncurses and panels – progress

leave a comment »

Thanks a lot to manver’s Panel class (Linked in previous post). I’ve got some old sample programs using panels functioning with manver’s Window and Panel code. Also, today, I used the Window class provided in examples in the ffi-ncurses program alongside manver’s panel class.
I’d say manver’s window class required fewer modifications from the old ncurses-ruby code. However, there’s some uncleanliness at times when i have to pass the pointer of the window class to methods instead of the window itself. It would have been nice if the classes could have managed this internally. Also, the panel class needs to know the location of libpanelw either in the ENV or coded in class.

Now i can actually start the task of porting the rbcurse work to ffi-ncurses. Most of my ncurses work is in 2-3 classes, so that should not be an issue. However, very often something does not work, but does not give an error. Or printing happens in the wrong place. Or colors are not set. One has to be very careful while testing. These things can get missed unless one has an output to compare with.

Written by totalrecall

September 5, 2011 at 2:03 pm

Migrating rbcurse to ffi-ncurses

with 4 comments

Back after a long break. Ruby 1.9.3 is out and it has something called io/console which I could not figure out. Anyway, I’d like to port rbcurse so it can use ffi-ncurses instead of ncurses-ruby which is so infernally hard for a lot of people to install.
ffi-ncurses does not have panel support. I wasted many hours trying to add it to Window. I found Ver’s panel.rb but that did not work with ffi’s Window class (provided in the examples). I found another Window.rb in the Ver package (github) and I am in quite a mess currently trying to integrate them. Getting segmentation faults.

Will probably some updates on that tumblr page I have somewhere.

Written by totalrecall

September 4, 2011 at 1:13 pm

Does gmail web interface use IMAP ?

with one comment

I’ve been writing a gmail client as a demo just to kick around rbcurse’s newer features.
When I fetch the body of a mail, it takes a little time. This also sets the message/mail as READ on the server.

However, on gmail’s web interface, clicking on an unread mail instantly displays the body. This means that gmail has downloaded the body in the background *without* setting off the flag as READ. So is gmail using its own IMAP api, or something else ?

Also, some operations from the gmail gem such as star and unstar don’t seem to work. Could be a bug in the gem, though. However, however a strange thing is that the UID of a starred message in the Inbox is different from its UID in "Starred". So when i am in any folder, i have no way of knowing what the starred messages are. How does Gmail itself manage identifying starred items.

gmail client rbcurse

gmail client using rbcurse

Written by totalrecall

November 8, 2010 at 2:02 pm

Posted in ncurses, rbcurse, ruby

ncurses working with ruby 1.9.2 (Snow Leopard)

with 14 comments

Thanks to the comment on the previous post, and the folks on ruby-forum, I’ve managed to get the ncurses gem working on ruby 1.9.2. Some changes are required w.r.t. STR2CSTR. I’ve uploaded a gem here. I’ve named the gem ncurses-0.9.2.gem to avoid confusion with the existing 0.9.1. I hope it’s not illegal.

btw, not all examples of ncurses are working. Some are breaking due to changes in ruby 1.9.x, and some I don’t know. example.rb, rain.rb and hello_world are working.

Edit: Thanks to Ralf Papenkordt, ncurses 1.2.4 is now working on Snow Leopard. The gem and tarbz2 are available on github.

Update: You may also try:

gem install snowleopard-ncurses

Written by totalrecall

August 22, 2010 at 2:11 pm

Posted in ncurses, ruby

ncurses gem failing on Snow Leopard under ruby 1.9.2

with 2 comments

I have ncurses gem working fine under ruby 1.9.1 (after some fixing and patching).
However, i just installed ruby 1.9.2 using rvm. The stock “gem install ncurses” of course fails. Then I downloaded and installed ncurses-0.9.1. This also of course fails. I patched it and got it to install. However, all examples fail. Here’s what i get:

dyld: lazy symbol binding failed: Symbol not found: _STR2CSTR
Referenced from: /Users/rahul/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/x86_64-darwin10/ncurses.bundle
Expected in: flat namespace dyld:
Symbol not found: _STR2CSTR
Referenced from: /Users/rahul/.rvm/rubies/ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/x86_64-darwin10/ncurses.bundle
Expected in: flat namespace
Trace/BPT trap

I also copied the working ncurses gem from 1.9.1 (and installed it under 1.9.2) and that too gives the same runtime error.

EDIT: SOLVED Pls see https://totalrecall.wordpress.com/2010/08/22/ncurses-working-with-ruby-1-9-2-snow-leopard/

Written by totalrecall

August 20, 2010 at 11:05 pm

Posted in ncurses, ruby

A vim-like listbox in rbcurse (ruby ncurses)

leave a comment »

Lots of terminal application users like applications to use vim-like keys. So I’ve played around with the Listbox of rbcurse, and added some mappings to give it a very vim (and emacsy) feel. The result is on github (master19 branch) as examples/testlistbox.rb.

What did i do:

1. require "rbcurse/vieditable"

This adds a whole lots of vim like bindings to lists. Since, this file is shared by textareas and lists, I’ve put in some separate mappings for listboxes in there. This allows us to use “gg” “G”, “dd”, o, O, j,k and plenty of other keys.

Note than normally entering into a cell of a listbox makes it editable in-place. Exiting saves the value. But being terminal freaks, we don’t like that behavior ! We want keys to be used for navigation and search etc. So for changing contents I can press a “C”. And edit box at the bottom of the screen (ugh! reminds you of alpine, doesn’t it). Similarly, to add a row above or below the present you can press “o” or “O”.

Please note, to keep the library and my life simple, delete is “dd”, So to delete 5 rows its “5dd” not “5d”, To yank 5 rows it is “5yy” not “5y”. Maybe in the future, I’ll look into this.

2. $catch_alt_digits = true; # emacs like alt-1..9 numeric arguments

For the emacs crowd. You like to use C-u for numeric arguments. In a rbcurse app, C-u no longer does an undo, its always used for numeric arguments, each successive press of C-u uses a range: 4, 16, 64 etc (I’ve detailed this in a previous post)

However. catch_alt_digits allows us to use numeric arguments like Alt-9 9 for 99. To go down 99 rows, an emacs guy can do Alt-99 j. Of course, vim guys can just do “99j”.
The advantage of catch_alt_digits is that it can be used in editable boxes too, such as textareas.

3. cell_editing_allowed false

In order that keys can be mapped to functions or blocks, I’ve disabled cell_editing. If I did not, then j or k would insert a j or k in the box.

4. listb.one_key_selection = false # this allows us to map keys to methods

By default, if cell_editing is false, typing a key takes us to the first item that starts with that key. That’s pretty friendly behavior, but it does not allow us to map keys. So setting this as false, means we can map keys. Now use “f” to go to the first row, as “fn” or “f <char>”.

5. The mappings. Rather than put the mappings in the sample file, I’ve added them to the vieditable.rb file, so they may be reused. So lets call that method.

listb.vieditable_init_listbox

6. We want to have infinite linear undo and redo. So let’s instantiate our undo manager and give it our list.

undom = SimpleUndo.new listb

Now we can use “u” and “C-r” for undo and redo. The emacs key “C-_” can also be used. You can do single or multi-row deletes and undo. “12dd”, “u”. For this don’t forget to require the undo manager at the top.

require 'rbcurse/undomanager'

That’s about it. However, there’s more in the mappings. I’ve adopted emacs’s kill-ring concept. So “yy” does a kill-ring-save. “p” and “P” of course do a paste (emacs calls it a yank, for vimmers a yank is a copy). For emacsers, M-w does a kill-ring-save, C-y does a yank (paste), and M-y does a yank-pop. Again, this is explained in a previous post, but it helps to save multiple rows into a ring, and select which one one wishes to paste. We first have to type C-y to paste the last copy, and then M-y to cycle through previous copies. I think this gives the best of both worlds without a vimmer having to change his habit of yy and p/P.

This sample is not included in the rbcurse gem 1.1.3. Fetch it from github, it will be included in 1.1.4 when i release it shortly.

Written by totalrecall

May 24, 2010 at 11:47 am

Posted in ncurses, rbcurse, ruby