From 76557c53f60bab75459db03e29c50f5d6ae55309 Mon Sep 17 00:00:00 2001 From: jao Date: Thu, 3 Feb 2022 23:52:42 +0000 Subject: Xmobar.X11.Actions -> Xmobar.Run.Actions --- src/Xmobar/Run/Actions.hs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/Xmobar/Run/Actions.hs (limited to 'src/Xmobar/Run') diff --git a/src/Xmobar/Run/Actions.hs b/src/Xmobar/Run/Actions.hs new file mode 100644 index 0000000..f7d0e45 --- /dev/null +++ b/src/Xmobar/Run/Actions.hs @@ -0,0 +1,36 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Xmobar.Run.Actions +-- Copyright : (c) Alexander Polakov +-- License : BSD-style (see LICENSE) +-- +-- Maintainer : Jose A. Ortega Ruiz +-- Stability : unstable +-- Portability : unportable +-- +----------------------------------------------------------------------------- + +module Xmobar.Run.Actions (Button, Action(..), runAction, stripActions) where + +import System.Process (system) +import Control.Monad (void) +import Text.Regex (Regex, subRegex, mkRegex, matchRegex) +import Data.Word (Word32) + +type Button = Word32 + +data Action = Spawn [Button] String + deriving (Eq, Show) + +runAction :: Action -> IO () +runAction (Spawn _ s) = void $ system (s ++ "&") + +stripActions :: String -> String +stripActions s = case matchRegex actionRegex s of + Nothing -> s + Just _ -> stripActions strippedOneLevel + where + strippedOneLevel = subRegex actionRegex s "[action=\\1\\2]\\3[/action]" + +actionRegex :: Regex +actionRegex = mkRegex "`]*)`?( +button=[12345]+)?>(.+)" -- cgit v1.2.3