The main idea is to add support for symbolic IDs, such as @name, where one can already use ordinal IDs, such as %N, in a form. Similarly for command output redirection: add support for @name: where %N: can be used.
Can be escaped with \@ID to avoid expansion
Can be mixed with %N and ^N: but not recommended; better use one or the other
Wherever the use of symbolic references (@ID) vs ordinal references (%N) simplifies coding or maintaining the code.
Form options
--field=LABEL[!TOOLTIP][:TYPE[@ID]]
...
--use-output-prefix[=PREFIX]
Prefix output field value with PREFIX. Default PREFIX is %@=. If %@ is included
in PREFIX, it will be replaced by the field's @ID (without the leading "@") if
defined, otherwise by fixed string "nul".
...
BTN - button field. Label text may be formatted as LABEL[!ICON[!TOOLTIP]]
where `!' is an item separator. LABEL is the text of button label or yad stock
id. ICON is a button icon (stock id or file name). TOOLTIP is the text of an
optional help popup tooltip. Initial value is a command which is started when
the button is clicked. Special symbols %N (percent followed by a number) in
command will be replaced by the value of the Nth field. If command starts with
@, the output of com‐ mand will be parsed and lines that start with M: (a
number followed by colon) will set the new value of the Mth field. @ID can
be used instead of %N and M:. A quoting style for value when sh -c is used -
single quotes around command and double quotes around -c argument.
In option.c, setting the default output prefix was similar to setting the default interpreter, so I followed that example. The setter function and the new options are:
IDs, if any, are expanded into their corresponding %N and ^N: forms, which are then processed as usual with the existing code. Two new functions in form.c perform ID expansion: preprocess_atid() and preprocess_cb() (callback). Expansion is based on regular expressions.
Function preprocess_atid() is called twice.
First in expand_action() before the latter expands %N into field value:
command and cmd refer to before/after the call to preprocess_atid() in expand_action(). text and data refer to before/after the call to preprocess_atid() in parse_cmd_output().
FORM SYMBOLIC ID
The main idea is to add support for symbolic IDs, such as
@name
, where one can already use ordinal IDs, such as%N
, in a form. Similarly for command output redirection: add support for@name:
where%N:
can be used.This commit adds two new features to forms:
Example:
Output:
Can be combined with --quoted-output
Output:
Fixed string "nul" is used automatically for any undeclared @ID.
Example:
Can be escaped with \@ID to avoid expansion Can be mixed with %N and ^N: but not recommended; better use one or the other
Wherever the use of symbolic references (@ID) vs ordinal references (%N) simplifies coding or maintaining the code.
In option.c, setting the default output prefix was similar to setting the default interpreter, so I followed that example. The setter function and the new options are:
Modifications of existing functions:
add_field()
as usual.form_print_field()
. The code is straightforward, although it affects eachcase
of the mainswitch
.Field ID is stored in struct
YadFields
as memberatid
. Mind thatatid
stores "@ID" not "ID".IDs, if any, are expanded into their corresponding
%N
and ^N:
forms, which are then processed as usual with the existing code. Two new functions in form.c perform ID expansion:preprocess_atid()
andpreprocess_cb()
(callback). Expansion is based on regular expressions.Function
preprocess_atid()
is called twice. First inexpand_action()
before the latter expands%N
into field value:needs_free
indicates the need to callg_free()
on*cmd
command
(input) is the field value as specified by the usercmd
(output) is the same value with%N
standing for@ID
%1$s
in the regular expression stands for%N
Of course N={1,...M}.Second in
parse_cmd_output()
before the latter expands ^N:
into output redirection:text
(input) is the raw command outputdata
(output) is the same text withN:
standing for ^@ID:
This trace shows it all, @ID => %N value expansion, @ID: => N: redirection expansion, \@ID escaping.
INCREMENT BY 1 AND REPROGRAM BUTTON ACTION
command
andcmd
refer to before/after the call topreprocess_atid()
inexpand_action()
.text
anddata
refer to before/after the call topreprocess_atid()
inparse_cmd_output()
.