Implementing a multi-line entry field in ncurses
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.