ao-mud is a spellbook of well-commented atomic bash scripts that each do one thing. we are building semantic building blocks for an autonomously-evolving digital spellcasting language.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.0 KiB

#!/bin/sh
# bg_log: a script to output a message from a background process, while taking
# into account the user's current input and preserving it.
#
# Cast this spell to send a message from a background process to the terminal,
# without interrupting or overwriting the user's input.
# todo: refactor this to use the cursor file
bg_log() {
# Save the current cursor position
printf '\033[s'
# Calculate the number of lines used by the user's input
lines=$(current_input_lines)
# Move the cursor up the number of lines used by the user's input
printf '\033[%dA' "$lines"
# Clear the current line
printf '\033[2K'
# Output the message
printf '%s\n' "$@"
# Clear the current line
printf '\033[2K'
# Move the cursor down the number of lines used by the user's input
printf '\033[%dB' "$lines"
# Restore the cursor position
printf '\033[u'
}
# Check if the script is being executed or sourced
if [ "$0" = "$BASH_SOURCE" ]; then
# Script is being executed, call the bg_log function to output a message
bg_log $1
fi