@@ -74,30 +74,42 @@ function moulti_type {
74
74
MOULTI_NEW_STEP_PATTERN=' ^([-=#@]+)(\s*)(.+?)\2\1$'
75
75
76
76
function moulti_process_lines {
77
- # Optional user hooks:
78
- command -v moulti_make_step > /dev/null && custom_make_step=1
79
- command -v moulti_inspect_line > /dev/null && inspect_line=1
80
- # Main loop:
81
77
local step_counter=0
78
+ IFS=' '
82
79
while read -r line; do
83
80
if [[ " ${line} " =~ ${MOULTI_NEW_STEP_PATTERN} ]]; then
84
81
(( ++ step_counter))
85
82
local prev_id=" ${step_id} "
86
83
local next_id=" $$ _${step_counter} "
87
- if [ " ${custom_make_step} " ]; then
88
- step_id=$( moulti_make_step " ${prev_id} " " ${next_id} " " ${line} " " ${BASH_REMATCH[@]} " < /dev/null)
89
- [ " ${step_id} " ] || step_id=" ${prev_id} "
84
+ step_id=$( moulti_make_step " ${prev_id} " " ${next_id} " " ${line} " " ${BASH_REMATCH[@]} " < /dev/null)
85
+ if [ " ${step_id} " ] && [ " ${step_id} " != " ${prev_id} " ]; then
86
+ # Redirect stdout to `moulti pass our_new_step`
87
+ exec > >( moulti pass " ${step_id} " )
90
88
else
91
- step_id=" ${next_id} "
92
- moulti step add " ${step_id} " --title=" ${line} " --bottom-text=' ' --scroll-on-activity=-1 < /dev/null
89
+ step_id=" ${prev_id} "
93
90
fi
94
- # Redirect stdout to `moulti pass our_new_step`
95
- exec > >( moulti pass " ${step_id} " )
96
- fi
97
- if [ " ${inspect_line} " ]; then
98
- moulti_inspect_line " ${line} " " ${step_id} " < /dev/null
99
- else
100
- printf ' %s\n' " ${line} "
101
91
fi
92
+ moulti_inspect_line " ${line} " " ${step_id} " < /dev/null
102
93
done
103
94
}
95
+
96
+ # Arguments:
97
+ # 1: previous step id
98
+ # 2: next step id (suggestion)
99
+ # 3: current line (complete, no CR/LF)
100
+ # 4: matched substring
101
+ # 5: capture #1
102
+ # 6: capture #2, etc.
103
+ # This function MUST output the id of the created step.
104
+ function moulti_make_step {
105
+ # Default implementation: use the complete line as title:
106
+ moulti step add " $2 " --title=" $3 " --bottom-text=' ' --scroll-on-activity=-1 && echo " $2 "
107
+ }
108
+
109
+ # Arguments:
110
+ # 1: current line (complete, no CR/LF)
111
+ # 2: current step id
112
+ function moulti_inspect_line {
113
+ # Default implementation: systematically output the line:
114
+ printf ' %s\n' " ${line} "
115
+ }
0 commit comments