This commit is contained in:
parent
506fc04054
commit
ccf3d391dd
1 changed files with 8 additions and 42 deletions
50
index.ts
50
index.ts
|
@ -105,48 +105,14 @@ program
|
||||||
});
|
});
|
||||||
|
|
||||||
program.command("init").action(() => {
|
program.command("init").action(() => {
|
||||||
console.log(`# Real-time output processing version
|
console.log(`${CLI_NAME}() {
|
||||||
function pcli() {
|
command ${CLI_NAME} "$@" | while IFS= read -r line; do
|
||||||
local cli_command="$1"
|
if [[ $line == __EXEC__* ]]; then
|
||||||
shift
|
eval "\${line#__EXEC__}"
|
||||||
|
else
|
||||||
# Use unbuffer to force line buffering, or stdbuf if available
|
echo "$line"
|
||||||
if command -v unbuffer >/dev/null 2>&1; then
|
fi
|
||||||
# unbuffer from expect package - best option
|
done
|
||||||
unbuffer "$cli_command" "$@" | while IFS= read -r line; do
|
|
||||||
if [[ "$line" =~ ^__EXEC__[[:space:]]*(.*) ]]; then
|
|
||||||
local cmd="\${match[1]}"
|
|
||||||
echo "Executing: $cmd"
|
|
||||||
eval "$cmd"
|
|
||||||
else
|
|
||||||
echo "$line"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
elif command -v stdbuf >/dev/null 2>&1; then
|
|
||||||
# stdbuf - force line buffering
|
|
||||||
stdbuf -oL "$cli_command" "$@" | while IFS= read -r line; do
|
|
||||||
if [[ "$line" =~ ^__EXEC__[[:space:]]*(.*) ]]; then
|
|
||||||
local cmd="\${match[1]}"
|
|
||||||
echo "Executing: $cmd"
|
|
||||||
eval "$cmd"
|
|
||||||
else
|
|
||||||
echo "$line"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
else
|
|
||||||
# Fallback using script to simulate a terminal
|
|
||||||
script -q /dev/null "$cli_command" "$@" | while IFS= read -r line; do
|
|
||||||
# Remove any terminal escape sequences that script might add
|
|
||||||
line=$(echo "$line" | sed 's/\\x1b\\[[0-9;]*m//g')
|
|
||||||
if [[ "$line" =~ ^__EXEC__[[:space:]]*(.*) ]]; then
|
|
||||||
local cmd="\${match[1]}"
|
|
||||||
echo "Executing: $cmd"
|
|
||||||
eval "$cmd"
|
|
||||||
else
|
|
||||||
echo "$line"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}`);
|
}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue