geommer / yabar

A modern and lightweight status bar for X window managers.
MIT License
680 stars 49 forks source link

type persist causes a glitchily rendered block #185

Open AveryLychee opened 6 years ago

AveryLychee commented 6 years ago

I have a script to convert my bspwm status into something slightly prettier (shown below, in case it's relevant). When run in the terminal, this produces 1 line per bspwm update, and the line is always exactly the same length.

However, when I have this configuration for my block:

    wm: {
        exec: "bspformat.hs";
        type: "persist";
        variable-size: true;
        foreground-color-rgb: 0xe1bcc8;
        background-color-argb: 0xFF1d2c47;
    }

The result is very glitchy - sometimes it shows the full output, sometimes it only shows parts of it. Other times it also displays parts of the bspc subscribe command's output mixed in with the formatted output.

I get the same glitchy results if I write the script to take stdin and use exec: "bspc subscribe | format_script.hs" in my block

The formatting script:

#!/usr/bin/env runhaskell

import System.IO
import Control.Monad
import System.Process

main = do hSetBuffering stdin LineBuffering
          (_, Just bspcHandle, _, _) <- createProcess (proc "bspc" ["subscribe"]){ std_out = CreatePipe }
          forever $ do hGetLine bspcHandle >>= putStrLn . format

format "" = ""
format s = let (current, rest) = break (==':') s
           in (case current of
             'O':occFocused     -> " [ " ++ occFocused    ++ " ] "
             'o':occUnfocused   -> "   " ++ occUnfocused  ++ "   "
             'F':freeFocused    -> " | " ++ freeFocused   ++ " | "
             'f':freeUnfocused  -> "   " ++ freeUnfocused ++ "   "
             'U':urgFocused     -> " [[" ++ urgFocused    ++ "]] "
             'u':urgUnfocused   -> " ! " ++ urgUnfocused    ++ " ! "
             'L':layout         -> "   " ++ layout
             _                  -> ""
             ) ++ format (fix rest)
        where
          fix (':':s) = s
          fix s = s
Emmk commented 6 years ago

I see the same on multiple bash scripts, that produce perfect outputs if run in a terminal One of which is actually a type periodic, and yet produces this weird rendering.

My first script prints the current battery status formatted like this: % I either:

  1. Get the full output
  2. Get the battery icon
  3. Get the percentage
  4. Get nothing

My other script prints the total network activity in the last second; this one is periodic, and is formatted like this: As for its rendering, the same happens as with the previous one. The 2 values are separated by n spaces depending on their lengths, each line having the exact same length. Both blocks have more than enough space reserved with a fixed-size.

Both of these scripts have a central space char in their ouput, so the problem should revolve around spaces.