Skip to content

Commit 4143e67

Browse files
committed
Bash functions: introduce moulti_process_lines.
1 parent 59f0e5b commit 4143e67

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

examples/moulti-functions.bash

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,34 @@ function moulti_type {
7070
# No sleep because this hack is already inefficient enough.
7171
done
7272
}
73+
74+
MOULTI_NEW_STEP_PATTERN='^([-=#@]+)(\s*)(.+?)\2\1$'
75+
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+
local step_counter=0
82+
while read -r line; do
83+
if [[ "${line}" =~ ${MOULTI_NEW_STEP_PATTERN} ]]; then
84+
((++step_counter))
85+
local prev_id="${step_id}"
86+
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}"
90+
else
91+
step_id="${next_id}"
92+
moulti step add "${step_id}" --title="${line}" --bottom-text=' ' --scroll-on-activity=-1 < /dev/null
93+
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+
fi
102+
done
103+
}

0 commit comments

Comments
 (0)