Created
December 7, 2013 18:50
-
-
Save fowlmouth/7846962 to your computer and use it in GitHub Desktop.
STFL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* | |
* STFL - The Structured Terminal Forms Language/Library | |
* Copyright (C) 2006 Clifford Wolf <[email protected]> | |
* | |
* This library is free software; you can redistribute it and/or | |
* modify it under the terms of the GNU Lesser General Public | |
* License as published by the Free Software Foundation; either | |
* version 3 of the License, or (at your option) any later version. | |
* | |
* This library is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
* Lesser General Public License for more details. | |
* | |
* You should have received a copy of the GNU Lesser General Public | |
* License along with this library; if not, write to the Free Software | |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
* MA 02110-1301 USA | |
* | |
* example.stfl: STFL Code for example.c | |
* | |
vbox | |
hbox | |
.expand:0 | |
@style_normal:bg=yellow,fg=black | |
label | |
text:'Little STFL example program' | |
label[label one] | |
text[label one text]:"Line number one" | |
label["2nd label"] | |
text[also possible to use : here now]:"Fun! Fun! Fun!" | |
label["quotes are needed for a closing bracket: ]"] | |
text[c_like_names_are_still_recommended_thought]:"Whatever" | |
table | |
.expand:0 | |
@input#style_focus:bg=blue,fg=white,attr=bold | |
@input#style_normal:bg=blue,fg=black | |
@input#.border:rtb | |
@L#style_normal:fg=red | |
@L#.expand:0 | |
@L#.border:ltb | |
@L#.spacer:r | |
label#L | |
text:'Field A:' | |
input | |
.colspan:3 | |
text[value_a]:'foo' | |
vbox | |
.rowspan:2 | |
.expand:0 | |
.border:lrtb | |
label text:'this' | |
label text:'is a' | |
label text:'test' | |
tablebr | |
label#L | |
text:'Field B:' | |
input | |
text[value_b]:'bar' | |
label#L | |
text:'Field C:' | |
input | |
text[value_c]:'Hello'"'"'World!' | |
hbox | |
vbox | |
vbox | |
style_normal:bg=red | |
@label#style_normal:bg=white,fg=black | |
label .tie:tc | |
text:"A rather long test label" | |
label .tie:l | |
text:"Short (left)" | |
label .tie:rb | |
text:"Short (right)" | |
vbox | |
tie:lrb | |
style_normal:bg=blue | |
@label#style_normal:bg=white,fg=black | |
label .tie:c | |
text:"A rather long test label" | |
label .tie:l | |
text:"Short (left)" | |
label .tie:r | |
text:"Short (right)" | |
vbox | |
tie:r | |
style_normal:bg=green | |
@label#style_normal:bg=white,fg=black | |
label | |
text:"A rather long test label" | |
label .tie:l | |
text:"Short (left)" | |
label .tie:r | |
text:"Short (right)" | |
textview[textview] | |
.expand:0 | |
@style_blue_normal:fg=blue | |
@style_red_normal:fg=red | |
@style_bold_normal:attr=bold,attr=underline | |
richtext:1 | |
listitem text:"This is normal text" | |
listitem text:"Normal <blue>blue Text <red>red Text </>normal" | |
listitem text:"Multi line: <blue>first line" | |
listitem text:"this is the 2nd line, still blue" | |
listitem text:"3rd line</>, and normal again!" | |
listitem text:"a smaller-than sign: <>" | |
listitem text:"a greater-than sign: >" | |
listitem text:"<bold>bold text</> normal text" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import locale | |
when defined(LINUX): | |
const libname* = "libstfl.so" | |
type | |
PForm* = ptr object | |
PIpool* = ptr object | |
{.push callconv: cdecl, dynlib: libname.} | |
proc stfl_create* (text: cstring): PForm {.importc.} | |
proc stfl_reset* {.importc.} | |
{.push importc: "stfl_$1".} | |
proc free*(form: PForm) | |
proc run* (form: PForm; timeout: cint): cstring | |
proc set* (form: PForm; name, value: cstring) | |
proc ipool_create* (code: cstring): PIpool | |
proc ipool_flush* (ipool: PIpool) | |
proc ipool_destroy*(ipool: PIpool) | |
{.pop.} | |
{.pop.} | |
when isMainModule: | |
#if (!setlocale(LC_ALL,"")) | |
#fprintf(stderr, "WARING: Can't set locale!\n"); | |
#struct stfl_ipool *ipool = stfl_ipool_create(nl_langinfo(CODESET)); | |
let ipool = ipool_create(getLocaleName()) | |
#struct stfl_form *f = stfl_create(L"<example.stfl>"); | |
let f = stfl_create("<example.stfl>") | |
#stfl_set(f, L"value_a", L"This is a little"); | |
set(f, "value_a", "This is a little") | |
#stfl_set(f, L"value_b", stfl_ipool_towc(ipool, "test for STFL!")); | |
set(f, "value_b", "test for STFL!") | |
#stfl_ipool_flush(ipool); | |
ipool_flush(ipool) | |
#const wchar_t *event = 0; | |
#while (!event || wcscmp(event, L"ESC")) | |
# event = stfl_run(f, 0); | |
var event: cstring | |
while event.isNil or ($event != "ESC"): | |
event = run(f, 0) | |
#stfl_reset(); | |
stfl_reset() | |
#printf("A: %ls\n", stfl_get(f, L"value_a")); | |
#printf("B: %ls\n", stfl_get(f, L"value_b")); | |
#printf("C: %s\n", stfl_ipool_fromwc(ipool, stfl_get(f, L"value_c"))); | |
#stfl_ipool_flush(ipool); | |
free(f); | |
ipool_destroy(ipool); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment