fix types for ARM support; fix errno handling; minor fixes; license GPL3 or later fix
[guish.git] / README.md
blobd7eda97afd3b542f0e880bc91a3ebf4f24fb772d
1 # NAME
3 guish - A language to make and modify GUIs
5 # SYNOPSIS
7 **guish** \[**-c**
8 \<code\>\]\[**-s**\]\[**-q**\]\[**-k**\]\[**-t**\]\[**-f**\]\[**-v**\]\[**-b**\]\[**-h**\]\[\<file\>\]\[\<arguments\>\]
10 # DESCRIPTION
12 **guish** is a language to create and modify GUIs; it can be used to tie
13 different programs together by embedding, or to make simple GUIs.
15 This is version 2.x, which depends just on Xlib as all toolkits have
16 been removed (there are some optional dependencies).
18 # OPTIONS
20 **-c \<code\>**
22 :   read and execute commands from command line.
24 **-s**
26 :   display elements when created.
28 **-q**
30 :   quit when closing last element/window.
32 **-k**
34 :   terminate all external programs when quitting.
36 **-t**
38 :   fallback on tty after reading data from other inputs.
40 **-f**
42 :   show available X11 fonts.
44 **-v**
46 :   show version.
48 **-b**
50 :   show build (compiled in) options.
52 **-h**
54 :   guess.
56 # INPUTS AND SOURCES
58 guish reads commands from multiple source sequentially; these source
59 are: command line (with **-c** option), file, standard input, and if
60 **-t** option is given, controlling terminal. After reading commands
61 from a source, it tries to switch to another one, and when there are no
62 more sources, it simply stays idle.
64 After executing from file or command line or standard input, then
65 finally it switchs to controlling terminal (if **-t** option is given)
66 and executes from there.
68 If the file given is a named pipe, then it will be opened in
69 non-blocking mode, allowing to issue commands from the other end of the
70 pipe.
72 # SYNTAX OVERVIEW
74 Being a command interpreter, guish has a little set of syntax rules.
75 They comprises expressions, commands, quotes and special operators.
76 Generic commands and signals are common to all elements, while there are
77 ones which are specific to each element. A phrase is the execution unit,
78 and ends if the program encounters a newline-like character, or a
79 semicolon (\";\").
81 ## Comments
83 Single line comments begin with a **\#**, and end at newline like
84 character:
86      a = 4 # this is a comment
88 Multiline comments instead are embedded inside **#\[** and **\]#** (or
89 end at the end of source):
91      a = 4 #[ This,
92      is a multiline comment,
93      ending here. ]# puts "a: @{a}"
95 ## Elements and element expressions
97 Elements are basically widgets and have some commands and signals
98 associated with them; they can be created using element expressions,
99 enclosing element name within **\|\|**:
101      |b|+
103 In this example, \"\|b\|\" is an expression which creates an element of
104 type button, and returns its X11 window id (ex, \"65011718\").
106 The **+** command will then show the button (all elements are hidden by
107 default unless **-s** option is given).
109 ## Subject and implied subject
111 To refer to the last created/modified element, you can use it without
112 naming it explicitly, for example:
114      |i|;+
116 The \"+\" command will by applied to element created by \"\|i\|\"
117 expression automatically.
119 ## Variables and variable substitution
121 We can refer to elements by using variable substitution, instead of
122 using their window ids:
124      bt = |b|
126 and then:
128      @bt < "new button"
130 ## Commands
132 Commands instead can be of three distinct types: special, generic and
133 normal.
135 Special commands are meant to change guish behaviour, generic ones are
136 meant to modify an element of any type and normal ones are for a
137 specific element type (every element can have specialized commands).
139 ## Signals
141 Signals make it possible to run actions on UI changes (or, more
142 generally, on some events).
144      |b|=>c{run free}
146 Here, the user creates a button that when clicked will make guish
147 execute a system command (free in this case) (see **run** in SPECIAL
148 COMMANDS).
150      |b|<generator =>c{|b|<clone}
152 A button which is a factory of buttons (run this with **-s** option).
154 Here the evaluation of the code block is done when the click signal is
155 triggered.
157 ## Scopes and closures
159 All variables (functions too, as blocks can be assigned to variables)
160 have a specific scope:
162      a = 1
163      {b = 2}()
164      puts "@{a}:@{b}"
166 Here the variable \"a\" is defined in the global scope, while \"b\" is
167 defined in a temporarily block scope; hence just \"a\" is printed to
168 stdout.
170 When accessing reading/defining a variable in a local scope, if the
171 variable is already defined in the enclosing scope then that variable is
172 picked to be read/modified:
174      a = 1
175      {
176          a = 5
177          puts@a
178      }()
179      puts@a
181 Here \"a\" is defined in the global scope, then modified from block
182 scope and printed from there, and its value doesn\'t change.
184 If a variable is defined inside a block, then all embedded blocks that
185 reference that variable will get its value at definition time (a
186 closure):
188      {
189          a = 1
190          return {
191              puts @a
192          }
193      }()()
195 ## Quotes, blocks and functions
197 There are single and double quoting: anything embedded inside single
198 quotes \'\', is treated literally (no escaping takes place) and as a
199 single token.
201 Variable and function interpolations (respectively via \"**\@{\...}**\"
202 and \"**@(\...)**\") are used inside double quotes \"\", external
203 command substitution quotes \`\` and external window id substitution
204 **\<(\...)**.
206 Escaping (\"\\n\\t\\r\\f\\v\\b\") takes place only inside double quotes
207 \"\".
209      a = 'my string'; puts "this is:     @{a}"
210      puts "sum of 1 + 5 is: @(add(1, 5))"
212 Anything embedded inside **{}** is treated as a code block and no
213 variable substitution is done at definition time.
215 To \"execute\" a block, simply use parens **()**. If arguments are
216 given, they can be referenced inside block by using **\@n**, where \"n\"
217 is a number which represents a specific argument by position, with
218 indexes starting at 1 (works with command line parameters too). To refer
219 to all arguments (at once) given to the block use **@\*** operator (when
220 in string interpolation, argument separator is a space).
222      v = myvar
223      a = {puts "here is @{v}"}
224      a()
226 Here the variable \"v\" is not substituted when assigning the block to
227 \"a\"; it\'s substituted later, when function \"a\" is called.
229      {
230          puts join("string length is: ", len(@1))
231      }("home")
233 Here instead, the block is defined and executed immediately, using
234 \"home\" as the first argument.
236 Being a block a piece of code, it can be used to define functions by
237 simply being assigned to a variable:
239      fn = {return add(@1, @2)}
240      puts join("my func res:", fn(2, 4)) 
242 In addition, when defining a new function, it\'s possible to
243 \"overwrite\" the builtin functions in the current scope.
245 When returning from a function, instead, it\'s possible to return
246 multiple arguments (the remaining phrase) to the caller:
248      fn = {return 1 2 3}
249      puts join(fn())
251 ## Conditionals
253 Anything equal to 0, \"0\" or empty (like **\'\'**, **\"\"**, **{}**) is
254 false, true otherwise. This is useful with **if** and **else** commands:
256      if 1 { |b|<text } else { |b|<neverhere }
260      if ge(@a,4) { |l|<4 }
262 ## Loops and iteration
264 Here an example of a **while** loop:
266      a = 1
267      after 4 {a = 0}
268      while {eq(@a, 1)} {
269          wait 1 puts 'true'
270      }
271      puts 'end'
273 And here another one using **each** function:
275      each({puts @1}, 1, 2, 3, 4, 5})
277 And another one of a **for** loop:
279      for x in 1 2 3 4: { puts @x }
281 ## Tail recursion optimization (TCO)
283 Since **2.2.1** version, guish supports tail recursion optimization too,
284 effectively turning a tail recursive function into a loop:
286      upto = {
287          if gt(@1, @2) {
288              return
289          }
290          puts @1
291          return upto(add(@1, 1), @2)
292      }
293      upto(1, 7)
295 To use TCO, the last phrase of a function must use **return** command
296 directly (not inside another block like if-else).
298 ## External window id substitution
300 Everything inside **\<( )** is recognized as an external command (X11
301 GUI), forked and executed, and its window id is substituted (using
302 \_NET_WM_PID).
304 Note that this method will not work with programs that fork.
306 For example:
308      a = <(xterm)
310 xterm program is spawn, and can be driven (almost) like a normal
311 element.
313 ## External command substitution
315 Everything inside **\`\`** is recognized as an external command and
316 executed. Then the command output (STDOUT) is substituted inside source
317 code and interpreted after that.
319 For example:
321      |b|<`echo clickme`
323 ## Slicing
325 Anything inside **\[\]** is trated as a slice expression. The usage is
326 **\[\<n\>\[,\<x\>\]\]**, when \<n\> is an index, and \<x\> is an
327 optional end index (always inclusive); if the preceding argument is a
328 regular token, then the expression will return its characters as
329 specified by index(es), otherwise if it\'s a block, the expression will
330 return its tokens:
332      puts {1, 2, 3, 4, {a, b}, cat}[4][1]
334 The output of this example is \'b\'.
336 If the index(es) given are out of range, an empty token is returned.
338 # SPECIAL VARIABLES
340 **SW**
342 :   primary screen width, in pixels.
344 **SH**
346 :   primary screen height, in pixels.
348 **X**
350 :   pointer\'s x coord.
352 **Y**
354 :   pointer\'s y coord.
356 **self**
358 :   variable holding the window id when in signal code.
360 **args**
362 :   refers to the block in which there are positional arguments and
363     function arguments (alternative syntax).
365 **FILE**
367 :   variable holding the path of current source file.
369 **LINE**
371 :   variable holding current line number at \"that\" point in source
372     code.
374 # ENVIRONMENT VARIABLES
376 **GUISH_MAXWIDWAIT**
378 :   the maximum number of seconds to wait when applying external window
379     id substitution (defaults to 3 seconds)
381 # ELEMENTS
383 Available elements are:
385 **b**
387 :   A button.
389 **i**
391 :   An input box.
393 **l**
395 :   A label.
397 **p**
399 :   A page (container of other elements; show and hide are applied to
400     all subelements).
402 **c**
404 :   A checkbox.
406 **t**
408 :   A label with a totally transparent background (requires a
409     compositor).
411 # SPECIAL COMMANDS
413 Special commands are not tied to elements, they are like statements.
415 **=\> \<signal\> \<subcmd\>**
417 :   register a sub-command \<subcmd\> to run when \<signal\> triggers.
418     For normal signals (eg. signals tied to elements), there must exist
419     an implied subject.
421 **!\> \<signal\>**
423 :   unregister a sub-command \<subcmd\> previously registered on signal
424     \<signal\>.
426 **q**
428 :   quit guish (exit status 0).
430 **exit \<status\>**
432 :   quit guish (exit status \<status\>).
434 **cd \<path\>**
436 :   change current working directory using \<path\>.
438 **run \<cmd\>**
440 :   execute shell command \<cmd\>.
442 **puts \[\<\...\>\]**
444 :   prints remaining phrase to stdout with a newline added.
446 **p \[\<\...\>\]**
448 :   prints remaining phrase to stdout.
450 **e \[\<\...\>\]**
452 :   prints remaining phrase to stderr.
454 **unset \<name\|num\|wid\> \[\<attr\>\]**
456 :   unsets a variable (\<name\>) or timed scheduled procedure registered
457     with \<num\>, see **every** command. If, instead of \<name\|num\>,
458     an element id \<wid\> is given and a name attribute \<attr\> is
459     given, deletes that element attribute.
461 **source \<file\>**
463 :   execute commands from file.
465 **vars \[\<wid\>\]**
467 :   shows all variables present in the current scope or, if \<wid\>
468     element id is given, shows all element attributes (uses stderr).
470 **ls**
472 :   display all existing widgets (stderr).
474 **del \<wid\>**
476 :   delete a widget with id \<wid\>.
478 **every \<seconds\> \<block\>**
480 :   schedule \<code\> to run after \<seconds\> seconds are elapsed.
482 **after \<seconds\> \<block\>**
484 :   schedule \<block\> to run once after \<seconds\> seconds are
485     elapsed.
487 **wait \<seconds\>**
489 :   stop command execution and wait \<seconds\> seconds before resuming
490     (accepts decimal values too). XEvent handling, schedules actions and
491     signal execution are unaffected by this option.
493 **if \<condition\> \<block\>**
495 :   executes \<block\> if condition evaluates to true (see
496     Conditionals).
498 **unless \<condition\> \<block\>**
500 :   executes \<block\> if condition evaluates to false (see
501     Conditionals).
503 **else \<block\>**
505 :   executes \<block\> if last conditional command was successful (see
506     Conditionals).
508 **return \<phrase\>**
510 :   when used inside a function, returns all its arguments (the
511     remaining phrase) to the caller.
513 **while \<condition\> \<block\>**
515 :   executes \<block\> until \<condition\> evaluates to true (see
516     Conditionals).
518 **until \<condition\> \<block\>**
520 :   executes \<block\> until \<condition\> evaluates to true (see
521     Conditionals).
523 **for \[\<var1\>, \<var2\>, \...\] in \[\<val1\>, \<val2\>, \...\] : \<block\>**
525 :   executes the block \<block\> for each group of variables.
527 **break**
529 :   exit from current loop.
531 **rel \<element1\> \<element2\> \<alignment\>**
533 :   relates \<element1\> to \<element2\>, moving \<element1\> near
534     \<element2\> using \<alignment\> (see alignment in STYLE AND
535     ATTRIBUTES section, as \<alignment\> opts are similar) every time
536     \<element2\> is moved. If \"0\" is specified as alignment, the
537     relation is deleted.
539 **pass \[\<args\>\]**
541 :   do nothing, consuming remaining arguments.
543 **send \<wid\> \<keysequence\>**
545 :   send a keysequence to an element whose id si \<wid\> (must be
546     enabled at compilation time).
548 **ctrl \<wid\> \<keysequence\>**
550 :   send control key sequence to an element whose id si \<wid\> (must be
551     enabled at compilation time).
553 # GENERIC COMMANDS
555 Generic commands are applicable to any element, regardless of its type
556 (there are exceptions though).
558 **G**
560 :   element is undetectable in taskbar.
562 **F**
564 :   resize the element to fit the entire screen.
566 **d**
568 :   restore element\'s default window attributes.
570 **!**
572 :   bypass window manager.
574 **!!**
576 :   follow window manager as default.
578 **n**
580 :   center element in its parent.
582 **-**
584 :   hide element.
586 **+**
588 :   show element.
590 **c**
592 :   click element.
594 **f**
596 :   focus element.
598 **t**
600 :   make element stay at top.
602 **b**
604 :   make element stay at bottom.
606 **x**
608 :   hide element, or quit guish if quit-on-last-close is on and the
609     element is the last closed one.
611 **l**
613 :   lower the element.
615 **r**
617 :   raise the element.
619 **M**
621 :   maximize the element.
623 **D**
625 :   disable the element.
627 **E**
629 :   enable the element.
631 **o**
633 :   fits element\'s size to its content.
635 **w**
637 :   resize an element in right-bottom directions to fit its parent,
638     respecting limits of other elements.
640 **nfill**
642 :   resize an element in right-bottom directions to fit its parent.
644 **rfill**
646 :   resize an element in right direction to fit its parent, respecting
647     limits of other elements.
649 **nrfill**
651 :   resize an element in right direction to fit its parent.
653 **bfill**
655 :   resize an element in bottom direction to fit its parent, respecting
656     limits of other elements.
658 **nbfill**
660 :   resize an element in bottom direction to fit its parent.
662 **L**
664 :   clear element\'s data.
666 **: \<title\>**
668 :   set element title.
670 **s \<text\>**
672 :   set element style (see STYLE AND ATTRIBUTES section).
674 **z \<w\> \<h\>**
676 :   resize element by width and height.
678 **m \<x\> \<y\>**
680 :   move element to coords \<x\> \<y\>.
682 **/ \[\<l\|L\|a\|A\|p\|x\|n\> \[\<\...\>\]\]**
684 :   draws/fills lines, points and arcs depending on operation (See
685     Drawing operations subsection). Origin coordinates correspond to the
686     bottom-left corner as default Cartesian axes (instead of upper-left
687     one used for windows/elements). If no operation is given, then all
688     drawings are discarded from the implied element.
690 **A \<element\> \<alignment\>**
692 :   moves implied element to \<element\> using \<alignment\> (see
693     alignment in STYLE AND ATTRIBUTES section, as \<alignment\> opts are
694     similar).
696 **\< \<text\>**
698 :   set element text using \<text\>.
700 **\<+ \<text\>**
702 :   add additional text to element text using \<text\>.
704 **\> \<var\>**
706 :   define a variable named \<var\> using element text to set its value.
708 **g**
710 :   enable/disable (toggle) moving the parent of the element by
711     click-and-drag it. Enabling this will automatically exclude x/y
712     moving flags below.
714 **X**
716 :   enable/disable (toggle) moving an element inside its parent by
717     click-and-drag on x axis Enabling this will automatically exclude
718     the flag to click-and-drag and move parent.
720 **Y**
722 :   enable/disable (toggle) moving an element inside its parent by
723     click-and-drag on y axis Enabling this will automatically exclude
724     the flag to click-and-drag and move parent.
726 ## Drawing operations
728 **l \[\<color\> \<x1\> \<y1\> \<x2\> \<y2\> \[\<\...\>\]\]**
730 :   draws lines between given points using color \<color\> (beware this
731     command consumes all the phrase). If no arguments are given, then
732     all element lines are discarded.
734 **L \[\<color\> \<x1\> \<y1\> \<x2\> \<y2\> \[\<\...\>\]\]**
736 :   fills the polygon described by given points using color \<color\>
737     (beware this command consumes all the phrase). If no arguments are
738     given, then all filled polygons are discarded.
740 **a \[\<color\> \<x\> \<y\> \<w\> \<h\> \<alpha\> \<beta\> \[\<\...\>\]\]**
742 :   draws an arc using color \<color\> and whose \"center\" is at \<x\>
743     \<y\>, major and minor axes are respectively \<w\> and \<h\>, start
744     and stop angles are \<alpha\> and \<beta\> (consumes all the
745     phrase). If no arguments are given, then all element arcs are
746     discarded.
748 **A \[\<color\> \<x\> \<y\> \<w\> \<h\> \<alpha\> \<beta\> \[\<\...\>\]\]**
750 :   fills an arc using color \<color\> and whose \"center\" is at \<x\>
751     \<y\>, major and minor axes are respectively \<w\> and \<h\>, start
752     and stop angles are \<alpha\> and \<beta\> (consumes all the
753     phrase). If no arguments are given, then all element arcs are
754     discarded.
756 **p \[\<color\> \[\<\...\>\]\]**
758 :   draws given points using color \<color\> (beware this command
759     consumes all the phrase). If no arguments are given, then all points
760     are discarded.
762 **x \[\<color\> \[\<\...\>\]\]**
764 :   draws given pixels using color \<color\> (beware this command
765     consumes all the phrase). If no arguments are given, then all pixels
766     are discarded.
768 **n \[\<color\> \<name\> \<x\> \<y\>\]**
770 :   draws given point using color \<color\> and putting the text
771     \<name\> at that point. If no arguments are given, then all points
772     are discarded.
774 # NORMAL COMMANDS
776 ## checkbox commands
778 **C**
780 :   check.
782 **U**
784 :   uncheck.
786 ## input commands
788 **S**
790 :   show input data as normal while typing.
792 **H**
794 :   hide input data while typing.
796 **P**
798 :   use password mode, displaying just asterisks.
800 **W**
802 :   toggles \"go to the next line\" when hitting return (triggers return
803     signal anyway).
805 ## page commands
807 **Q**
809 :   make subelements equals (in size).
811 **S \<style\>**
813 :   style all subelements.
815 **P**
817 :   free all embedded elements.
819 **\<\< \<element\>**
821 :   embeds element (or an external client).
823 **\<\<\< \<element\>**
825 :   embeds element (or an external client), fitting the page to its
826     content.
828 **\>\> \<element\>**
830 :   free element, reparenting it to root window.
832 **\>\>\> \<element\>**
834 :   free element, reparenting it to root window and fitting the page to
835     its content.
837 **v**
839 :   set vertical layout readjusting all subwidgets.
841 **h**
843 :   set horizontal layout readjusting all subwidgets.
845 **Z \<e1\> \<e2\>**
847 :   swaps sub-elements position.
849 **N**
851 :   inverts the order of sub-elements.
853 # SPECIAL SIGNALS
855 Special signals are independent from elements, and are tied to internal guish events.
857 :   
859 **q**
861 :   triggered at program exit.
863 **t**
865 :   triggered when program receives a SIGINT or a SIGTERM.
867 # GENERIC SIGNALS
869 Generic signals are common to all elements.
871 :   
873 **x**
875 :   triggered when element is closed.
877 **c**
879 :   triggered when element is clicked.
881 **lc**
883 :   triggered when element is left-clicked.
885 **rc**
887 :   triggered when element is right-clicked.
889 **mc**
891 :   triggered when element is middle-clicked.
893 **cc**
895 :   triggered when element is double clicked.
897 **lcc**
899 :   triggered when element is double left-clicked.
901 **rcc**
903 :   triggered when element is double right-clicked.
905 **mcc**
907 :   triggered when element is double middle-clicked.
909 **p**
911 :   triggered when element is pressed.
913 **lp**
915 :   triggered when element is left-pressed.
917 **rp**
919 :   triggered when element is right-pressed.
921 **mp**
923 :   triggered when element is middle-pressed.
925 **r**
927 :   triggered when element is released.
929 **lr**
931 :   triggered when element is left-released.
933 **rr**
935 :   triggered when element is right-released.
937 **mr**
939 :   triggered when element is middle-released.
941 **m**
943 :   triggered when element is moved.
945 **s**
947 :   triggered when element scrolled down.
949 **S**
951 :   triggered when element scrolled up.
953 **z**
955 :   triggered when element is resized.
957 **e**
959 :   triggered when mouse pointer \"enters\" the element.
961 **l**
963 :   triggered when mouse pointer \"leaves\" the element.
965 **f**
967 :   triggered when focusing the element.
969 **u**
971 :   triggered when un-focusing the element.
973 # NORMAL SIGNALS
975 Normal signals are per element.
977 :   
979 ## checkbox signals
981 **U**
983 :   triggered when checkbox is unchecked.
985 **C**
987 :   triggered when checkbox is checked.
989 ## input signals
991 **R**
993 :   triggered when input has focus and \"return\" is hit.
995 # REDUNDANT TOKENS
997 These tokens are ignored: \"**,**\", \"**-\>**\".
999 # EVALUATION ORDER AND SUBSTITUTIONS
1001 Every time a new phrase is evaluated, it goes through a series of
1002 special substitutions/evaluations before it\'s commands are interpreted.
1004 The evaluation order is: hex substitution (at tokenizer level),
1005 evaluation of expressions (where code evaluation/execution,
1006 substitutions and functions are computed), evaluation of special
1007 commands and execution of generic/normal commands.
1009 Moreover if after the execution phase (the last one) the phrase is not
1010 empty, the evaluation cycle will restart from evaluation of expressions
1011 phase, and it will continue until there are no more tokens in the
1012 phrase.
1014 Every phrase is reduced to an empty phrase while evaluating:
1016      a=234;{i1=|i|;<'input1'+}();{i2=|i|;<'input2'+}()|b|<btn+
1018 This example is composed by 2 phrases, and the code block in each phrase
1019 is executed before each assignment.
1021 ## Hex substitution
1023 Non quoted tokens are subject to hex substitution: if a \"\\x\" plus 2
1024 hexadecimal characters is found, it\'s substituted with corresponding
1025 ascii characters.
1027      puts \x68\x6F\x6D\x65
1029 Here, the string \"home\" is printed.
1031 ## Globbing
1033 If a \"**\***\" is given, then all widgets wids are substituted.
1035      |b||b||b|+
1036      puts *
1038 ## Variable substitution
1040 With the **=** operator (actually, it\'s a special statement command),
1041 it\'s possible to assign values to a variable, reusing it later by
1042 simply referencing it using **@** operator when not inside quotes or by
1043 wrapping it inside **\@{}** when in double quotes, shell command
1044 substitution quotes **\`\`**, or external window id substitution **\<(
1045 )**.
1047      b = 123; puts @a
1049 There are two methods to define/create empty variables: by explicitely
1050 assing an empty string to a variable (ex. a = \"\") or by simply omit
1051 the value (ex. a =).
1053 In addition, if there is more than one value to assign, a block is
1054 automatically created (embedding those values) and assigned to that
1055 variable:
1057      a = 1              # this simply assigns '1' to the variable 'a'
1058      b = 1, 2, 3, 4     # this instead assigns the block '{1, 2, 3, 4}' to the variable 'a'
1059      c = {1, 2, 3, 4}   # same but explicit
1061 Each block has it\'s own scope, and variable resolution works by
1062 searching from the last scope to the first. Ex:
1064      a = 1
1065      puts(@a)
1066      {
1067          a=345
1068          b=6534
1069      }()
1070      puts@a
1071      puts"b:@{b}"
1073 In the last example, a is set to 1 and printed, then it\'s changed to
1074 345 from another scope, in which another variable (b) is set. After code
1075 block, just \"a\" is updated, and \"b\" doesn\'t exist anymore.
1077 For example:
1079      gname = MY_GRIP_NAME
1080      |l|<@gname
1084      gname = MY_GRIP_NAME
1085      name = 'random name'
1086      puts "@{gname} is maybe @{name}"
1088 ## Element expressions
1090 Anything inside **\|\|** is an element expression; a widget of a given
1091 element is created and its X11 window id substituted. The synopsis is:
1092 \|\<element\>\[{\<width\>, \<height\>}\]\| Ex.
1094      |b|+
1096 If an integer is given, instead of one of available element types, then
1097 the program tries to find an existing program having that integer as
1098 window id. Ex.
1100      |12341234|-
1102 This creates a widget (\"external\") for the external program and hides
1105 ## Shell command substitution
1107 Anything inside **\`\`** is treated as a shell command, and it\'s output
1108 is substituted.
1110      d = `date`
1111      ols = `ls -l`
1113 ## External window id substitution
1115 Everything inside **\<( )** is recognized as an external command (X11
1116 GUI), forked and executed, and its window id is substituted (using
1117 \_NET_WM_PID).
1119 For example:
1121      a = <(xterm)
1123 xterm program is spawn, and can be driven (almost) like a normal
1124 element.
1126 # OPERATORS
1128 ## Binary
1130 **\<s\> .. \<e\>**
1132 :   returns integers starting at \<s\> and ending at \<e\> (inclusive)
1133     as multiple tokens.
1135 **\<var\> = \[\<val\>, \[\<val1\>, \...\]\]**
1137 :   defines a variable (consumes all the phrase). If no value is given,
1138     an empty token is assigned to the variable. If a single value is
1139     given, that value is assigned to the variable. If multiple values
1140     are given, then all these values are wrapped inside a block, and
1141     this block is assigned to the variable.
1143 **\<attr\> .= \[\<val\>, \[\<val1\>, \...\]\]**
1145 :   defines an element using the implied subject attribute (consumes all
1146     the phrase). If no value is given, an empty token is assigned to the
1147     variable. If a single value is given, that value is assigned to the
1148     variable. If multiple values are given, then all these values are
1149     wrapped inside a block, and this block is assigned to the variable.
1151 ## Unary
1153 **@\<varname\|num\>**
1155 :   dereferences a variable name (or positional argument).
1157 **@\***
1159 :   returns all function parameters as tokens (usable with command line
1160     parameters too).
1162 **\[\<eid\>\].\<attr\>**
1164 :   dereferences an element attribute; if \<eid\> is given, uses that
1165     element, otherwise uses implied subject.
1167 # ELEMENT ATTRIBUTES
1169 Every element can have some default readonly attributes and a variable
1170 number of custom attributes (which can be set by using assignment only,
1171 not by using **let** function). To set an attribute, use the \"**.=**\"
1172 operator; to get it instead use the \"**.**\" operator.
1174      b = |b|; myattr .= 'here'; puts(@b.myattr)
1176 In the last example, a custom attribute, \"myattr\" is created and used.
1178 The following are default attributes (readonly):
1180 **t**
1182 :   widget\'s type.
1184 **w**
1186 :   widget\'s width.
1188 **h**
1190 :   widget\'s height.
1192 **x**
1194 :   widget\'s x coord.
1196 **y**
1198 :   widget\'s y coord.
1200 **b**
1202 :   widget\'s border width.
1204 **g**
1206 :   widget\'s margin width.
1208 **d**
1210 :   widget\'s text data.
1212 **T**
1214 :   widget\'s title.
1216 **c**
1218 :   widget\'s checked/unchecked status (only for checkbox).
1220 **n**
1222 :   widget\'s number of subwidgets (only for page).
1224 **s**
1226 :   widget\'s subwidgets ids (one token each, only for page).
1228 **pid**
1230 :   process ID associated with the widget.
1232 **v**
1234 :   widget is visible.
1236 **e**
1238 :   widget is enabled (freezed/unfreezed).
1240 **f**
1242 :   widget is focused.
1244 # BUILTIN FUNCTIONS
1246 Symbol \"**\...**\" means a variable number of arguments.
1248 **exists(\<eid\>)**
1250 :   returns 1 if a widget with id \<eid\> exists, 0 otherwise.
1252 **read(\[\<file\>\])**
1254 :   reads and returns a line (excluding newline) from standard input; if
1255     an existing file is given, reads and returns all its content. Beware
1256     that this function blocks the GUI events, and returns nothing when
1257     reading from stdin and source is non-blocking.
1259 **write(\<text\>, \<file\>)**
1261 :   writes text into file and returns the number of characters written.
1262     Creates the file if it doesn\'t exist yet.
1264 **append(\<text\>, \<file\>)**
1266 :   append text to the end of file and returns the number of characters
1267     written. Creates the file if it doesn\'t exist yet.
1269 **eval(\...)**
1271 :   evaluates code by first stringifying all given arguments and then
1272     returns the result of evaluation if any. Beware that this function
1273     runs in the \"current\" scope, and can modify it.
1275 **builtin(\<func\>, \...)**
1277 :   gets the name of a builtin function and a variable number of
1278     arguments, then calls the builtin function with those arguments and
1279     returns the result (if any). It\'s useful when overriding builtin
1280     functions.
1282 **each(\<function\>, \...)**
1284 :   executes \<function\> for each additional argument given passing it
1285     as the first argument to the block. If return values are present,
1286     they will be accumulated and then returned.
1288 **env(\<var\>)**
1290 :   returns the value of the environment variable \"var\".
1292 **cwd()**
1294 :   returns the value of the current working directory.
1296 **rev(\[\<block\>\], \...)**
1298 :   if a block is given as first argument, its element will be returned
1299     in reverse, otherwise **rev** will return all its arguments in
1300     reverse. This function is somewhat special, as when there are no
1301     arguments to get, it\'ll return nothing (statement behaviour).
1303 **let(\[\<var\>, \<val\>\], \...)**
1305 :   sets variables, works exactly like assignment with special operator
1306     **=**, but in expressions. This function is somewhat special, it\'ll
1307     return nothing (statement behaviour).
1309 **if(\<cond\>, \[\<v1\>, \[\<v2\>\]\])**
1311 :   if \<cond\> is true and \<v1\> is given, returns \<v1\>, else if
1312     \<cond\> is false and \<v2\> is given, returns \<v2\>.
1314 **unless(\<cond\>, \[\<v1\>, \[\<v2\>\]\])**
1316 :   if \<cond\> is false and \<v1\> is given, returns \<v1\>, else if
1317     \<cond\> is true and \<v2\> is given, returns \<v2\>.
1319 **and(\...)**
1321 :   returns the first true argument; if there are no true arguments,
1322     returns the last one which is false. The function evaluates any
1323     block given.
1325 **or(\...)**
1327 :   returns the last true argument if all arguments are true, otherwise
1328     returns the first false argument. The function evaluates any block
1329     given.
1331 **flat(\...)**
1333 :   returns all given arguments; if a block is found, then it is
1334     flatted.
1336 **block(\...)**
1338 :   returns a code block, embedding the given arguments into **{}**.
1340 **some(\...)**
1342 :   returns given arguments. If nothing is given, returns an empty
1343     token.
1345 **puts(\...)**
1347 :   prints given arguments to stdout. This function is somewhat special,
1348     it\'ll return nothing (statement behaviour).
1350 **push(\...)**
1352 :   pushes given arguments to current function arguments (works with
1353     command line parameters too). This function is somewhat special,
1354     it\'ll return nothing (statement behaviour).
1356 **pushb(\...)**
1358 :   pushes given arguments to current function arguments from the
1359     beginning (works with command line parameters too). This function is
1360     somewhat special, it\'ll return nothing (statement behaviour).
1362 **pop()**
1364 :   pops the last argument from function arguments (works with command
1365     line parameters too). This function is somewhat special, as if there
1366     are no arguments to pop, it\'ll return nothing (statement
1367     behaviour).
1369 **popb()**
1371 :   pops the first argument from function arguments (works with command
1372     line parameters too). This function is somewhat special, as if there
1373     are no arguments to pop.
1375 **times(\<n\>, \<arg\>)**
1377 :   returns a sequence of tokens made by \<n\> times \<arg\>. This
1378     function is somewhat special, as when there are 0 tokens to
1379     replicate, it\'ll return nothing (statement behaviour).
1381 **get(\<name\>)**
1383 :   returns the value of the variable with name \<name\>, or an empty
1384     token if the variable does not exist.
1386 **true(\<arg\>)**
1388 :   returns 1 if \<arg\> is true, 0 otherwise.
1390 **false(\<arg\>)**
1392 :   returns 0 if \<arg\> is true, 1 otherwise.
1394 **in(\<n\>, \<heap\>)**
1396 :   returns 1 if \<n\> is found in \<heap\>, 0 otherwise; the arguments
1397     can be of any type (single tokens and blocks).
1399 **join(\...)**
1401 :   joins blocks and/or tokens by applying the following rules to all
1402     arguments given, and accumulates the result as the first operand. If
1403     the operands are blocks, then a single new block is created by
1404     joining them; if the operands are tokens, then a single new token is
1405     created by joining them, and its type will be that of the \"second\"
1406     token; if the operands are mixed (eg. a block and a token), then the
1407     token will be embedded inside the block.
1409 **isdef(\<token\>)**
1411 :   returns 1 if \<token\> is a variable, 0 otherwise.
1413 **isvar(\<token\>)**
1415 :   returns 1 if \<token\> is a (type) variable, 0 otherwise.
1417 **isfunc(\<token\>)**
1419 :   returns 1 if \<token\> refers to a function, 0 otherwise.
1421 **isblock(\...)**
1423 :   returns 1 if just one argument is given and is a block, 0 otherwise.
1425 **isint(\...)**
1427 :   returns 1 if just one argument is given and is an integer, 0
1428     otherwise.
1430 **len(\<arg\>)**
1432 :   if a block is given, returns the number of its element, otherwise
1433     returns the number of characters of the token.
1435 **split(\<token\>, \<sep\>)**
1437 :   splits \"token\" using separator \"sep\" and returns resulting
1438     tokens having their type equal to that of \"token\".
1440 **csplit(\<token\>, \<sep\>)**
1442 :   splits \"token\" using separator \"sep\" and returns resulting
1443     tokens as normal commands.
1445 **seq(\<t1\>, \<t2\>, \...)**
1447 :   returns 1 if all arguments are equal (string comparison), 0
1448     otherwise.
1450 **add(\...)**
1452 :   perform addition.
1454 **sub(\...)**
1456 :   perform subtraction.
1458 **mul(\...)**
1460 :   perform multiplication
1462 **div(\...)**
1464 :   perform division.
1466 **mod(\...)**
1468 :   perform modulus.
1470 **rand()**
1472 :   returns a random positive integer.
1474 **sqrt(\<n\>)**
1476 :   returns the square root of \<n\>.
1478 **cbrt(\<n\>)**
1480 :   returns the cube root of \<n\>.
1482 **pow(\<n\>, \<e\>)**
1484 :   returns the power of \<n\> raised to \<e\>.
1486 **log(\<n\>)**
1488 :   returns the base 10 logarithm of \<n\>.
1490 **ln(\<n\>)**
1492 :   returns the natural logarithm of \<n\>.
1494 **sin(\<n\>)**
1496 :   returns the sine of \<n\> (degrees).
1498 **cos(\<n\>)**
1500 :   returns the cosine of \<n\> (degrees).
1502 **tan(\<n\>)**
1504 :   returns the tangent of \<n\> (degrees).
1506 **hex(\<n\>)**
1508 :   returns \<n\> in its hexadecimal representation.
1510 **int(\<n\>)**
1512 :   returns integral part of given number \<n\>; rounds to nearest
1513     integer.
1515 **xor(\<n1\>, \<n2\>, \...)**
1517 :   perform bitwise XOR.
1519 **band(\<n1\>, \<n2\>, \...)**
1521 :   perform bitwise AND.
1523 **bor(\<n1\>, \<n2\>, \...)**
1525 :   perform bitwise OR.
1527 **lsh(\<n1\>, \<n2\>, \...)**
1529 :   perform bitwise left shift.
1531 **rsh(\<n1\>, \<n2\>, \...)**
1533 :   perform bitwise right shift.
1535 **not(\<n\>)**
1537 :   perform negation
1539 **eq(\<n1\>, \<n2\>, \...)**
1541 :   equal-to
1543 **ne(\<n1\>, \<n2\>, \...)**
1545 :   not-equal-to
1547 **lt(\<n1\>, \<n2\>, \...)**
1549 :   less-than
1551 **gt(\<n1\>, \<n2\>, \...)**
1553 :   greater-than
1555 **le(\<n1\>, \<n2\>, \...)**
1557 :   less-equal-than
1559 **ge(\<n1\>, \<n2\>, \...)**
1561 :   greater-equal-than
1563 **abs(\<n\>)**
1565 :   perform absolute value
1567 **neg(\<n\>)**
1569 :   unary minus.
1571 # STYLE AND ATTRIBUTES
1573 Each element has some properties/attributes which can be set by using
1574 style command. This command takes a string that has a format like CSS:
1576      |l| s 'bg: blue; fg: white'
1578 Here, we create a label with a blue background and white foreground.
1580 Each field must be separated by newlines, **;** or **\|**. Colors can be
1581 specified by using a common shortname, such as \"yellow\", or by using
1582 RGB value, such as \"#ff32ae\".
1584 **background \| bg: \<color\|/\<path to image\>\>**
1586 :   set background color or a background image by specifying image path;
1587     if the string \"null\" is given as \<path to image\>, current image
1588     is removed. (Background image loading requires building guish with
1589     Imlib2 support.)
1591 **color \| foreground \| fg: \<color\>**
1593 :   set foreground color
1595 **pressed-background \| pbg: \<color\>**
1597 :   background color when element is pressed
1599 **pressed-color \| pfg: \<color\>**
1601 :   foreground color when element is pressed
1603 **hovered-background \| hbg: \<color\>**
1605 :   background color when element is hovered
1607 **hovered-color \| hfg: \<color\>**
1609 :   foreground color when element is hovered
1611 **border-color \| bc: \<color\>**
1613 :   set border color
1615 **width \| w: \<value in pixels\>**
1617 :   set width
1619 **height \| h: \<value in pixels\>**
1621 :   set height
1623 **border \| b: \<value in pixels\>**
1625 :   set border width
1627 **line \| l: \<value in pixels\>**
1629 :   set line width (use with \"/\" command)
1631 **margin \| g: \<value in pixels\>**
1633 :   set margin width
1635 **mode \| m: \<expanding mode\>**
1637 :   set expanding mode type (See Expanding mode)
1639 **align \| a: \<alignment\>**
1641 :   set alignment type (See Alignment)
1643 **f \| font: \<font name\>**
1645 :   set font type using a X11 font name
1647 ## Expanding mode
1649 **fixed \| f**
1651 :   width and height are fixed (default for all elements)
1653 **wfixed \| w**
1655 :   width is fixed, height can change
1657 **hfixed \| h**
1659 :   height is fixed, width can change
1661 **relaxed \| r**
1663 :   width and height can change
1665 ## Alignment
1667 Any element that\'s not a page has a particular text alignment that can
1668 be changed. If an alignment is specified for a page element instead,
1669 (whose defaults alignments are top-center for horizontal layout, and
1670 middle-left for vertical one), then its sub-elements will be aligned
1671 accordingly, depending from page layout type too.
1673 **l \| left \| middle-left**
1675 :   show text at middle left
1677 **r \| right \| middle-right**
1679 :   show text at middle right
1681 **c \| center \| middle-center**
1683 :   show text at middle center
1685 **tl \| top-left**
1687 :   show text at top left
1689 **tr \| top-right**
1691 :   show text at top right
1693 **t \| top-center**
1695 :   show text at top center
1697 **bl \| bottom-left**
1699 :   show text at bottom left
1701 **br \| bottom-right**
1703 :   show text at bottom right
1705 **b \| bottom-center**
1707 :   show text at bottom center
1709 # AUTHOR
1711 Francesco Palumbo \<phranz@subfc.net\>
1713 # THANKS
1715 La vera Napoli, Carme, Pico, Titina, Molly, Leo, i miei amati nonni, mio
1716 padre, mia madre, e tutti coloro su cui ho potuto e posso contare.
1717 Grazie mille.
1719 # LICENSE
1721 **GPL-3.0-or-later** see COPYING