2
##########################################################################
4
# STFL - The Structured Terminal Forms Language/Library #
5
# Copyright (C) 2006 Clifford Wolf <clifford@clifford.at> #
7
# This program is free software; you can redistribute it and/or modify #
8
# it under the terms of the GNU General Public License as published by #
9
# the Free Software Foundation; either version 2 of the License, or #
10
# (at your option) any later version. #
12
##########################################################################
15
STFL - Structured Terminal Forms Language/Library
16
=================================================
18
STFL is a library which implements a curses-based widget set for text
19
terminals. The STFL API can be used from C, SPL, Python, Perl and Ruby. The
20
public STFL API is only 14 simple function calls big and there are already
21
generic SWIG bindings. Thus is very easy to port STFL to additional scripting
24
A special language (the Structured Terminal Forms Language) is used to
25
describe STFL GUIs. The language is designed to be easy and fast to write
26
so an application programmer does not need to spend ages fiddling around
27
with the GUI and can concentrate on the more interesting programming tasks.
29
There are two different syntaxes for STFL code, one designed to make
30
handwriting of STFL code as easy as possible and one aiming at generated
33
The STFL GUI descriptions (written in STFL code) do not contain any concrete
34
layouting information such as x/y coordinates of widgets. Instead container
35
widgets such as vertical and horizontal boxes as well as tables are used to
36
group widgets and the actual layouting work is done by the STFL library. Thus
37
STFL GUIs can handle terminals of different sizes and terminal resize events
38
transparently for the application programmer.
41
Building and Installing STFL
42
----------------------------
44
Simply run 'make' and 'make install'. You might want to edit the Makefile.cfg
45
file before building and installing STFL.
48
The Structured Terminal Forms Language
49
--------------------------------------
51
STFL Forms consist of (instances of) widgets which are organized in a tree. A
52
special language - the Structured Terminal Forms Language - can be used to
53
describe such trees in an efficient and still easy to read and maintain way.
55
The Structured Terminal Forms Language has only two syntactical constructs:
56
Variable declarations and widget instanciations. Each widget instanciation
57
may contain variable declarations and child widget instanciations.
59
A widget can be instanciated by simly writing down the type of the widget.
64
Sometimes one wants to give the instanciated widget a name so the widget
65
can be easily accesed later. This can be done by appending the widget name
66
using square brackets:
70
Child widgets are instanciated the same way but must be indented:
76
Note that one must not use tabs for the indenting. Only blanks are allowed.
78
Variables are declared like child widgets. A variable consists of a key and
79
a value, seperated by a colon. Values can be quoted using single or double
80
quotes when they contain blanks.
86
text:"This is a test.."
88
It is also possible to append an additional name to variables using square
89
brackets so the application can read and write the variable value:
93
text[label1_text]:"Hello World!"
95
text[label2_text]:"This is a test.."
97
Usually variables configure the widget they are directly associated with or
98
store status information from that widget. But sometimes variables contain
99
information about the relationship of the widget they are directly associated
100
with and its parent widget. This variables are always start with a dot.
102
Example given the .border variable can be used to configure the borders of
113
Sometimes one wants to set a variable not only for the current widget but also
114
for all its child widgets. This can be done by prefixing the variable name
115
with he at-sign. Example given:
118
@style_normal:fg=white,bg=blue
122
text:"..on blue background."
124
This kind of variables can also be defined for only one widget type:
127
@style_normal:fg=white,bg=blue
128
@input#style_normal:fg=black,bg=red
130
text:"White text on blue background."
132
text:"Black text on red background."
134
Alternatively it is possible to postfix the widget types with '#classname'
135
and prefix the variables with 'classname#':
138
@style_normal:fg=white,bg=blue
139
@foobar#style_normal:fg=black,bg=red
141
text:"White text on blue background."
143
text:"Black text on red background."
145
While widget instanciations must alsways be on a new line, variable declarions
146
can also be written on the same line as the widget they are for and it is
147
possible to declare more than one variable in one line:
150
label .border:lrtb text:"Hello"
152
.border:lrtb text:"World!"
154
Sometimes one wants to generate STFL code from scripts. In this cases it can
155
become hard to automatically generate the indenting correctly. For such
156
situations it is possible to use a different format with curly brackets. The
157
following two code fragmentsa are identical:
173
{vbox{hbox{label .expand:0 text:"Foo: "}{input[foo] text:"Hello"}
174
{hbox{label .expand:0 text:"Bar: "}{input[bar] text:"World!"}}}
176
Newline characters are not allowed inside of an STFL code fragment in curly
177
brackets (the example above is just broken up in two line to improve the
178
readability). It is even possible to embed an STFL code fragment in curly
179
brackets in a normal indented code block. Example given:
182
{hbox{label .expand:0 text:"Foo: "}{input[foo] text:"Hello"}}
183
{hbox{label .expand:0 text:"Bar: "}{input[bar] text:"World!"}}
185
It is also possible to include the focus information in STFL code: Simply
186
prefix the widget which shall have the focus with a '!'. Only one widget
187
may have the focus at a time.
189
The STFL parser can also read external files. This can be done by putting the
190
filename in < > brackets in the STFL file. Note that this is not a varbatim
191
include but calls another parser instance recursively. So there is an extra
192
indenting / curly brackets state for the external file.
194
Comment lines in STFL code start with a '*' character. There must be no
195
statement in the same line as the comment (i.e. only whitespaces are allowed
196
before the '*' character). Comment are not allowed within a code fragment
200
The STFL Style Descriptions
201
---------------------------
203
STFL is using a generic syntax whenever the style (color, etc.) of a text
204
can be specified: A comma seperated key=value list, where the key can be
205
'bg' for background, 'fg' for foreground and 'attr' for text attributes.
206
Example given the following style string can be used for creating bold
207
blinking white text on blue background:
209
bg=blue,fg=white,attr=bold,attr=blink
211
The following colors are supported:
222
And the following attributes:
233
The terminal default colors are used when no background or no foreground color
234
is specified. So keep care when only specifying one value. Example given text
235
printed using the style string 'fg=white' can't be seen on terminals with a
236
white default background.
239
The STFL Widget Library
240
-----------------------
245
This widgets simply layouts its child widgets vertically or horizontally
246
repectively. The following variables are supported by both widgets:
249
The background style.
252
Tie the box containing the widgets to the specified borders.
253
The value is a string containing the characters 'l' (left
254
border), 'r' (right border), 't' (top border), 'b' (bottom
255
border) and 'c' (center). The default value is 'lrtb'.
258
Tie this widget within its sub-box to the specified borders.
259
The value is using the same syntax as the "tie" variable above.
262
Contains the information if child widgets should be expanded
263
to fit the available space. The value is a string that may
264
contain the characters 'v' (for vertical expansion), 'h' (for
265
horizontal expansion) and '0' (for no expansion).
267
The hbox widget ignores the vertical expansion information and
268
the vbox widget the horizontal expansion information.
270
The default value is 'vh'.
273
Hardcode the height of this child widget to the specified
274
number of lines. Usually one wants to also declare .expand:0
275
when declaring this variable.
278
Hardcode the width of this child widget to the specified
279
number of characters. Usually one wants to also declare
280
.expand:0 when declaring this variable.
285
A simple text label. The following variables are supported by this widget:
288
The style used for displaying the text.
291
The text to be displayed
296
A simple input widget for one line of text input. The following variables are
297
supported by this widget:
300
The style of this widget when it does not have the
304
The style of this widget when it does have the focus.
307
The value displayed in the input box.
310
The current cursor position in the input box.
313
The offset of the text displayed in the input box
314
(when the text is larger then the input box).
319
The most important container widget. The special widget 'tablebr' is used to
320
mark the begin of a new table row. The following variables are supported by
324
The style for the table bordes.
327
Contains the information if child widgets should be expanded
328
to fit the available space. The value is a string that may
329
contain the characters 'v' (for vertical expansion), 'h' (for
330
horizontal expansion) and '0' (for no expansion).
332
Since there is just one width for all cells in a column and
333
just one height for all cells in a row it still may happen
334
that cells are expanded a bit.
336
The default value is 'vh'.
339
Hardcode the height or .width of this table cell to the
340
specified number of characters. Usually one wants to also
341
declare .noexpand:1 when declaring one of this variables.
344
The number of columns or rows for this cell. Default is '1'.
347
The borders for this cell. This is a string which may contain
348
the characters 'l', 'r', 't' and 'b' for left, right, top and
352
Like .border, but only adds a spacer between the cells.
355
Tie this table cell within its box to the specified borders.
356
The value is a string containing the characters 'l' (left
357
border), 'r' (right border), 't' (top border), 'b' (bottom
358
border) and 'c' (center). The default value is 'lrtb'.
368
DOCUMENTME (Not implemented yet)
373
DOCUMENTME (Not implemented yet)
378
DOCUMENTME (Not implemented yet)
383
DOCUMENTME (Not implemented yet)
388
DOCUMENTME (Not implemented yet)
391
The Common STFL Scripting Language API
392
--------------------------------------
394
STFL has a big C-API which allows a wide range of in-depth operations on
395
widget trees. But most of this C-API is only needed for writing new STFL
396
widgets. The common STFL scripting language API only has a small number of
397
functions and besides the 'form handlers' this functions do only operate
398
on read-only scalar values, so it is pretty easy to write additional bindings
399
for scripting languages not yet supported by STFL.
404
All functions listed here are also available thru the STFL C-API.
406
All strings returned by stfl functions are constant and must not be freed or
407
modified by the caller. When the caller wants to preserve a string for longer
408
than until the next stfl function call the caller must copy the strings.
410
All strings passed to STFL functions are considered read-only by STFL and
411
are neither modified nor freed by STFL.
413
The functions which may return an undefined value will return a null-pointer
414
in C. All string parameters which are null-pointers are interpreted as they
420
The stfl_free() function is not implemented in SPL because the SPL garbage
421
collector does call the low-level STFL free function automatically. The
422
stfl_reset() function is automatically called when the STFL module is unloaded
423
(i.e. on program termination).
425
The stfl_quote() function can also be called using the name encode_stfl() so
426
it can be used with the SPL encoding/quoting operator (::).
431
The stfl_free() function is not implemented in Python because the garbage
432
collector does call the low-level STFL free function automatically. The
433
stfl_reset() function is automatically called on program termination.
435
The functions which take a form as first parameter can also be called as method
436
of the form. All functions are in the "stfl" namespace, so the "stfl_" prefix
437
for the function names is replaced with "stfl." in python.
442
The stfl_free() function is not implemented in Perl because the garbage
443
collector does call the low-level STFL free function automatically. The
444
stfl_reset() function is automatically called on program termination.
446
The functions which take a form as first parameter can also be called as method
447
of the form. All functions are in the "stfl" namespace, so the "stfl_" prefix
448
for the function names is replaced with "stfl::" in perl.
453
The stfl_free() function is not implemented in Perl because the garbage
454
collector does call the low-level STFL free function automatically. The
455
stfl_reset() function is automatically called on program termination.
457
The functions which take a form as first parameter can also be called as method
458
of the form. All functions are in the "Stfl" namespace, so the "stfl_" prefix
459
for the function names is replaced with "Stfl." in ruby.
464
Parses the the STFL description text passed as parameter and returns a form
465
handler. Most of the following functions expect such a form handler as first
471
Free all resources associated with this form. On languages with a garbage
472
collector calling this function is optional and might even be implemented
475
stfl_run(form, timeout)
476
~~~~~~~~~~~~~~~~~~~~~~~
478
Return the next event. If no more prior generated events are waiting display
479
the form and process one input character. The following events are generated
480
directly by the STFL core:
483
The timeout has been reached.
486
The return key has been pressed.
489
The escape key has been pressed.
492
A function key has been pressed.
494
The 2nd parameter is a timeout in ms. When no key has been pressed until this
495
timeout has been reached. Set this parameter to 0 to disable the timeout.
497
When the timeout parameter is set to -1 the form is displayed independent of
498
the current status of the event queue and the function returns right after
499
displaying the form without handling any input characters. In this mode always
500
an undefined value is returned.
505
The stfl_run() function automatically activates ncurses. This function
506
can be used to explicitely switch back to normal text mode. In some
507
languages this is automatically done on program termination.
512
Returns the current value of the specified variable. When the variable does not
513
exist this function returns an undefined value.
515
stfl_set(form, name, value)
516
~~~~~~~~~~~~~~~~~~~~~~~~~~~
518
This sets the specified variable to the specified value.
523
Returns the name of the widget which currently has the focus or an undefined
524
value when the widget having the focus has no name.
526
stfl_set_focus(form, name)
527
~~~~~~~~~~~~~~~~~~~~~~~~~~
529
Set the focus to the specified widget.
534
Quote the text so it can be savely used as variable value in STFL code.
536
stfl_dump(form, name, prefix, focus)
537
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
539
Return the subtree starting with the widget specified in the 2nd parameter as
540
STFL code fragment. The entire form is return when the 2nd parameter is an
541
empty string or undefined. All widget and variable names in the dump are
542
prefixed with the string in the 3rd parameter. The information which widget has
543
the focus is also included in the dump when the 4th parameter is an integer
546
The function returns an undefined value when there was an error.
548
stfl_modify(form, name, mode, text)
549
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
551
Import the STFL code specified in the 4th parameter to an existing form. The
552
2nd parameter is used to specify a widget which is used as starting point for
553
the modification. The 3rd parameter is a string specifying how the new STFL
554
code should be added to the widget tree:
557
Replace the widget in the tree with the new tree.
560
Replace the child list of the widget with the child list
561
of the root element of the new tree.
564
Add the new tree at the begin of the child list of the widget.
567
Add the child list of the root element of the new tree at the
568
begin of the child list of the widget.
571
Add the new tree at the end of the child list of the widget.
574
Add the child list of the root element of the new tree at the
575
end of the child list of the widget.
578
Add the new tree before the widget.
581
Add the child list of the root element of the new tree before
585
Add the new tree after the widget.
588
Add the child list of the root element of the new tree after
591
The replace mode simply deletes the widget and the replace_inner mode deletes
592
all existing childs of the widget when an empty string is passed as 4th
595
stfl_lookup(form, path, newname)
596
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
598
Lookup widgets in the form using a path and optionally assign a new name.
600
This function is not implemented yet.
605
Return the error status of the last STFL call. This is undefined when no error
606
occoured and the error message otherwise.
608
stfl_error_action(mode)
609
~~~~~~~~~~~~~~~~~~~~~~~
611
Set the error handling algorithm. The following strings are valid as mode
615
Print error message to stderr and call the abort() function.
618
Print error message to stderr and call exit(1).
621
Print error message to stderr and continue execution.
624
Display a little menu and let the user decide what to do.
627
Do nothing - just continue program execution.
629
The default mode is "interactive".
638
Event Handler Variables
639
-----------------------
641
DOCUMENTME (Not implemented yet)
653
- Implement so far unimplemented widgets
654
- Common 'on*' event handler variables
655
- Missing error handling and reporting
656
- Implement stfl_lookup() function