Line Editor


Grid Cartographer is supplied with a library of additional functions to perform common tasks. These are available to all Squirrel scripts by adding <load> entries into the hook definition, or by using the include function. Note: hook references should appear before the main script so that the function names, etc. are registered correctly prior to use.


Header | stdio/getline.nut



getline( maxlength:int ): string

A simple line input buffer, up to maxlength characters. It supports backspace, delete, cursor left/right, home and end. Entered lines are stored in a history and can be accessed using the up/down cursor keys. F3 will also restore the last typed line.

The line editor continues until the enter key is pressed. If CTRL+C is pressed, the function returns an empty string. ESC will clear the current line to let you start again.


getlinecb( maxlength:int, callback:function ): string

This is an extended version of getline which operates in the same way, with the addition of executing a callback function repeatedly. The callback is passed a string value containing the current edit buffer contents and must return a boolean value of true to signal the line editor should continue. If the callback returns false the line editor stops and returns null.