From c6e59f6c0fd3d23ccd3ce77ff1f59949c27312d1 Mon Sep 17 00:00:00 2001 From: Jens Nolte <jens@nightmarestudio.de> Date: Sat, 1 Feb 2020 22:19:02 +0100 Subject: [PATCH] Minor changes for consistency --- src/QBar/BlockOutput.hs | 43 +++++++++++++++++++++-------------------- src/QBar/Core.hs | 5 ++--- src/QBar/Server.hs | 2 +- src/QBar/Theme.hs | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/QBar/BlockOutput.hs b/src/QBar/BlockOutput.hs index 5869ae4..8230f62 100644 --- a/src/QBar/BlockOutput.hs +++ b/src/QBar/BlockOutput.hs @@ -11,11 +11,11 @@ import Data.Int (Int64) import qualified Data.Text.Lazy as T -data BlockOutput = BlockOutput - { _fullText :: BlockText - , _shortText :: Maybe BlockText - , _blockName :: Maybe T.Text - , _invalid :: Bool +data BlockOutput = BlockOutput { + _fullText :: BlockText, + _shortText :: Maybe BlockText, + _blockName :: Maybe T.Text, + _invalid :: Bool } deriving (Eq, Show) @@ -102,16 +102,16 @@ isNormal i | otherwise = True toImportance :: Real a => (a, a, a, a, a, a) -> a -> Importance -toImportance (tMax, tCrit, tErr, tWarn, tNorm, tMin) = - toImportance' (Just tMax, tCrit, tErr, tWarn, tNorm, Just tMin) +toImportance (tMax, tCritical, tError, tWarning, tNormal, tMinimal) = + toImportance' (Just tMax, tCritical, tError, tWarning, tNormal, Just tMinimal) toImportance' :: forall a. Real a => (Maybe a, a, a, a, a, Maybe a) -> a -> Importance -toImportance' (tMax, tCrit, tErr, tWarn, tNorm, tMin) val - | tCrit <= val = 4 + valueCrit tMax tCrit val - | tErr <= val = 3 + linearMatch tCrit tErr val - | tWarn <= val = 2 + linearMatch tErr tWarn val - | tNorm <= val = 1 + linearMatch tWarn tNorm val - | otherwise = 0 + valueOtherwise tNorm tMin val +toImportance' (tMax, tCritical, tError, tWarning, tNormal, tMinimal) val + | tCritical <= val = 4 + valueCritical tMax tCritical val + | tError <= val = 3 + linearMatch tCritical tError val + | tWarning <= val = 2 + linearMatch tError tWarning val + | tNormal <= val = 1 + linearMatch tWarning tNormal val + | otherwise = 0 + valueOtherwise tNormal tMinimal val where e :: Importance e = exp 1 @@ -121,16 +121,17 @@ toImportance' (tMax, tCrit, tErr, tWarn, tNorm, tMin) val logarithmicMatch l u = 1 - 1 / log (e + realToFrac (u - l)) frac :: a -> a -> Importance frac a b = realToFrac a / realToFrac b - valueCrit :: Maybe a -> a -> a -> Importance - valueCrit (Just tMax') tCrit' v - | tMax' > v = linearMatch tMax' tCrit' v + valueCritical :: Maybe a -> a -> a -> Importance + valueCritical (Just tMax') tCritical' v + | tMax' > v = linearMatch tMax' tCritical' v | otherwise = 1 - valueCrit Nothing tCrit' v = logarithmicMatch tCrit' v + valueCritical Nothing tCritical' v = logarithmicMatch tCritical' v valueOtherwise :: a -> Maybe a -> a -> Importance - valueOtherwise tNorm' (Just tMin') v - | tMin' < v = linearMatch tNorm' tMin' v + valueOtherwise tNormal' (Just tMinimal') v + | tMinimal' < v = linearMatch tNormal' tMinimal' v | otherwise = 0 - valueOtherwise tNorm' Nothing v = 1 - logarithmicMatch v tNorm' + valueOtherwise tNormal' Nothing v = 1 - logarithmicMatch v tNormal' + removePango :: BlockText -> T.Text @@ -168,7 +169,7 @@ activeText = mkText True normalImportant normalText :: T.Text -> BlockText normalText = mkText False normalImportant -pangoText :: T.Text -> BlockText +pangoText :: PangoText -> BlockText pangoText pango = BlockText [PangoTextSegment pango] surroundWith :: (T.Text -> BlockText) -> T.Text -> T.Text -> BlockText -> BlockText diff --git a/src/QBar/Core.hs b/src/QBar/Core.hs index 5bef93a..acb9654 100644 --- a/src/QBar/Core.hs +++ b/src/QBar/Core.hs @@ -112,8 +112,7 @@ updateEventHandler eventHandler (Just (blockOutput, _)) = Just (blockOutput, Jus runBarIO :: Bar -> BarIO r -> IO r runBarIO bar action = runReaderT (runSafeT action) bar -modify :: (BlockOutput -> BlockOutput) - -> Pipe BlockState BlockState BarIO r +modify :: (BlockOutput -> BlockOutput) -> Pipe BlockState BlockState BarIO r modify x = PP.map (over (_Just . _1) x) autoPadding :: Pipe BlockState BlockState BarIO r @@ -228,7 +227,7 @@ blockScript path = forever $ updateBlock =<< (lift blockScriptAction) ExitSuccess -> return $ case map E.decodeUtf8 (C8.lines output) of -- TODO: Fix this, but how? -- PangoSegments cannot have external formatting, so either allow that here, - -- or duplicate the function into ango and nonPango variants. + -- or duplicate the function into pango and nonPango variants. -- (text:short:color:_) -> setColor color $ shortText short $ createScriptBlock text (text:short:_) -> shortText ?~ pangoText short $ createScriptBlock text (text:_) -> createScriptBlock text diff --git a/src/QBar/Server.hs b/src/QBar/Server.hs index 35da00f..1f69276 100644 --- a/src/QBar/Server.hs +++ b/src/QBar/Server.hs @@ -69,7 +69,7 @@ swayBarOutput MainOptions{verbose} = do encodeOutput :: [BlockOutput] -> BS.ByteString encodeOutput bs = encode $ zipWith encodeBlock bs $ defaultTheme bs encodeBlock :: BlockOutput -> (T.Text, Maybe T.Text) -> RenderBlock - encodeBlock b (fullText', shortText') = RenderBlock fullText' shortText' (b^.blockName) + encodeBlock b (fullText', shortText') = RenderBlock fullText' shortText' (b ^. blockName) -- |A producer that reads swaybar/i3bar-input events from stdin and emits them as 'BlockEvent's. swayBarInput :: MainOptions -> Producer BlockEvent BarIO () diff --git a/src/QBar/Theme.hs b/src/QBar/Theme.hs index 45c4d55..7490ed2 100644 --- a/src/QBar/Theme.hs +++ b/src/QBar/Theme.hs @@ -26,7 +26,7 @@ mkTheme theming' = map themeBlock where theming :: SimplifiedTheme theming - | block^.invalid = invalidSimplifiedTheme + | block ^. invalid = invalidSimplifiedTheme | otherwise = theming' fullText' :: PangoText fullText' = themeBlockText theming $ block ^. fullText -- GitLab