From 6e124f046b5b92dd3cdfc4a4ea337e3aca4c025d Mon Sep 17 00:00:00 2001 From: jao Date: Fri, 4 Feb 2022 05:53:48 +0000 Subject: swaybar-protocol: very basic format --- src/Xmobar/Text/Swaybar.hs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Xmobar/Text/Swaybar.hs (limited to 'src/Xmobar/Text/Swaybar.hs') diff --git a/src/Xmobar/Text/Swaybar.hs b/src/Xmobar/Text/Swaybar.hs new file mode 100644 index 0000000..a4ee306 --- /dev/null +++ b/src/Xmobar/Text/Swaybar.hs @@ -0,0 +1,39 @@ +------------------------------------------------------------------------------ +-- | +-- Module: Xmobar.Text.Swaybar +-- Copyright: (c) 2022 Jose Antonio Ortega Ruiz +-- License: BSD3-style (see LICENSE) +-- +-- Maintainer: jao@gnu.org +-- Stability: unstable +-- Portability: portable +-- Created: Fri Feb 4, 2022 03:58 +-- +-- +-- Segment codification using swaybar-protocol JSON strings +-- +------------------------------------------------------------------------------ + +module Xmobar.Text.Swaybar (preamble, formatSwaybar) where + +import Data.List (intercalate) + +import Xmobar.Config.Types (Config) + +import Xmobar.Run.Parsers ( Segment + , Widget(..) + -- , tColorsString + -- , colorComponents + ) + +preamble :: String +preamble = "{\"version\": 1, \"click_events\": true}\x0A[" + +formatSwaybar' :: Config -> Segment -> String +formatSwaybar' _conf (Text txt, _, _, _) = + "{\"full_text\":\"" ++ txt ++ "\"}" +formatSwaybar' _ _ = "" + +formatSwaybar :: Config -> [Segment] -> String +formatSwaybar conf segs = + "[" ++ intercalate "," (map (formatSwaybar' conf) segs) ++ "]," -- cgit v1.2.3