xmobar -> test own Modules

This commit is contained in:
2024-03-16 16:05:46 +01:00
parent c38b8b4264
commit 012ec94106
4 changed files with 45 additions and 13 deletions

View File

@@ -0,0 +1,25 @@
-----------------------------------------------------------------------------
-- |
-- Module : Xmobar.Plugins
-- Copyright : (c) Andrea Rossato
-- License : BSD-style (see LICENSE)
--
-- Maintainer : Jose A. Ortega Ruiz <jao@gnu.org>
-- Stability : unstable
-- Portability : unportable
--
-- This module exports the API for plugins.
--
-- Have a look at Plugins\/HelloWorld.hs
--
-----------------------------------------------------------------------------
module Plugins
( Exec (..)
, tenthSeconds
, readFileSafe
, hGetLineSafe
) where
import Commands
import XUtil

View File

@@ -1,4 +1,4 @@
----------------------------------------------------------------------------- -- -----------------------------------------------------------------------------
-- | -- |
-- Module : Plugins.Audio -- Module : Plugins.Audio
-- Copyright : (c) Elias Schröter -- Copyright : (c) Elias Schröter
@@ -16,8 +16,9 @@
module Plugins.Audio where module Plugins.Audio where
import Plugins --import Plugins
import System.Process import System.Process
import GHC.Show (Show(show))
-- | Color for Muted -- | Color for Muted
type MuteColor = String type MuteColor = String
@@ -25,6 +26,8 @@ type MuteColor = String
type UnMuteColor = String type UnMuteColor = String
-- | The Icon of the muted Speaker -- | The Icon of the muted Speaker
type SpeakerMuteIcon = String type SpeakerMuteIcon = String
-- | The Icon of half volume Speaker
type SpeakerHalfIcon = String
-- | The Icon of the unmuted Speaker -- | The Icon of the unmuted Speaker
type SpeakerIcon = String type SpeakerIcon = String
-- | The Icon of the muted Microphone -- | The Icon of the muted Microphone
@@ -32,7 +35,7 @@ type MicrophoneMuteIcon = String
-- | The Icon of the unmuted Microphone -- | The Icon of the unmuted Microphone
type MicrophoneIcon = String type MicrophoneIcon = String
data Audio = Audio MuteColor UnMuteColor SpeakerMuteIcon SpeakerIcon MicrophoneMuteIcon MicrophoneIcon Int deriving (Read, Show) data Audio = Audio MuteColor UnMuteColor SpeakerMuteIcon SpeakerHalfIcon SpeakerIcon MicrophoneMuteIcon MicrophoneIcon Int deriving (Read, Show)
-- | Counts the days to a specific date from today. This function returns the number -- | Counts the days to a specific date from today. This function returns the number
-- of days followed by a String -- of days followed by a String
@@ -44,10 +47,10 @@ cdw y m d s = do currentTime <- getCurrentTime
getAudio :: MuteColor -> UnMuteColor -> SpeakerMuteIcon -> SpeakerIcon -> MicrophoneMuteIcon -> MicrophoneIcon -> IO String getAudio :: MuteColor -> UnMuteColor -> SpeakerMuteIcon -> SpeakerIcon -> MicrophoneMuteIcon -> MicrophoneIcon -> IO String
getAudio mC umC smI sI mmI mI = do getAudio mC umC smI sI mmI mI = do
let status = readProcess "pulseaudio-ctl full-status" let status = words readProcess "pulseaudio-ctl full-status"
let infoList = [w | w <- words status] return $ show status
instance Exec Countdown where instance Exec Audio where
alias ( Audio _ _ _ _ _ _ _) = "audio" alias ( Audio {}) = "audio"
run ( Audio mC umC smI sI mmI mI _ ) = getAudio run ( Audio mC umC smI shI sI mmI mI _ ) = getAudio
rate ( Countdown _ _ _ _ _ _ r ) = r rate ( Audio _ _ _ _ _ _ _ r ) = r

View File

@@ -23,10 +23,10 @@ name: xmobar-custom
version: 0.1.0.0 version: 0.1.0.0
-- The package author(s). -- The package author(s).
author: einfischy author: 4Lost
-- An email address to which users can send suggestions, bug reports, and patches. -- An email address to which users can send suggestions, bug reports, and patches.
maintainer: accounts.codeberg@kstn.in maintainer: elias.schroeter@e.email
-- A copyright notice. -- A copyright notice.
-- copyright: -- copyright:
@@ -42,9 +42,11 @@ executable xmobar
-- .hs or .lhs file containing the Main module. -- .hs or .lhs file containing the Main module.
main-is: xmobar.hs main-is: xmobar.hs
other-modules: Plugins.Audio
-- Other library packages from which modules are imported. -- Other library packages from which modules are imported.
build-depends: base ^>=4.17.2.1, build-depends: base ^>=4.17.2.1,
xmobar ^>=0.47.1 xmobar ^>=0.47.1,
process ^>=1.6.18.0
-- Directories containing source files. -- Directories containing source files.
hs-source-dirs: . hs-source-dirs: .

View File

@@ -1,4 +1,5 @@
import Xmobar import Xmobar
import Plugins.Audio
--import Xmobar.Run.Exec --import Xmobar.Run.Exec
--import Xmobar (Command(ComX)) --import Xmobar (Command(ComX))
--import GHC.Real (Integral(rem)) --import GHC.Real (Integral(rem))
@@ -16,7 +17,7 @@ config =
, fgColor = "#f5e0dc" , fgColor = "#f5e0dc"
, commands = , commands =
[ [
Run $ Com "/bin/sh" ["-c", "Status=$(pulseaudio-ctl full-status); Volume=$(cut -d ' ' -f 1 <<<$Status); Mute=$(cut -d ' ' -f 2 <<<$Status); Microphone=$(cut -d ' ' -f 3 <<<$Status); SpeakerColor=\"#a6e3a1\"; MicColor=\"#a6e3a1\"; if [[ $Mute == \"yes\" ]]; then Symbol=\"\xf466\"; SpeakerColor=\"#f38ba8\"; elif [[ $Volume -le 50 ]]; then Symbol=\"\xf027\"; elseSymbol=\"\xf028\"; fi; if [[ $Microphone == \"yes\" ]]; then MicOut=\"\xf036d\"; MicColor=\"#f38ba8\"; else MicOut=\"\xf036c\"; fi; echo \"<fc=$SpeakerColor><fn=1>$Symbol</fn></fc> $Volume% <fc=$MicColor><fn=1>$MicOut</fn></fc>\""] "audio" 10 --Run $ Com "/bin/sh" ["-c", "Status=$(pulseaudio-ctl full-status); Volume=$(cut -d ' ' -f 1 <<<$Status); Mute=$(cut -d ' ' -f 2 <<<$Status); Microphone=$(cut -d ' ' -f 3 <<<$Status); SpeakerColor=\"#a6e3a1\"; MicColor=\"#a6e3a1\"; if [[ $Mute == \"yes\" ]]; then Symbol=\"\xf466\"; SpeakerColor=\"#f38ba8\"; elif [[ $Volume -le 50 ]]; then Symbol=\"\xf027\"; elseSymbol=\"\xf028\"; fi; if [[ $Microphone == \"yes\" ]]; then MicOut=\"\xf036d\"; MicColor=\"#f38ba8\"; else MicOut=\"\xf036c\"; fi; echo \"<fc=$SpeakerColor><fn=1>$Symbol</fn></fc> $Volume% <fc=$MicColor><fn=1>$MicOut</fn></fc>\""] "audio" 10
--Run $ Com "/bin/sh" ["-c", "Status=$(pulseaudio-ctl full-status); --Run $ Com "/bin/sh" ["-c", "Status=$(pulseaudio-ctl full-status);
-- Volume=$(cut -d ' ' -f 1 <<<$Status); -- Volume=$(cut -d ' ' -f 1 <<<$Status);
-- Mute=$(cut -d ' ' -f 2 <<<$Status); -- Mute=$(cut -d ' ' -f 2 <<<$Status);
@@ -46,6 +47,7 @@ config =
-- "--template", "<fc=<speakerColor>><fn=1><speakerIcon></fn></fc> <Volume>% <fc=<micColor>><fn=1><micIcon></fn></fc>" -- "--template", "<fc=<speakerColor>><fn=1><speakerIcon></fn></fc> <Volume>% <fc=<micColor>><fn=1><micIcon></fn></fc>"
-- , "" "" -- , "" ""
--] 10 --] 10
Run $ Audio "#f38ba8" "#a6e3a1" "\xf466" "\xf027" "\xf027" "\xf036d" "\xf036c" 10
, Run $ Com "/bin/sh" ["-c", "echo \"<fc=#f9e2af><fn=1>\xf00e0</fn></fc> $(xbacklight -get)%\""] "backlight" 10 , Run $ Com "/bin/sh" ["-c", "echo \"<fc=#f9e2af><fn=1>\xf00e0</fn></fc> $(xbacklight -get)%\""] "backlight" 10
, Run $ Cpu , Run $ Cpu
[ [