From a79af4e822ffdace2631fd6721603093f64e63be Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Sun, 21 Oct 2018 11:28:22 +0200 Subject: [PATCH] cleaning --- src/GPM.hs | 2 +- src/GPM/Helpers.hs | 21 +++++++++++++-------- src/GPM/Review.hs | 22 ++++++++++++++-------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/GPM.hs b/src/GPM.hs index c79ac1a..8d76b8e 100755 --- a/src/GPM.hs +++ b/src/GPM.hs @@ -9,7 +9,7 @@ Maintainer : yann.esposito@gmail.com module GPM where -import Protolude hiding (stdout) +import Protolude import Turtle diff --git a/src/GPM/Helpers.hs b/src/GPM/Helpers.hs index b5ea9e3..ef8768d 100644 --- a/src/GPM/Helpers.hs +++ b/src/GPM/Helpers.hs @@ -20,18 +20,24 @@ module GPM.Helpers ) where -import Protolude hiding (die) +import Protolude hiding (die) import Turtle -import qualified Control.Foldl as Fold -import qualified System.Directory as Directory +import qualified Control.Foldl as Fold import qualified System.Console.ANSI as Console +import qualified System.Directory as Directory +import qualified System.IO -- | execute a shell script and return the last line as text -- but also log the command to the console to minimize surprise debug :: Text -> IO (Maybe Text) debug cmd = do - putErrText cmd + Console.setSGR [ Console.SetColor Console.Foreground Console.Dull Console.Cyan + , Console.SetItalicized True + ] + putErrText (" " <> cmd) + Console.setSGR [ Console.Reset ] + System.IO.hFlush System.IO.stderr fmap lineToText <$> _foldIO (inshell cmd empty) (Fold.generalize Fold.last) -- | execute a shell script without stdin and without handling output @@ -78,11 +84,10 @@ inDir workDir action = do putTextColor :: Console.Color -> Text -> IO () putTextColor color t = do - Console.setSGR [ Console.SetColor Console.Foreground Console.Dull color - , Console.SetConsoleIntensity Console.NormalIntensity - ] + Console.setSGR [ Console.SetColor Console.Foreground Console.Dull color ] putText t - Console.setSGR [Console.Reset] + Console.setSGR [ Console.Reset ] + System.IO.hFlush System.IO.stdout green :: Text -> IO () green = putTextColor Console.Green diff --git a/src/GPM/Review.hs b/src/GPM/Review.hs index f3fa4b2..c521761 100644 --- a/src/GPM/Review.hs +++ b/src/GPM/Review.hs @@ -43,15 +43,21 @@ data ReviewCommand = ReviewStart ReviewOptions -- | init gpm branch to handle reviews init :: IO () init = do - green "* Init Reviews support" - let fic = "reviews" "write-contributing-yogsototh.org" - mktree "reviews" - putText $ format ("* "%fp) fic + green "* reviews.org" + putText " create some example review for inspiration" + let reviewDir = "reviews" + mktree reviewDir + let fic = reviewDir "write-contributing-yogsototh.org" + putText $ format (" "%fp) fic writeFile (toS (format fp fic)) $(embedStringFile "templates/review.org") - debug_ "git add reviews" - mktree "templates" - writeFile "templates/new-review.org" $(embedStringFile "templates/new-review.org") - debug_ "git add templates" + debug_ (toS (format ("git add "%fp) reviewDir)) + putText " create some review templates" + let templateDir = "templates" + templateFic = templateDir "new-review.org" + mktree templateDir + writeFile (toS (format fp templateFic)) $(embedStringFile "templates/new-review.org") + putText $ format (" "%fp) templateFic + debug_ (toS (format ("git add "%fp) templateDir)) -- | Command Line Options data ReviewOptions = ReviewOptions