LemonBoy / bar

A featherweight, lemon-scented, bar based on xcb
MIT License
1.61k stars 194 forks source link

Coloring leaves behind unsightly spaces #216

Closed kaiser-dg closed 6 years ago

kaiser-dg commented 6 years ago

Just what it says on the tin, some colors will leaves spaces behind for some reason. The biggest offender seems to be %{F#FFFF01}. This is the shellscript I'm piping into the bar:

#!/bin/sh

volume() {
    if [ $(pactl list sinks | grep Mute | cut -d: -f2 | cut -d\  -f2) == "yes" ]; then
    echo -e "%{F#FFFF01}\b"
    else
    echo -e "%{F#-}"
    fi
    pactl list sinks | grep '^[[:space:]]Volume:' | \
    head -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,'
    if [ $(mpc status|tail -n2|head -c8) == "[paused]" ]; then
    echo "%{F#FFFF01}"
    else
    echo "%{F#-}"
    fi
    mpc current
    echo "%{F#-}"
}

clock() {
    date +%H:%M:%S
}

battery() {
    cat /sys/class/power_supply/BAT0/capacity /sys/class/power_supply/BAT0/status
}

essid() {
    ESSID=$(nmcli -t -f active,ssid,signal dev wifi | egrep '^yes' | cut -d: -f2)
    if [ "$ESSID" ]; then
    echo "%{F#00FF00}"
    else
    echo "%{F#FF0000} Down!"
    fi
    echo $ESSID
}

ip4addr() {
    ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'
}

cpuload() {
    LINE=`ps -eo pcpu |grep -vE '^\s*(0.0|%CPU)' |sed -n '1h;$!H;$g;s/\n/ +/gp'`
    echo `bc <<< $LINE`
}

memload() {
    read t f <<< `grep -E 'Mem(Total|Free)' /proc/meminfo |awk '{print $2}'`
    read b c <<< `grep -E '^(Buffers|Cached)' /proc/meminfo |awk '{print $2}'`

    # then, calcultate the percentage of memory used

}

while true; do
    BAR_INPUT="%{c}WiFI:$(essid) $(ip4addr) %{F#-} | Volume: $(volume) | Battery: $(battery) | $(date) | CPU load: $(cpuload)"
    echo $BAR_INPUT
    sleep 1
done
LemonBoy commented 6 years ago

Please provide minimal reproducible example and a screenshoot, I {can,won}'t debug such a big script full of moving parts.

kaiser-dg commented 6 years ago

I figured it out. I forgot the -n on the echo statements and the newlines rendered as a space. Sorry for wasting your time.