author | Edouard Tisserant |
Tue, 24 Aug 2021 11:12:41 +0200 | |
branch | svghmi |
changeset 3298 | e6131894be1d |
parent 3241 | fe945f1f48b7 |
child 3329 | d44b6346d4c2 |
permissions | -rw-r--r-- |
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
1 |
// widget_display.ysl2 |
2792
0c0d3895b036
SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents:
2791
diff
changeset
|
2 |
|
3241
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
3 |
widget_desc("Display") { |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
4 |
longdesc |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
5 |
|| |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
6 |
If Display widget is a svg:text element, then text content is replaced by |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
7 |
value of given variables, space separated. |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
8 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
9 |
Otherwise, if Display widget is a group containing a svg:text element |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
10 |
labelled "format", then text content is replaced by printf-like formated |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
11 |
string. In other words, if "format" labeled text is "%d %s %f", then 3 |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
12 |
variables paths are expected : HMI_IN, HMI_STRING and HMI_REAL. |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
13 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
14 |
In case Display widget is a svg::text element, it is also possible to give |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
15 |
format string as first argument. |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
16 |
|| |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
17 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
18 |
shortdesc > Printf-like formated text display |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
19 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
20 |
arg name="format" count="optional" accepts="string" > printf-like format string when not given as svg:text |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
21 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
22 |
path name="fields" count="many" accepts="HMI_INT,HMI_REAL,HMI_STRING,HMI_BOOL" > variables to be displayed |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
23 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
24 |
} |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
25 |
|
2790
8fab1886ebec
SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents:
2789
diff
changeset
|
26 |
|
3232
7bdb766c2a4d
SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3204
diff
changeset
|
27 |
widget_class("Display") |
2998
e8f707d99dc3
SVGHMI: Update Widget Display templates to generate Class based declaration.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2883
diff
changeset
|
28 |
|| |
e8f707d99dc3
SVGHMI: Update Widget Display templates to generate Class based declaration.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2883
diff
changeset
|
29 |
frequency = 5; |
3008
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
30 |
dispatch(value, oldval, index) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
31 |
this.fields[index] = value; |
3142
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
32 |
this.request_animate(); |
2998
e8f707d99dc3
SVGHMI: Update Widget Display templates to generate Class based declaration.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2883
diff
changeset
|
33 |
} |
e8f707d99dc3
SVGHMI: Update Widget Display templates to generate Class based declaration.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2883
diff
changeset
|
34 |
|| |
e8f707d99dc3
SVGHMI: Update Widget Display templates to generate Class based declaration.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2883
diff
changeset
|
35 |
|
3232
7bdb766c2a4d
SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3204
diff
changeset
|
36 |
widget_defs("Display") { |
3142
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
37 |
const "format" optional_labels("format"); |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
38 |
const "has_format","string-length($format)>0"; |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
39 |
value "$format"; |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
40 |
|
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
41 |
if "$hmi_element[not(self::svg:text)] and not($has_format)" |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
42 |
error > Display Widget id="«$hmi_element/@id»" must be a svg::text element itself or a group containing a svg:text element labelled "format" |
3008
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
43 |
|
3022
f6fe42b7ce60
SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents:
3008
diff
changeset
|
44 |
const "field_initializer" foreach "path" { |
f6fe42b7ce60
SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents:
3008
diff
changeset
|
45 |
choose{ |
f6fe42b7ce60
SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents:
3008
diff
changeset
|
46 |
when "@type='HMI_STRING'" > "" |
3065
c369a742443d
SVGHMI: non significant cosmetic changes
Edouard Tisserant
parents:
3035
diff
changeset
|
47 |
otherwise > 0 |
3022
f6fe42b7ce60
SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents:
3008
diff
changeset
|
48 |
} |
f6fe42b7ce60
SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents:
3008
diff
changeset
|
49 |
if "position()!=last()" > , |
f6fe42b7ce60
SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents:
3008
diff
changeset
|
50 |
} |
f6fe42b7ce60
SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents:
3008
diff
changeset
|
51 |
| fields: [«$field_initializer»], |
3142
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
52 |
| animate: function(){ |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
53 |
choose { |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
54 |
when "$has_format" { |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
55 |
| if(this.format_elt.getAttribute("lang")) { |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
56 |
| this.format = svg_text_to_multiline(this.format_elt); |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
57 |
| this.format_elt.removeAttribute("lang"); |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
58 |
| } |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
59 |
| let str = vsprintf(this.format,this.fields); |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
60 |
| multiline_to_svg_text(this.format_elt, str); |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
61 |
} |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
62 |
otherwise { |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
63 |
| let str = this.args.length == 1 ? vsprintf(this.args[0],this.fields) : this.fields.join(' '); |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
64 |
| multiline_to_svg_text(this.element, str); |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
65 |
} |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
66 |
} |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
67 |
| }, |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
68 |
| |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
69 |
if "$has_format" { |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
70 |
| init: function() { |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
71 |
| this.format = svg_text_to_multiline(this.format_elt); |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
72 |
| }, |
2637bb6a6bb0
SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3065
diff
changeset
|
73 |
} |
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
diff
changeset
|
74 |
} |
3008
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
75 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
76 |
emit "preamble:display" |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
77 |
|| |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
78 |
/* https://github.com/alexei/sprintf.js/blob/master/src/sprintf.js */ |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
79 |
/* global window, exports, define */ |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
80 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
81 |
!function() { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
82 |
'use strict' |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
83 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
84 |
var re = { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
85 |
not_string: /[^s]/, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
86 |
not_bool: /[^t]/, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
87 |
not_type: /[^T]/, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
88 |
not_primitive: /[^v]/, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
89 |
number: /[diefg]/, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
90 |
numeric_arg: /[bcdiefguxX]/, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
91 |
json: /[j]/, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
92 |
not_json: /[^j]/, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
93 |
text: /^[^\x25]+/, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
94 |
modulo: /^\x25{2}/, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
95 |
placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
96 |
key: /^([a-z_][a-z_\d]*)/i, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
97 |
key_access: /^\.([a-z_][a-z_\d]*)/i, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
98 |
index_access: /^\[(\d+)\]/, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
99 |
sign: /^[+-]/ |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
100 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
101 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
102 |
function sprintf(key) { |
3204
856f4698a0a8
SVGHMI: Fixed wierd CDATA mess in output xhtml, because of backticks copy pasted in some yml ||text block||
Edouard Tisserant
parents:
3142
diff
changeset
|
103 |
// arguments is not an array, but should be fine for this call |
3008
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
104 |
return sprintf_format(sprintf_parse(key), arguments) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
105 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
106 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
107 |
function vsprintf(fmt, argv) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
108 |
return sprintf.apply(null, [fmt].concat(argv || [])) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
109 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
110 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
111 |
function sprintf_format(parse_tree, argv) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
112 |
var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
113 |
for (i = 0; i < tree_length; i++) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
114 |
if (typeof parse_tree[i] === 'string') { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
115 |
output += parse_tree[i] |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
116 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
117 |
else if (typeof parse_tree[i] === 'object') { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
118 |
ph = parse_tree[i] // convenience purposes only |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
119 |
if (ph.keys) { // keyword argument |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
120 |
arg = argv[cursor] |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
121 |
for (k = 0; k < ph.keys.length; k++) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
122 |
if (arg == undefined) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
123 |
throw new Error(sprintf('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k-1])) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
124 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
125 |
arg = arg[ph.keys[k]] |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
126 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
127 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
128 |
else if (ph.param_no) { // positional argument (explicit) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
129 |
arg = argv[ph.param_no] |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
130 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
131 |
else { // positional argument (implicit) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
132 |
arg = argv[cursor++] |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
133 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
134 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
135 |
if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
136 |
arg = arg() |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
137 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
138 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
139 |
if (re.numeric_arg.test(ph.type) && (typeof arg !== 'number' && isNaN(arg))) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
140 |
throw new TypeError(sprintf('[sprintf] expecting number but found %T', arg)) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
141 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
142 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
143 |
if (re.number.test(ph.type)) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
144 |
is_positive = arg >= 0 |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
145 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
146 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
147 |
switch (ph.type) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
148 |
case 'b': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
149 |
arg = parseInt(arg, 10).toString(2) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
150 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
151 |
case 'c': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
152 |
arg = String.fromCharCode(parseInt(arg, 10)) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
153 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
154 |
case 'd': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
155 |
case 'i': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
156 |
arg = parseInt(arg, 10) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
157 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
158 |
case 'j': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
159 |
arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
160 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
161 |
case 'e': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
162 |
arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential() |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
163 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
164 |
case 'f': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
165 |
arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
166 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
167 |
case 'g': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
168 |
arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
169 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
170 |
case 'o': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
171 |
arg = (parseInt(arg, 10) >>> 0).toString(8) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
172 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
173 |
case 's': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
174 |
arg = String(arg) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
175 |
arg = (ph.precision ? arg.substring(0, ph.precision) : arg) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
176 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
177 |
case 't': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
178 |
arg = String(!!arg) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
179 |
arg = (ph.precision ? arg.substring(0, ph.precision) : arg) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
180 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
181 |
case 'T': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
182 |
arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase() |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
183 |
arg = (ph.precision ? arg.substring(0, ph.precision) : arg) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
184 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
185 |
case 'u': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
186 |
arg = parseInt(arg, 10) >>> 0 |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
187 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
188 |
case 'v': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
189 |
arg = arg.valueOf() |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
190 |
arg = (ph.precision ? arg.substring(0, ph.precision) : arg) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
191 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
192 |
case 'x': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
193 |
arg = (parseInt(arg, 10) >>> 0).toString(16) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
194 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
195 |
case 'X': |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
196 |
arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase() |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
197 |
break |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
198 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
199 |
if (re.json.test(ph.type)) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
200 |
output += arg |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
201 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
202 |
else { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
203 |
if (re.number.test(ph.type) && (!is_positive || ph.sign)) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
204 |
sign = is_positive ? '+' : '-' |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
205 |
arg = arg.toString().replace(re.sign, '') |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
206 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
207 |
else { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
208 |
sign = '' |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
209 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
210 |
pad_character = ph.pad_char ? ph.pad_char === '0' ? '0' : ph.pad_char.charAt(1) : ' ' |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
211 |
pad_length = ph.width - (sign + arg).length |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
212 |
pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : '' |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
213 |
output += ph.align ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
214 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
215 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
216 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
217 |
return output |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
218 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
219 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
220 |
var sprintf_cache = Object.create(null) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
221 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
222 |
function sprintf_parse(fmt) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
223 |
if (sprintf_cache[fmt]) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
224 |
return sprintf_cache[fmt] |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
225 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
226 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
227 |
var _fmt = fmt, match, parse_tree = [], arg_names = 0 |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
228 |
while (_fmt) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
229 |
if ((match = re.text.exec(_fmt)) !== null) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
230 |
parse_tree.push(match[0]) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
231 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
232 |
else if ((match = re.modulo.exec(_fmt)) !== null) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
233 |
parse_tree.push('%') |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
234 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
235 |
else if ((match = re.placeholder.exec(_fmt)) !== null) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
236 |
if (match[2]) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
237 |
arg_names |= 1 |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
238 |
var field_list = [], replacement_field = match[2], field_match = [] |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
239 |
if ((field_match = re.key.exec(replacement_field)) !== null) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
240 |
field_list.push(field_match[1]) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
241 |
while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
242 |
if ((field_match = re.key_access.exec(replacement_field)) !== null) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
243 |
field_list.push(field_match[1]) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
244 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
245 |
else if ((field_match = re.index_access.exec(replacement_field)) !== null) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
246 |
field_list.push(field_match[1]) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
247 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
248 |
else { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
249 |
throw new SyntaxError('[sprintf] failed to parse named argument key') |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
250 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
251 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
252 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
253 |
else { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
254 |
throw new SyntaxError('[sprintf] failed to parse named argument key') |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
255 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
256 |
match[2] = field_list |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
257 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
258 |
else { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
259 |
arg_names |= 2 |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
260 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
261 |
if (arg_names === 3) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
262 |
throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported') |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
263 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
264 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
265 |
parse_tree.push( |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
266 |
{ |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
267 |
placeholder: match[0], |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
268 |
param_no: match[1], |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
269 |
keys: match[2], |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
270 |
sign: match[3], |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
271 |
pad_char: match[4], |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
272 |
align: match[5], |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
273 |
width: match[6], |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
274 |
precision: match[7], |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
275 |
type: match[8] |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
276 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
277 |
) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
278 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
279 |
else { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
280 |
throw new SyntaxError('[sprintf] unexpected placeholder') |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
281 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
282 |
_fmt = _fmt.substring(match[0].length) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
283 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
284 |
return sprintf_cache[fmt] = parse_tree |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
285 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
286 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
287 |
/** |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
288 |
* export to either browser or node.js |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
289 |
*/ |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
290 |
/* eslint-disable quote-props */ |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
291 |
if (typeof exports !== 'undefined') { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
292 |
exports['sprintf'] = sprintf |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
293 |
exports['vsprintf'] = vsprintf |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
294 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
295 |
if (typeof window !== 'undefined') { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
296 |
window['sprintf'] = sprintf |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
297 |
window['vsprintf'] = vsprintf |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
298 |
|
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
299 |
if (typeof define === 'function' && define['amd']) { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
300 |
define(function() { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
301 |
return { |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
302 |
'sprintf': sprintf, |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
303 |
'vsprintf': vsprintf |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
304 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
305 |
}) |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
306 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
307 |
} |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
308 |
/* eslint-enable quote-props */ |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
309 |
}(); // eslint-disable-line |
dabad70db1bf
SVGHMI: allow multiple variables and formatting in Display widget. Formatting is printf style and given as first argument. If no formating is given as widget argument, space separated.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2998
diff
changeset
|
310 |
|| |