The Accidental Rubyist

invalid byte sequence in UTF-8

Archive for February 2010

Emacs fun in ruby ncurses library

leave a comment »

For all those situations where numeric arguments or numeric prefixes to methods cannot be specified by typing a number (typically editable components), we have 2 ways of specifying, copied shamefully from emacs.

1. C-u – each press of C-u multiplies a “multiplier” by 4. So you get 4 16 64.
To go execute C-n 16 times, one can do: C-u C-u C-n.

2. C-u 16 C-n
After C-u enter numbers, and end with key binding.
You can terminate a number with a second C-u as C-u 16 C-u 0. This is required if the command itself is numeric. Here 0 is a command.

3. Use the key M-1 through M-9to specify numeric argument. For larger numbers pressing M (alt) is not required. Example, M-1 6 M-n, executes M-n 16 times. Perhaps, emacs people use the C-u when the command is invokes by Control, and M-1 when invoked by Meta. I don’t know. I just know that we’ve got to make this ncurses widget library as powerful as possible. And key-bindings are an important way.
If my explanation did not make sense, you can read this page. Note, i’ve not implemented negative arguments (yet).

WARNING ! Since I am catching C-u globally, therefore C-u is no longer used as undo in Field and Textarea. I’ve used C-_ for undo.

Written by totalrecall

February 26, 2010 at 8:59 pm

Posted in rbcurse

rbcurse gets vim keys here and there

leave a comment »

Now `Textviews`, `Listboxes` have vim like keys and one can easily map double key combinations to methods.
I’ve included some of this in the demo examples/rfe.rb (ruby 2-pane file explorer).
Also, these widgets can take a number preceding motion commands, so you can do “12j”, “33l”, or “10” arrow-key/C-n etc. “gg” takes to top.
This is just for starters.

The problem in `Textarea` is that since it is _editable_, i don’t know how to specify a “multiplier” (numeric argument). I looked up emacs which uses 2 styles: C-u followed by a number. Or M-number. Have to think about this.

Curently, listboxes jump to the first (or next) element when an alphanumeric key is pressed. Experimentally, to get into vim mode, one may press M-v (alt-v). Now f (char) takes you to the file starting with (char) . So not much functionality lost. Now, gg, G, j, k, dd, etc work, along with multipliers.

Written by totalrecall

February 24, 2010 at 9:04 pm

Posted in rbcurse

Splitpanes with Scrollpanes are finally working again (rbcurse)

leave a comment »

rbcurse is getting back into shape — currently working on a branch named rfed16 – its a simplified version of rbcurse19, in that i’ve reduced the number of pads in SplitPanes and ScrollPanes – in fact removed them altogether – only the final widget creates a pad. I am now using absolute coordinates, so i am better in control. Placing the cursor is no longer and issue.
There are still some programs not functioning — in this case it usually means some missing information not yet passed, not a change in logic, so there’s no breakage of previous programs as i fix.

Here’s a pic of 3 text objects. All are inside ScrollPanes. There’s one SplitPane inside another SplitPane.

Scrollpane inside a splitpane

3 Scrollpane inside a couple splitpanes



# print only lines that DO NOT match a regular expression (emulates ‘grep’)
$ cat | ruby -pe ‘next if $_ =~ /regexp/’

Written by totalrecall

February 17, 2010 at 2:48 pm

Posted in rbcurse

Some thoughts on automated testing of ncurses apps

leave a comment »

My major issue when making changes to code is that existing dependent program break. Typically the break is a UI related break, or a cursor positioning bug. UI means something may not print in the correct position, or may not print at all (thanks to copywin).

My log files contain details of positioning of copywin, and cursor. I can compare these after making changes to see if anything has changed. However, for that i must execute the same keys. Here is where expect can help.
An expect script with some basic key movements should create the same log file after code changes. The main issues with this are the timestamps and object references which i clean out. Also, log files change when i add a debug statement or change the same. But its still a good clue to help me see what’s gone wrong if suddenly a program is printing wierdly, or I am not sure whether this is how program once behaved or displayed its screen.

These issues are however, not with older versions of rbcurse. It’s only the new version with container such as tabbedpanes, splitpanes and scrollpanes which often contain instances of each other. I am also now going to store screenshots of how test programs look when the screen loads so i know after making changes how it once looked.

expect seems to have an issue with the sleep command. It executes all the sleeps before loading the screen and then executes all the keys with no gap. However, my log file should be created okay.

(Makes mental note never to do any programming that cannot be tested automatically!)


Who are you? You have no entry in /etc/utmp! Aborting…

Written by totalrecall

February 8, 2010 at 7:56 pm

Posted in ncurses

Progress on scrollpanes within tabbedpanes (ncurses)

leave a comment »

Thankfully, some progress on the cursor front. These images show a textview. In one case the textview is inside a scrollpane inside a tabbedpane. In the other the textarea is directly inside a tabbedpane.

tabbedpane containing scrollpane with textview widget

TabbedPane with ScrollPane


TabbedPane with TextArea directly placed in it

TabbedPane with TextArea directly placed in it


I am reworking and trying to simplify the cursor placement – a major headache until now with such embedded objects.
In some previous screenshots, scrollpanes were starting display from 1,1 instead of 0,0. Correcting that has resulted in breakage, but helped in simplifying some code. I am really hoping to rewrite scrollpanes and splitpanes with a simpler approach if i can think of one. The ncurses method copywin is a major headache and keeps getting me.

I am hoping to write a splitpane like widget which is more like vim’s splits. So all the splits are on one level. Currently, a splitpane takes only 2 objects. You can embed a splitpane inside another, which is what most examples give. This makes it painful for the user to indicate which splitpane he wishes to expand or contract with a keyboard.

# If you are one of those sorry ba$tards who has to work with python you’ll know what I mean.
URL
— Micha Niskin

Written by totalrecall

February 8, 2010 at 1:16 pm

Posted in rbcurse