summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPaul Fertser <fercerpav@gmail.com>2020-02-27 10:13:57 +0300
committerjao <jao@gnu.org>2020-03-05 17:52:09 +0000
commitae16735a74a711c0ed7adf6e1df18b75a5a26205 (patch)
tree7202f6ccb8c0da7e72becdb96af81fe6456850d8
parentf9370ebb1242bf4cc8e0a10393321acdd6e02a65 (diff)
downloadxmobar-ae16735a74a711c0ed7adf6e1df18b75a5a26205.tar.gz
xmobar-ae16735a74a711c0ed7adf6e1df18b75a5a26205.tar.bz2
Wireless: fix hlint warnings, reenable CI checks
This makes the code hlint-clean for --cpp-define=USE_NL80211, --cpp-define=IWLIB and without --cpp-define too.
-rw-r--r--.travis.yml2
-rw-r--r--src/Xmobar/Plugins/Monitors/Wireless.hs21
2 files changed, 14 insertions, 9 deletions
diff --git a/.travis.yml b/.travis.yml
index 54b4ee0..9ccfc21 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -27,5 +27,5 @@ install:
- wget https://raw.github.com/ndmitchell/hlint/master/misc/travis.sh
script:
-# - sh ./travis.sh src
+ - sh ./travis.sh src
- cabal configure --enable-tests -fall_extensions && cabal build && cabal test
diff --git a/src/Xmobar/Plugins/Monitors/Wireless.hs b/src/Xmobar/Plugins/Monitors/Wireless.hs
index 1237aa9..bd6d52e 100644
--- a/src/Xmobar/Plugins/Monitors/Wireless.hs
+++ b/src/Xmobar/Plugins/Monitors/Wireless.hs
@@ -1,4 +1,7 @@
-{-# LANGUAGE TypeApplications, CPP #-}
+{-# LANGUAGE CPP #-}
+#ifdef USE_NL80211
+{-# LANGUAGE TypeApplications #-}
+#endif
-----------------------------------------------------------------------------
-- |
-- Module : Plugins.Monitors.Wireless
@@ -16,7 +19,6 @@
module Xmobar.Plugins.Monitors.Wireless (wirelessConfig, runWireless) where
import System.Console.GetOpt
-import Data.Maybe (fromMaybe)
import Xmobar.Plugins.Monitors.Common
@@ -26,7 +28,7 @@ import Network.IWlib
import Control.Exception (bracket)
import qualified Data.Map as M
import GHC.Int (Int8)
-import Data.Maybe (listToMaybe)
+import Data.Maybe (listToMaybe, fromMaybe)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
import Data.ByteString.Char8 (unpack)
@@ -42,12 +44,12 @@ import System.Posix.IO (closeFd)
data IwData = IwData { wiEssid :: String, wiSignal :: Maybe Int, wiQuality :: Int }
getWirelessInfo :: String -> IO IwData
-getWirelessInfo ifname = do
+getWirelessInfo ifname =
bracket makeNL80211Socket (closeFd . getFd) (\s -> do
iflist <- getInterfaceList s
iwdata <- runMaybeT $ do
ifidx <- MaybeT . return $ foldr (\(n, i) z ->
- if (ifname == "" || ifname == n) then Just i else z)
+ if ifname == "" || ifname == n then Just i else z)
Nothing
iflist
scanp <- liftIO (getConnectedWifi s ifidx) >>=
@@ -63,13 +65,16 @@ getWirelessInfo ifname = do
return . unpack
signal = staInfoFromPacket stap >>= staSignalMBM >>=
return . fromIntegral @Int8 . fromIntegral
- qlty = fromMaybe (-1) (round @Float . (/ 0.7) . (+ 110) .
- clamp (-110) (-40) . fromIntegral <$> signal)
+ qlty = maybe (-1) (round @Float . (/ 0.7) . (+ 110) .
+ clamp (-110) (-40) . fromIntegral) signal
MaybeT . return $ Just $ IwData ssid signal qlty
return $ fromMaybe (IwData "" Nothing (-1)) iwdata)
where
rightToMaybe = either (const Nothing) Just
- clamp lb up v = if v < lb then lb else if v > up then up else v
+ clamp lb up v
+ | v < lb = lb
+ | v > up = up
+ | otherwise = v
#endif
newtype WirelessOpts = WirelessOpts