The Accidental Rubyist

invalid byte sequence in UTF-8

Archive for March 2010

branch renaming woes

leave a comment »

I did some renaming, but after pushing to github the old branches are still there. Some merge headaches too.

If you are looking for the old 1.8.x version (earlier called master), its now branch classic18.
I’ve renamed rfed16 to master19 and then tried to merge it into master. Managed a manual merge, but it still shows differences between master and master19, if i try manually changing master19, it complains of conflicts.
So basically, i can’t work on master19 and keep merging back to master. My only option is to make a new branch from master, and keep merging from that (hopefully it will not complain). Also, i hope master has everything up-to-date.

Used git mergetool –tools=vimdiff for merging. opendiff confused me totally not showing me the conflict, although reporting it below.


Tech Support:
“No sir, that is not hackers taking over your computer every 10 minutes, that’s what we call a screen saver.”

Advertisements

Written by totalrecall

March 20, 2010 at 8:37 pm

Posted in rbcurse

Scrolling Form in ruby ncurses

leave a comment »

I’ve just added a Scrolling Form (class ScrollForm). This allows us to create a form that takes a lot more space than the physical screen. A multi-page data entry screen can be implemented using one ScrollForm. The user can just scroll down or right to get to other fields.

It extends Form with a couple of changes:

* Using a Pad to write on instead of Window
* Extending focusable() to include visible?(), so only visible components get focus
* Scroll Keys (M-l, h, n, p) are used to pan the screen vertically or horizontally

This component is in its infancy, need to take care of multi-line components. The demo is am working on is in examples/testscroller.rb

I think this is the last of the new components or widgets I have in mind. Now just to test out and make some more demos. And keep releasing patches or minor optimizations.
The next component will likely be the Tree Component, but that will be in another round of development perhaps 3-4 months down, not earlier.


# Instead of defining a local variable with some initial content (often just an empty hash or array), you can instead define it “on the go” so you can perform operations on it at the same time:

(z ||= []) << 'test'


http://www.rubyinside.com/21-ruby-tricks-902.html

Written by totalrecall

March 16, 2010 at 5:59 pm

Posted in rbcurse

Multiple object containers in ruby rbcurse

leave a comment »

I’ve introduced a simple container called MultiContainer. One can add multiple components to it, and it displays on component at a time. One can then cycle through components, add and delete components etc.
These components could be different widgets such as textareas, tables, lists etc.

An example of where one might use this is again a kind of SQL client in which there are several resultsets. One can create a TabbedPane with tabs for each resultset, or a MultiContainer with textviews. Currently, since the components can be editable, I’ve mapped M-: to the menu which gives options for iterating, listing, deleting components. M-: is a little cumbersome, so I might change it later.

I find MultiContainer and MultiTextView to be simple containers unlike TabbedPane which is quite involved. So its light, simple to setup and easy to maintain. These 2 containers allow us to save a lot of screen space.
For a demo of this, please see examples/testmulticomp.rb

Written by totalrecall

March 15, 2010 at 9:51 pm

Posted in rbcurse

vim like editing optional in a TextView

leave a comment »

For simple editing inside a TextView, I’ve mapped various editing functions to vi keys. I’ve done this as a module so it can be included at runtime in a TextView instance rather than extending the TextView class.

This editable version of TextView does editing only through keystrokes – there is no edit mode. On pressing C to change a line, or o or O etc a box is displayed at the bottom for editing or entering text which is then updated. Unlimited undo and redo, of course. I am also using the emacs like kill-ring here, so deletes and copies can be cycled through using M-y. C-y works for the current (last) copy. P and p are also usable. For an example, see examples/testscrollp.rb. You can test with a “dd”, “4dd”, “5dw”, “p”, “u” (undo) or C-_ (undo), C-r (redo), “x”, “5x”, “X”, df (char), “yy”, C (change line), o (open a line).

For a full proper editor, you would continue to use TextArea. However, being an edit mode editor, TextArea is unable to provide mapping for most vim keys which are single keys, thus i’ve used some emacs keys in TextArea. Since TextView is non-editable one can put it into “command-mode” and use most vim keys.

rbcurse is for geeks anyway, or atleast keyboard lovers, so lets make rbcurse a keyboard friendly ncurses library.

I’ve now started adding all key binding functionality to proper key bindings (instead of hard-coding them in the key checking loop of a component). Soon, when I’ve organized my thoughts, we should be able to use something like emacs’s “M-x” which (I think) allows a user to see what all functions he can use for an object and execute them, or bind them to a key.

Written by totalrecall

March 12, 2010 at 7:33 pm

Posted in rbcurse

Textview gets multiple buffers

leave a comment »

I should be testing and bringing out a stabler release, but can’t resist adding more. I’ve extended TextView so one can have multiple buffers open and cycle between them. The motivation is that often instead of a tabbedpane, we might want to just have many documents open. This is much easier. An application is an SQL client, where i have multiple resultsets and I want to cycle between resultsets and not keep rerunning queries.

I’ve mapped in the new Most-style menu to “:” so buffer navigation can happen on “:bp” “:bn” etc as in vim. “e” and “C-x f” allow opening a new file (buffer). The Most-style menu is a simple, cute menu just like the application most has. Easy to set options and suboptions, and attach Procs or symbols to execute. I’ve called it PromptMenu since it prompts for selection. Using a Prompt menu means the user does not have to remember keys, just pressing “:” will bring up a menu.

This component is called MultiTextView and extends TextView. I’d like to actually make it a module, so TextArea and Listbox and Table can just include it and get all the functionality without my having to extend it for each.

Written by totalrecall

March 11, 2010 at 9:00 pm

Posted in rbcurse

ruby TabbedPane new features – unlimited tabs

leave a comment »

ruby rbcurse now has a slightly better tabbedpane. Essentially, one can add as many Tabs as one needs.
Traversal will only take focus to visible tab buttons. While on the button form, M-l and M-h will scroll horizontally and being other tabs (buttons) in to view and focus. The test program examples/testtpane.rb can be tried out. While on the button form, press M-x several times. This is bound to a block that opens a new tab with a text object inside.
(for the moment, just press a left or right key to repaint the form). If you’ve got more buttons that can be displayed test out traversal with the TAB key. Now use M-l to bring the off-screen buttons into view.

Backtabbing from a form will bring focus onto the last visible button. Similarly, tabbing off the last field of a form will take focus to the first visible button of the button panel.

To make this possible, I’ve extended the old Form class and made a ScrollForm that contains a Pad instead of an Ncurses::Window. This class extends some methods of form to check for whether a field is visible or not. It also resizes the Pad, if a widget is created that falls outside the width or height. This new class has only been tested with the button panel which has a height of 1, and no rows. So it’s not tested with a form that contains many rows! I need to separate it and start testing it in various situations, so we can have multi-page forms in curses using only one form.

Written by totalrecall

March 4, 2010 at 12:17 pm

Posted in rbcurse

Rewrite of Tabbedpane

leave a comment »

As promised, a much cleaner version of TabbedPane, makes sense. One may add components directly without creating a form. When a component is added directly, the Tabbedpane can resize and position the component appropriately.
However, TabbedPane does not create a Pad-based form like it earlier did by default. If we wish to place multiple components in a TabbedPane we need to call TabbedPane.form(tab) passing the tab.

Pressing a down arrow on the buttons above, takes focus to the tab below. Also, there is the option of displaying the tab as we traverse through the buttons. This mimics MicroEmacs behavior in User Setup. Otherwise by default, tabbedpanes behave like Terminal’s Preference Pane (in OSX) – we have to press a button, or use hotkey for tab to be displayed.

I still have to work on handling more buttons that can be seen on the tabbedpane component, much like Firefox.

Syntax for adding a tab is now:

tab1 = tp.add_tab “&TextView”, textview

The above requires textview to be created before the call. ALternatively, one can add the component later.

tab1 = tp.add_tab “&TextView”
# create textview here
tab1.component = textview

Written by totalrecall

March 2, 2010 at 12:53 pm

Posted in rbcurse