packages feed

dzen-dhall 1.0.0 → 1.0.1

raw patch · 10 files changed

+78/−56 lines, 10 files

Files

CHANGELOG.md view
@@ -1,5 +1,14 @@ # Revision history for dzen-dhall -## 0.0.1 -- 2019-08-25+## 1.0.1 -- 2018-08-29++### Changes+- Add a small delay between dzen2 startups to preserve the ordering of bars (#6)++### Fixed+- Validation for `#XXXXXX`-formatted colors (#5)+- Padding (#4)++## 1.0.0 -- 2018-08-26  * First version. Released on an unsuspecting world.
README.md view
@@ -1,6 +1,7 @@ # dzen-dhall  [![Build Status](https://travis-ci.com/dzen-dhall/dzen-dhall.svg?branch=master)](https://travis-ci.com/dzen-dhall/dzen-dhall/)+![Hackage](https://img.shields.io/hackage/v/dzen-dhall)  [Dzen](https://github.com/robm/dzen) is a general purpose messaging, notification and menuing program for X11. It features rich in-text formatting & control language, allowing to create GUIs by piping output of arbitrary executables to the `dzen2` binary. There are plenty of good usage examples on [r/unixporn](https://www.reddit.com/r/unixporn/search/?q=dzen&restrict_sr=1). @@ -48,16 +49,13 @@ 	-- ^ Colon means "has type". `memoryUsage` is a `Bar` 	= bashWithBinaries 	  -- ^ Call to a function named `bashWithBinaries` with three arguments:-	  [ "free", "grep", "echo", "awk" ]-	  -- ^ Binaries required to run the script (used to exit early if some of them-	  -- are not present).+	  [ "free", "grep", "awk" ]+	  -- ^ A list of binaries required to run the script (used to exit early if+	  -- some of them are not present). 	  5000 	  -- ^ Update interval in milliseconds 	  ''-	  TMP=`free -b | grep 'Mem'`-	  TotalMem=`echo "$TMP" | awk '{ print $2; }'`-	  UsedMem=`echo "$TMP" | awk '{ print $3; }'`-	  echo "$((UsedMem * 100 / TotalMem))"+	  free -b | grep Mem | awk '{ printf("%.0f\n", $3 * 100 / $2) }'; 	  '' 	  -- ^ The script itself @@ -65,13 +63,10 @@ let swapUsage 	: Bar 	= bashWithBinaries-	  [ "free", "grep", "echo", "awk" ]+	  [ "free", "grep", "awk" ] 	  5000 	  ''-	  TMP=`free -b | grep 'Swap'`-	  TotalSwap=`echo "$TMP" | awk '{ print $2; }'`-	  UsedSwap=`echo "$TMP" | awk '{ print $3; }'`-	  echo "$((UsedSwap * 100 / TotalSwap))"+	  free -b | grep Swap | awk '{ printf("%.0f\n", $3 * 100 / $2) }'; 	  ''  -- A bar that shows current date:@@ -304,7 +299,7 @@  #### Relative positioning -Relative positioning (`p`) allows to shift by some number of pixels in any direction, reset vertical position, lock or unlock horizontal position, and "move" to one of the four edges of the screen:+Relative positioning (`p`) allows to shift by some number of pixels in any direction, reset vertical position, lock or unlock horizontal position, or move to one of the four edges of the screen:  ```dhall let Position@@ -326,7 +321,7 @@  #### Absolute positioning -With `pa` function, it is possible to specify absolute position of a bar, relative to the top-left edge of the screen.+With `pa` function, it is possible to specify absolute position of a bar, relative to the top-left corner of the screen.  `AbsolutePosition` is defined as: @@ -492,6 +487,7 @@   , input : Text   , updateInterval : Optional Natural   , escape : Bool+  } ```  For example, a simple clock plugin can be created as follows:@@ -681,9 +677,9 @@  let getEvent : Shell -let getCurrentState : Shell = utils.getCurrentState+let getCurrentState : Shell -let getNextState : Shell = utils.getNextState+let getNextState : Shell ```  For example, The following hook will succeed only if a certain file exists:@@ -745,6 +741,12 @@ ```  [[view complete example]](test/dhall/configs/assertions.dhall)++## Code structure overview++The image below contains an import tree for `config.dhall`. It was generated using `dhall resolve --dot`.++[![](img/graph.png)](https://raw.githubusercontent.com/dzen-dhall/dzen-dhall/master/img/graph.png)  ## Naming conventions 
dhall/config.dhall view
@@ -117,25 +117,19 @@ 		let memoryUsage 			: Bar 			= bashWithBinaries-			  [ "free", "grep", "echo", "awk" ]+			  [ "free", "grep", "awk" ] 			  5000 			  ''-			  TMP=`free -b | grep 'Mem'`-			  TotalMem=`echo "$TMP" | awk '{ print $2; }'`-			  UsedMem=`echo "$TMP" | awk '{ print $3; }'`-			  echo "$((UsedMem * 100 / TotalMem))"+			  free -b | grep Mem | awk '{ printf("%.0f\n", $3 * 100 / $2) }'; 			  ''  		let swapUsage 			: Bar 			= bashWithBinaries-			  [ "free", "grep", "echo", "awk" ]+			  [ "free", "grep", "awk" ] 			  5000 			  ''-			  TMP=`free -b | grep 'Swap'`-			  TotalSwap=`echo "$TMP" | awk '{ print $2; }'`-			  UsedSwap=`echo "$TMP" | awk '{ print $3; }'`-			  echo "$((UsedSwap * 100 / TotalSwap))"+			  free -b | grep Swap | awk '{ printf("%.0f\n", $3 * 100 / $2) }'; 			  ''  		let date
dzen-dhall.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 2cb0b71974259161f90b36853a7c56de12745bb2f70424c10cae5b6fb20ea1ed+-- hash: b68721f6e4d0f2557c8dd8e71bbc259433931d8686268ad8fb851180c946fe4b  name:           dzen-dhall-version:        1.0.0+version:        1.0.1 synopsis:       Configure dzen2 bars in Dhall language description:    Configure dzen2 bars in Dhall language homepage:       https://github.com/dzen-dhall/dzen-dhall#readme
src/DzenDhall/AST.hs view
@@ -104,19 +104,26 @@ splitAST n (ASTPadding width padding child) =   splitAST n (spaces leftPadding <> child <> spaces rightPadding)     where-      (leftPadding, rightPadding) = paddingWidths padding $ width - astWidth child+      (leftPadding, rightPadding) =+        paddingWidths padding $ width - astWidth child+       spaces :: Int -> AST       spaces 0 = EmptyAST       spaces w = ASTText $ Data.Text.justifyRight w ' ' ""+ splitAST _n res@(ASTShape _) =   EmptyR res 1 -- TODO + paddingWidths :: Padding -> Int -> (Int, Int)+paddingWidths _      w+  | w <= 0 = (0, 0) paddingWidths PLeft  w = (w, 0) paddingWidths PRight w = (0, w) paddingWidths PSides w   | w `mod` 2 == 0 = (w `div` 2, w `div` 2)   | otherwise = (w `div` 2, w `div` 2 + 1)+  astWidth :: AST -> Int astWidth (ASTText txt) = Data.Text.length txt
src/DzenDhall/AST/Render.hs view
@@ -141,12 +141,14 @@           P_BOTTOM   -> ("^p(_BOTTOM)",           "^p()")   render (ASTShape shape) = render shape   render (ASTPadding width padding ast) = do-    write $ mkPadding leftPadding+    write $ mkPaddingText leftPadding     render ast-    write $ mkPadding rightPadding+    write $ mkPaddingText rightPadding     where-      mkPadding w = Data.Text.justifyRight w ' ' ""-      (leftPadding, rightPadding) = paddingWidths padding width+      mkPaddingText n = Data.Text.justifyRight n ' ' ""+      (leftPadding, rightPadding) =+        paddingWidths padding $ width - astWidth ast+  -- * Helper functions 
src/DzenDhall/App/Run.hs view
@@ -15,7 +15,9 @@ import           Lens.Micro import           Lens.Micro.Extras import           System.Exit+import           Control.Concurrent (threadDelay) + -- | Parses 'Bar's. For each 'Configuration' spawns its own dzen binary, -- source threads and automata handlers. useConfigurations :: App Common ()@@ -36,14 +38,19 @@       (Parser.runBarParser barTokens)       (invalidTokens barTokens) $       \(bar :: Bar Marshalled) -> do-        let barSettings = cfg ^. cfgBarSettings          (bar', subscriptions, barRuntime, clickableAreas) <--          liftStartingUp (startUp cfg bar) barSettings+          liftStartingUp (startUp cfg bar) (cfg ^. cfgBarSettings)          runAppForked barRuntime (launchEventListener subscriptions clickableAreas)          runAppForked barRuntime (updateForever bar')++        -- This delay is required to preserve the order of multiple dzen2 instances.+        -- We want them to overlap in exactly the same order as defined in `config.dhall`.+        -- 50ms is nearly unnoticeable for humans, but just enough for dzen2 to connect to+        -- X and initialize its window.+        liftIO $ threadDelay 50000   checkDzen2Executable :: App stage ()
src/DzenDhall/App/StartingUp.hs view
@@ -137,18 +137,16 @@     ToStdout -> pure System.IO.stdout      ToDzen -> do-      (mb_stdin, mb_stdout, _, _) <- liftIO $+      (mb_stdin, _, _, _) <- liftIO $         createProcess $           (proc (runtime ^. rtDzenBinary) args)             { std_out = CreatePipe             , std_in  = CreatePipe } -      case (mb_stdin, mb_stdout) of-        (Just stdin, Just stdout) -> liftIO $ do+      case mb_stdin of+        (Just stdin) -> liftIO $ do           hSetEncoding  stdin  System.IO.utf8-          hSetEncoding  stdout System.IO.utf8           hSetBuffering stdin  LineBuffering-          hSetBuffering stdout LineBuffering           pure stdin         _ -> App.exit 4 $           "Couldn't open IO handles for dzen binary " <>
src/DzenDhall/Validation.hs view
@@ -67,23 +67,12 @@         Just err -> cont err what : acc      colorParser =-      hex3 <|> hex6 <|> colorName+      (try (hex 6) <|> try (hex 3) <|> colorName) <* eof       where-        hex3 = do-          void $ char '#'-          void hexDigitChar-          void hexDigitChar-          void hexDigitChar-          pure ""--        hex6 = do+        hex :: Int -> Parser Text+        hex size = do           void $ char '#'-          void hexDigitChar-          void hexDigitChar-          void hexDigitChar-          void hexDigitChar-          void hexDigitChar-          void hexDigitChar+          replicateM_ size hexDigitChar           pure ""          colorName = do
test/DzenDhall/Test/AST/Render.hs view
@@ -50,5 +50,19 @@                       (ASTText "b")))                (ASTText "c"))         runRender tree `shouldBe` "^fg(red)a^fg(green)b^fg(red)c^fg()"++    , testGroup "padding"+      [ testCase "#0" do+          let tree = ASTPadding 3 PLeft (ASTText "a")+          runRender tree `shouldBe` "  a"++      , testCase "#1" do+          let tree = ASTPadding 3 PRight (ASTText "a")+          runRender tree `shouldBe` "a  "++      , testCase "#2" do+          let tree = ASTPadding 3 PSides (ASTText "a")+          runRender tree `shouldBe` " a "+      ]     ]   ]