From 4d1402a1a7d87767267d48a77998e4fb13395b31 Mon Sep 17 00:00:00 2001 From: Pavan Rikhi Date: Sat, 17 Mar 2018 22:48:24 -0400 Subject: Split Modules into Library & Executable Structure Move the Main module to a new `app` directory. All other modules have been nested under the `Xmobar` name. Lots of module headers & imports were updated. --- src/Xmobar/Plugins/Monitors/Wireless.hs | 70 +++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/Xmobar/Plugins/Monitors/Wireless.hs (limited to 'src/Xmobar/Plugins/Monitors/Wireless.hs') diff --git a/src/Xmobar/Plugins/Monitors/Wireless.hs b/src/Xmobar/Plugins/Monitors/Wireless.hs new file mode 100644 index 0000000..545f6bc --- /dev/null +++ b/src/Xmobar/Plugins/Monitors/Wireless.hs @@ -0,0 +1,70 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Plugins.Monitors.Wireless +-- Copyright : (c) Jose Antonio Ortega Ruiz +-- License : BSD-style (see LICENSE) +-- +-- Maintainer : Jose Antonio Ortega Ruiz +-- Stability : unstable +-- Portability : unportable +-- +-- A monitor reporting ESSID and link quality for wireless interfaces +-- +----------------------------------------------------------------------------- + +module Xmobar.Plugins.Monitors.Wireless (wirelessConfig, runWireless) where + +import System.Console.GetOpt + +import Xmobar.Plugins.Monitors.Common +import Network.IWlib + +newtype WirelessOpts = WirelessOpts + { qualityIconPattern :: Maybe IconPattern + } + +defaultOpts :: WirelessOpts +defaultOpts = WirelessOpts + { qualityIconPattern = Nothing + } + +options :: [OptDescr (WirelessOpts -> WirelessOpts)] +options = + [ Option "" ["quality-icon-pattern"] (ReqArg (\d opts -> + opts { qualityIconPattern = Just $ parseIconPattern d }) "") "" + ] + +parseOpts :: [String] -> IO WirelessOpts +parseOpts argv = + case getOpt Permute options argv of + (o, _, []) -> return $ foldr id defaultOpts o + (_, _, errs) -> ioError . userError $ concat errs + +wirelessConfig :: IO MConfig +wirelessConfig = + mkMConfig " " + ["essid", "quality", "qualitybar", "qualityvbar", "qualityipat"] + +runWireless :: String -> [String] -> Monitor String +runWireless iface args = do + opts <- io $ parseOpts args + iface' <- if "" == iface then io findInterface else return iface + wi <- io $ getWirelessInfo iface' + na <- getConfigValue naString + let essid = wiEssid wi + qlty = fromIntegral $ wiQuality wi + e = if essid == "" then na else essid + ep <- showWithPadding e + q <- if qlty >= 0 + then showPercentWithColors (qlty / 100) + else showWithPadding "" + qb <- showPercentBar qlty (qlty / 100) + qvb <- showVerticalBar qlty (qlty / 100) + qipat <- showIconPattern (qualityIconPattern opts) (qlty / 100) + parseTemplate [ep, q, qb, qvb, qipat] + +findInterface :: IO String +findInterface = do + c <- readFile "/proc/net/wireless" + let nds = lines c + return $ if length nds > 2 then takeWhile (/= 'c') (nds!!2) else [] -- cgit v1.2.3