The Accidental Rubyist

invalid byte sequence in UTF-8

Archive for the ‘rbcurse’ 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.


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

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.


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

undom = 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

Extended features for tables (ncurses)

with 12 comments

Instead of cluttering up Table, or expecting a user to hack such functions, I am putting some stuff in tableextended.rb. One may include this after opening Table in one’s app. As may be seen in viewtodo.rb, one may bind a key to increasing or decreasing a column’s width. This function checks of numeric arguments so one may do: 15+ or 20- instead of pressing the key 20 times.

class Table
    # so we can increase and decrease column width using keys
    include TableExtended

After creating a table, I can do:

atable.configure() do
    bind_key(?+) {
        # this automatically takes care of numeric arguments such as 12+, 22+ etc
    bind_key(?-) {
        # this automatically takes care of numeric arguments such as 12-, 22- etc

The advantage of doing this, as against 20 times pressing + or -, is that i can now distribute the 20 across the other columns. Earlier if a user pressed + 20 times, i simply had no way of knowing how to distribute each increase or decrease.
Please see master19 branch on github.

Written by totalrecall

May 19, 2010 at 11:42 am

Posted in ncurses, rbcurse, ruby

rbcurse 1.1.2 released

with 2 comments

Ha ! Writing the tutorial helped bring out a typo in listbox which prevented numeric arguments to vim keys from working. So in 5k, 5j the 5 was getting ignored.
Tiny error. 1.1.2 is on

So I guess its just as well. The other day, I came across charva which is a ncurses package for Java. I think i saw this 6 years back or more when i used to work on Java. You can write a program in Swing and run it in charva just replacing java with charva. However, although I think its a great accomplishment (not used it, btw), the programmer has duplicated the GUI way of working in ncurses. In rbcurse, I am trying to go away from GUI metaphors and ways of working. In this age, people who would like to use ncurses/terminal, would probably like vim or emacs like keys, and a lot of power. That’s what I’ve been trying to look at in the last few changes made, and last few features added. Otherwise, rbcurse will just be a very poor second cousin to the GUI.

We’ve got to think of very different widgets/ components, so that users can work a lot faster in rbcurse than they would in a GUI. A totally different concept, not just a poor imitation of other toolkits.

I saw a charva screenshot, i noticed that in the JTable, he puts the header text on the top border, whereas i have a box as a header which eats up 3 lines. I think I can cut down the 2 lines.

Written by totalrecall

May 7, 2010 at 8:40 pm

Posted in ncurses, rbcurse, ruby