The Accidental Rubyist

invalid byte sequence in UTF-8

Implementing a multi-line entry field in ncurses

leave a comment »

I have uploaded the code for RubyCurses onto http://github.com/rkumar/rbcurse/tree/master.

Please note that it will take a week or so for the code to be usable, I have not yet saved the form data as yet, only entered and edited.

Just some thoughts on ML fields. There are various approaches to doing this that came in mind.

1. python has a sample called textpad.py. This sample places characters that are input onto the window. At the end of editing, it takes the characters from the window and puts it into a String.

This suffers from some problems:

a. no insert mode, one is always overwriting what was written

b. we cannot exceed the size of the window.

A simple workaround for this is to use pads. However, again, a pad’s dimensions have to be defined at creation time. So when we run out, we would have to recreate a larger pad. Again the insert/overwrite issue has to be worked around.

2. Using a string: This is the first option that comes to mind. However, inserts and deletes at the start of a long string can be inefficient (I think). Line management could be tricky.

3. Using an array. I opted for this approach and its worked out as yet. Deleting till end of line, deleting lines, inserting lines, joining lines is very simple.

However, for critical purposes, or large files it would always be recommended to invoke vim, nano etc. This is intended to be simple and not a word-processor by itself.

If anyone has thoughts on this topic, would like to hear.

Advertisements

Written by totalrecall

November 25, 2008 at 3:12 pm

Posted in ncurses, rbcurse

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: