Skip to content

Commit 0e5a510

Browse files
committed
refactor: Update ZUI demos
Signed-off-by: Salvydas Lukosius <ss-o@users.noreply.github.com>
1 parent 0e23194 commit 0e5a510

18 files changed

+614
-529
lines changed

demos/zui-demo-anchors

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
2+
# vim: ft=zsh sw=2 ts=2 et
3+
#
4+
# ZUI demo: anchors
5+
#
16
# Started from Zle or from command line
27
#
38
# Shows all types of anchors: external/regenerating, internal,
49
# internal/regenerating, pointing outside own module
510

611
-zui_std_cleanup deserialize:"zui-demo-anchors"
712
-zui_std_init app:"zui-demo-anchors" app_name:"ZUI Anchors"
8-
emulate -LR zsh -o extended_glob -o typeset_silent -o warn_create_global
13+
14+
builtin emulate -LR zsh
15+
builtin setopt extended_glob typeset_silent warn_create_global
16+
917
-zui_std_init2 # after emulate -LR
1018

1119
-zui_std_store_default_app_config b:border 1

demos/zui-demo-append

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
2+
# vim: ft=zsh sw=2 ts=2 et
3+
#
4+
# ZUI demo: append
5+
#
16
# Started from Zle or from command line
27
#
38
# A demo showing how to add module instances to already generated document
49

510
-zui_std_cleanup deserialize:"zui-demo-append"
611
-zui_std_init app:"zui-demo-append" app_name:"ZUI On-The-Fly Append"
7-
emulate -LR zsh -o extended_glob -o typeset_silent -o warn_create_global
12+
13+
builtin emulate -LR zsh
14+
builtin setopt extended_glob typeset_silent warn_create_global
15+
816
-zui_std_init2 # after emulate -LR
917

1018
-zui_std_store_default_app_config b:border 1
@@ -13,22 +21,22 @@ emulate -LR zsh -o extended_glob -o typeset_silent -o warn_create_global
1321

1422
# Generator for module 1
1523
demo_generator_A() {
16-
local mod="$1" ice="$2"
17-
18-
# Anchor only in last instance
19-
-zui_std_get_mod_factor "$mod"
20-
if [[ "$ice" = "$REPLY" ]]; then
21-
# 1+2 - from 1st line of this module, jump 2 beyond this module
22-
# Regenerate $mod/$ice, and $mod/$ice+1, first running handler
23-
local -a output
24-
-zui_std_anchor "append_next" "1+2" "" ",mod${mod}_ice${ice},mod${mod}_ice$(( ice + 1 ))," "" "${ZUI[MAGENTA]}Append next!${ZUI[FMT_END]}" "-zui_std_set_mod_factor $mod $(( REPLY + 1 ))" output
25-
fi
26-
27-
# Content
28-
reply=( "This is module $mod, instance $ice" ${output[1]} )
29-
30-
# Non-selectable lines Hops to jump with [ and ] Local anchors (if output[1] not empty ...)
31-
reply2=( 1 ) reply3=( 1 ) reply4=( ${output[1]:+append_next} )
24+
local mod="$1" ice="$2"
25+
26+
# Anchor only in last instance
27+
-zui_std_get_mod_factor "$mod"
28+
if [[ "$ice" = "$REPLY" ]]; then
29+
# 1+2 - from 1st line of this module, jump 2 beyond this module
30+
# Regenerate $mod/$ice, and $mod/$ice+1, first running handler
31+
local -a output
32+
-zui_std_anchor "append_next" "1+2" "" ",mod${mod}_ice${ice},mod${mod}_ice$(( ice + 1 ))," "" "${ZUI[MAGENTA]}Append next!${ZUI[FMT_END]}" "-zui_std_set_mod_factor $mod $(( REPLY + 1 ))" output
33+
fi
34+
35+
# Content
36+
reply=( "This is module $mod, instance $ice" ${output[1]} )
37+
38+
# Non-selectable lines Hops to jump with [ and ] Local anchors (if output[1] not empty ...)
39+
reply2=( 1 ) reply3=( 1 ) reply4=( ${output[1]:+append_next} )
3240
}
3341

3442
## Start application ##

demos/zui-demo-buttons

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
2+
# vim: ft=zsh sw=2 ts=2 et
3+
#
4+
# ZUI demo: buttons
5+
#
16
# Started from Zle or from command line
27
#
38
# Shows all types of hyperlinks, from raw-links to internal-inline links
49

510
-zui_std_cleanup deserialize:"zui-demo-buttons"
611
-zui_std_init app:"zui-demo-buttons" app_name:"ZUI Buttons"
7-
emulate -LR zsh -o extended_glob -o typeset_silent -o warn_create_global
12+
13+
builtin emulate -LR zsh
14+
builtin setopt extended_glob typeset_silent warn_create_global
15+
816
-zui_std_init2 # after emulate -LR
917

1018
-zui_std_store_default_app_config b:border 1
@@ -62,5 +70,3 @@ zui-event-loop 1:demo_generator_A
6270
-zui_std_cleanup serialize
6371

6472
return 0
65-
66-
# vim:ft=zsh

demos/zui-demo-configure

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
2+
# vim: ft=zsh sw=2 ts=2 et
3+
#
4+
# ZUI demo: configure/make
5+
#
16
# Started from Zle or from command line
27

38
-zui_std_cleanup deserialize:"zui-demo-configure"
49
-zui_std_init app:"zui-demo-configure" app_name:"ZUI Configure/Make wrapper"
5-
emulate -LR zsh -o extended_glob -o typeset_silent -o warn_create_global
10+
11+
builtin emulate -LR zsh
12+
builtin setopt extended_glob typeset_silent warn_create_global
13+
614
-zui_std_init2 # after emulate -LR
715

816
-zui_std_store_default_app_config s:timeout 300
@@ -12,45 +20,45 @@ local -a coproc_output
1220
local cstarted=0 mstarted=0 # denote if configure/make is running
1321

1422
demo_generator_A() {
15-
local mod="$1" ice="$2"
23+
local mod="$1" ice="$2"
1624

17-
reply=()
18-
-zui_std_rc_button "button1" "${ZUI[MAGENTA]}Run configure${ZUI[FMT_END]}" 'internal=1; coproc 2>&1 ./configure; cstarted=1'
19-
-zui_std_rc_button "button2" "${ZUI[MAGENTA]}Get CFLAGS${ZUI[FMT_END]}" 'internal=1; get_cflags'
20-
-zui_std_rc_button "button3" "${ZUI[MAGENTA]}Run make${ZUI[FMT_END]}" 'internal=1; coproc 2>&1 make; mstarted=1'
25+
reply=()
26+
-zui_std_rc_button "button1" "${ZUI[MAGENTA]}Run configure${ZUI[FMT_END]}" 'internal=1; coproc 2>&1 ./configure; cstarted=1'
27+
-zui_std_rc_button "button2" "${ZUI[MAGENTA]}Get CFLAGS${ZUI[FMT_END]}" 'internal=1; get_cflags'
28+
-zui_std_rc_button "button3" "${ZUI[MAGENTA]}Run make${ZUI[FMT_END]}" 'internal=1; coproc 2>&1 make; mstarted=1'
2129

22-
# Content
23-
reply=( "${reply[1]} ${reply[2]} ${reply[3]}" )
30+
# Content
31+
reply=( "${reply[1]} ${reply[2]} ${reply[3]}" )
2432

25-
# Non-selectable lines Hops to jump with [ and ] Local anchors
26-
reply2=( ) reply3=( 1 ) reply4=( )
33+
# Non-selectable lines Hops to jump with [ and ] Local anchors
34+
reply2=( ) reply3=( 1 ) reply4=( )
2735
}
2836

2937
demo_generator_B() {
30-
reply=()
31-
-zui_std_special_text "Configure/Make output"
32-
-zui_std_button "button4" "${ZUI[MAGENTA]}(clear)${ZUI[FMT_END]}" 'internal=1; coproc_output=( ); -zui_std_fly_mod_regen 2 1'
33-
reply=( "${ZUI[YELLOW]}${reply[1]}${ZUI[FMT_END]} ${reply[2]}" "${coproc_output[@]}" ) reply2=( ) reply3=( 1 ) reply4=( )
38+
reply=()
39+
-zui_std_special_text "Configure/Make output"
40+
-zui_std_button "button4" "${ZUI[MAGENTA]}(clear)${ZUI[FMT_END]}" 'internal=1; coproc_output=( ); -zui_std_fly_mod_regen 2 1'
41+
reply=( "${ZUI[YELLOW]}${reply[1]}${ZUI[FMT_END]} ${reply[2]}" "${coproc_output[@]}" ) reply2=( ) reply3=( 1 ) reply4=( )
3442
}
3543

3644
# Read & publish configure/make output
3745
-zui-standard-timeout-callback() {
38-
(( mstarted + cstarted == 0 )) && return
46+
(( mstarted + cstarted == 0 )) && return
3947

40-
local line had_read=0
41-
repeat 20; do
42-
read -r -p -t 0 line 2>/dev/null && { had_read=1; coproc_output+=( "$line" ); } || break
43-
done
48+
local line had_read=0
49+
repeat 20; do
50+
read -r -p -t 0 line 2>/dev/null && { had_read=1; coproc_output+=( "$line" ); } || break
51+
done
4452

45-
(( had_read )) && -zui_std_fly_mod_regen 2 1
46-
(( mstarted != 0 && had_read == 0 )) && [[ "${jobtexts[*]}" != *make* ]] && { ZUI[redraw]=1; mstarted=0; -zui_std_stalog "Message: " "make ended"; }
47-
(( cstarted != 0 && had_read == 0 )) && [[ "${jobtexts[*]}" != *configure* ]] && { ZUI[redraw]=1; cstarted=0; -zui_std_stalog "Message: " "configure ended"; }
53+
(( had_read )) && -zui_std_fly_mod_regen 2 1
54+
(( mstarted != 0 && had_read == 0 )) && [[ "${jobtexts[*]}" != *make* ]] && { ZUI[redraw]=1; mstarted=0; -zui_std_stalog "Message: " "make ended"; }
55+
(( cstarted != 0 && had_read == 0 )) && [[ "${jobtexts[*]}" != *configure* ]] && { ZUI[redraw]=1; cstarted=0; -zui_std_stalog "Message: " "configure ended"; }
4856
}
4957

5058
get_cflags() {
51-
local CFLAGS=`grep '^CFLAGS[[:space:]]*=' Makefile`
52-
-zui_std_stalog "Obtained: " "CFLAGS = ${CFLAGS#*=[[:space:]]##}"
53-
return 1
59+
local CFLAGS=`grep '^CFLAGS[[:space:]]*=' Makefile`
60+
-zui_std_stalog "Obtained: " "CFLAGS = ${CFLAGS#*=[[:space:]]##}"
61+
return 1
5462
}
5563

5664
## Start application ##
@@ -59,5 +67,3 @@ zui-event-loop 1:demo_generator_A 1:demo_generator_B
5967
-zui_std_cleanup serialize
6068

6169
return 0
62-
63-
# vim:ft=zsh

demos/zui-demo-edit

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
2+
# vim: ft=zsh sw=2 ts=2 et
3+
#
4+
# ZUI demo: edit
5+
#
16
# Started from Zle or from command line
27
#
38
# Text editor supporting maximum 1000 lines, 6000 with Zsh 5.3.2
49

510
-zui_std_cleanup deserialize:"zui-demo-edit"
611
-zui_std_init app:"zui-demo-edit" app_name:"ZUI Text Editor"
7-
emulate -LR zsh -o extended_glob -o typeset_silent -o warn_create_global
12+
13+
builtin emulate -LR zsh
14+
builtin setopt extended_glob typeset_silent warn_create_global
15+
816
-zui_std_init2 # after emulate -LR
917

1018
-zui_std_store_default_app_config s:status_size 3
@@ -18,34 +26,34 @@ local -a lines logs
1826
{ lines=( "${(@f)"$(<$edited_file)"}" ); } 2>/dev/null
1927

2028
demo_generator_A() {
21-
local mod="$1" ice="$2"
29+
local mod="$1" ice="$2"
2230

23-
reply=()
24-
-zui_std_rc_button "button_save_$ice" "${ZUI[RED]}Save${ZUI[FMT_END]}" 'internal=1; print -rl -- "${lines[@]}" > "$edited_file" && logs+=( "File saved" ) || logs+=( "Save failed" )'
25-
-zui_std_rc_button "button_relo_$ice" "${ZUI[RED]}Reload${ZUI[FMT_END]}" 'internal=1; lines=( "${(@f)"$(<$edited_file)"}" ) && logs+=( "File \`$edited_file'"'"' loaded" ); -zui_std_fly_mod_regen 2 1'
26-
-zui_std_rc_button "button_addl_$ice" "${ZUI[RED]}Add line${ZUI[FMT_END]}" 'internal=1; lines+=( "" ); -zui_std_fly_mod_regen 2 1'
27-
-zui_std_rc_button "button_remo_$ice" "${ZUI[RED]}Remove line${ZUI[FMT_END]}" 'internal=1; lines[-1]=( ); -zui_std_fly_mod_regen 2 1'
31+
reply=()
32+
-zui_std_rc_button "button_save_$ice" "${ZUI[RED]}Save${ZUI[FMT_END]}" 'internal=1; print -rl -- "${lines[@]}" > "$edited_file" && logs+=( "File saved" ) || logs+=( "Save failed" )'
33+
-zui_std_rc_button "button_relo_$ice" "${ZUI[RED]}Reload${ZUI[FMT_END]}" 'internal=1; lines=( "${(@f)"$(<$edited_file)"}" ) && logs+=( "File \`$edited_file'"'"' loaded" ); -zui_std_fly_mod_regen 2 1'
34+
-zui_std_rc_button "button_addl_$ice" "${ZUI[RED]}Add line${ZUI[FMT_END]}" 'internal=1; lines+=( "" ); -zui_std_fly_mod_regen 2 1'
35+
-zui_std_rc_button "button_remo_$ice" "${ZUI[RED]}Remove line${ZUI[FMT_END]}" 'internal=1; lines[-1]=( ); -zui_std_fly_mod_regen 2 1'
2836

29-
# Content
30-
reply=( "${ZUI[YELLOW]}$edited_file${ZUI[FMT_END]}" "${reply[*]}" )
37+
# Content
38+
reply=( "${ZUI[YELLOW]}$edited_file${ZUI[FMT_END]}" "${reply[*]}" )
3139

32-
# Non-selectable lines Hops to jump with [ and ] Local anchors
33-
reply2=( 1 ) reply3=( 1 ) reply4=( )
40+
# Non-selectable lines Hops to jump with [ and ] Local anchors
41+
reply2=( 1 ) reply3=( 1 ) reply4=( )
3442
}
3543

3644
demo_generator_B() {
37-
local mod="$1" ice="$2"
38-
39-
integer size=${#lines} idx
40-
local -a output
41-
for (( idx=1; idx <= size; idx ++ )); do
42-
reply=() # use the output immediately to utilize array-append optimizations of zsh 5.3.2
43-
noglob -zui_std_text_field "tfield${idx}" width offset lines[$idx]
44-
output+=( "${reply[1]}" )
45-
done
46-
47-
# Content Non-selectable lines Hops to jump with [ and ] Local anchors
48-
reply=( $output ) reply2=( ) reply3=( 1 ) reply4=( )
45+
local mod="$1" ice="$2"
46+
47+
integer size=${#lines} idx
48+
local -a output
49+
for (( idx=1; idx <= size; idx ++ )); do
50+
reply=() # use the output immediately to utilize array-append optimizations of zsh 5.3.2
51+
noglob -zui_std_text_field "tfield${idx}" width offset lines[$idx]
52+
output+=( "${reply[1]}" )
53+
done
54+
55+
# Content Non-selectable lines Hops to jump with [ and ] Local anchors
56+
reply=( $output ) reply2=( ) reply3=( 1 ) reply4=( )
4957
}
5058

5159
-zui-standard-status-callback() { [[ "${#logs}" -gt 0 ]] && { reply=( "Message: " "${logs[1]}" ); logs=( ${(@)logs[2,-1]} ); return 1; }; return 0; }
@@ -56,5 +64,3 @@ zui-event-loop 1:demo_generator_A 1:demo_generator_B 1:demo_generator_A
5664
-zui_std_cleanup serialize
5765

5866
return 0
59-
60-
# vim:ft=zsh

demos/zui-demo-fly

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
2+
# vim: ft=zsh sw=2 ts=2 et
3+
#
4+
# ZUI demo: fly
5+
#
16
# Started from Zle or from command line
27

38
-zui_std_cleanup deserialize:"zui-demo-fly"
49
-zui_std_init app:"zui-demo-fly" app_name:"ZUI On-The-Fly Regeneration"
5-
emulate -LR zsh -o extended_glob -o typeset_silent -o warn_create_global
10+
11+
builtin emulate -LR zsh
12+
builtin setopt extended_glob typeset_silent warn_create_global
13+
614
-zui_std_init2 # after emulate -LR
715

816
-zui_std_store_default_app_config b:border 1
@@ -13,31 +21,31 @@ local internal # trick variable to make a handler no-restart
1321

1422
# Generator for module 1
1523
demo_generator_A() {
16-
local mod="$1" ice="$2"
24+
local mod="$1" ice="$2"
1725

18-
reply=()
19-
-zui_std_rc_button_ext "restart" "" "" ",mod1_ice1," "" "${ZUI[MAGENTA]}restart${ZUI[FMT_END]}"
20-
-zui_std_rc_button "on-the-fly" "${ZUI[MAGENTA]}on-the-fly${ZUI[FMT_END]}" 'internal=1; -zui_std_fly_mod_regen "'"$mod"'" "'"$ice"'"'
26+
reply=()
27+
-zui_std_rc_button_ext "restart" "" "" ",mod1_ice1," "" "${ZUI[MAGENTA]}restart${ZUI[FMT_END]}"
28+
-zui_std_rc_button "on-the-fly" "${ZUI[MAGENTA]}on-the-fly${ZUI[FMT_END]}" 'internal=1; -zui_std_fly_mod_regen "'"$mod"'" "'"$ice"'"'
2129

22-
# Content
23-
reply=( "${ZUI[YELLOW]}ZUI${ZUI[FMT_END]} can regenerate module instance with ${reply[1]} or ${reply[2]}!" "Random number: $RANDOM" )
30+
# Content
31+
reply=( "${ZUI[YELLOW]}ZUI${ZUI[FMT_END]} can regenerate module instance with ${reply[1]} or ${reply[2]}!" "Random number: $RANDOM" )
2432

25-
# Non-selectable lines Hops to jump with [ and ] Local anchors
26-
reply2=( 2 ) reply3=( 1 ) reply4=( )
33+
# Non-selectable lines Hops to jump with [ and ] Local anchors
34+
reply2=( 2 ) reply3=( 1 ) reply4=( )
2735
}
2836

2937
# Show handler code in status window
3038
-zui-standard-status-callback() {
31-
local tpe="$1" selectable="$2" uniq="$3" search="$4" line="$5" segment="$6"
32-
[[ "$tpe" = "0" ]] && return 0 # Filter out non-hyperlinks
39+
local tpe="$1" selectable="$2" uniq="$3" search="$4" line="$5" segment="$6"
40+
[[ "$tpe" = "0" ]] && return 0 # Filter out non-hyperlinks
3341

34-
shift 6; local id="$1" data1="$2" data2="$3" data3="$4" data4="$5"
35-
id="${id#(zuiiaction|zuiaction|zuicheckbox|zuieanchor|zuianchor|zuitfield)}"
36-
handler="${ZUI[zuiiaction$id]}"
37-
reply=( "Handler: " "$handler" )
42+
shift 6; local id="$1" data1="$2" data2="$3" data3="$4" data4="$5"
43+
id="${id#(zuiiaction|zuiaction|zuicheckbox|zuieanchor|zuianchor|zuitfield)}"
44+
handler="${ZUI[zuiiaction$id]}"
45+
reply=( "Handler: " "$handler" )
3846

39-
# Resulting type: 1 - log message
40-
return 1
47+
# Resulting type: 1 - log message
48+
return 1
4149
}
4250

4351
## Start application ##
@@ -46,5 +54,3 @@ zui-event-loop 1:demo_generator_A
4654
-zui_std_cleanup serialize
4755

4856
return 0
49-
50-
# vim:ft=zsh

0 commit comments

Comments
 (0)