#!/bin/sh
#
# Status line applet for terminal emulators to run side by side with main terminal application.
# Although main goal is text-mode apps, runing in terminal emulators in any desktops with taskbar,
# it should be useful in anything that can display status / title, including terminal multiplexors.

# Options (must only be used in status update loop)

interval=1.0
status_cmd="echo No status"

# Setup status line

status_term=
tsl_str=
fsl_str=

status_line_setup()
{
	if tput hs; then
        	status_term="${TERM}"
	elif [ -v DISPLAY ]; then
        	status_term=xterm+sl
	else
		return 1
	fi

	tsl_str="$(tput tsl)"
	fsl_str="$(tput fsl)"
	return 0
}

# Status update loop

status_line_run()
{
	#trap "eval 'kill ${tpid}'" SIGTERM
	while true
	do
		sleep "${interval}" & tpid=$!

		status_text="${tsl_str}$( eval "${status_cmd}" )${fsl_str}"
		echo -n "${status_text}"

		wait ${tpid}
	done
}

