# Some common functions for CliFM plugins
# Author: L. Abramovich
# License: GPL3

cmd_exists()
{
	if type "$1" > /dev/null 2>&1; then
		echo "1";
	else
		echo "0";
	fi
}

# Get the current terminal amount of supported colors: normally 8 or 256
term_colors()
{
	if type tput > /dev/null 2>&1; then
		echo "$(tput colors)"
	else
		echo "8"
	fi
}

# Return the appropriate value for FZF --color option, honoring no-color
# directives
get_fzf_colors()
{
	if [ -n "$CLIFM_NO_COLOR" ] || [ -n "$NO_COLOR" ] \
	|| [ -n "$CLIFM_COLORLESS" ]; then
		echo "bw"
	else
		echo "16,prompt:6,fg+:-1,pointer:2,marker:2,hl:5,hl+:5,gutter:-1"
	fi
}

# Make sure FZF interface won't be messed up when running on an 8 bit
# terminal emulator
fzf_borders()
{
	if [ "$(term_colors)" -eq 256 ]; then
		echo "--border=left"
	else
		echo "--no-unicode"
	fi
}

# A few fixed values to construct the FZF interface
fzf_height="${CLIFM_FZF_HEIGHT:-80}%"
fzf_prompt="Clifm > "
colorize=1
[ -n "$CLIFM_COLORLESS" ] && colorize=0
