packages feed

trackit 0.2.1 → 0.3

raw patch · 3 files changed

+42/−7 lines, 3 files

Files

README.md view
@@ -46,3 +46,15 @@      ```    2. `trackit` supports scrolling, and keeps the scrolled view even if the output is updated.++## Tips and tricks++### `git status`++`git status` is slightly tricky to track using `trackit`. The reason is that the command creates a temporary lock file in the `.git` directory, resulting in a feedback loop between `trackit` and `git status` (if `trackit` listens for changes in the `.git` directory).++Since version 2.16, Git supports the flag `--no-optional-locks`, which prevents commands like `git status` to create locks. So we can use the following to track the result of `git status`:++    trackit -t . -c "git --no-optional-locks -c color.ui=always status"++This command also forces colored output, which is useful if this option hasn't been set globally.
src/Main.hs view
@@ -2,7 +2,7 @@  import Control.Concurrent (forkIO, killThread, threadDelay) import Control.Concurrent.STM.TVar (TVar, newTVarIO, readTVar, writeTVar)-import Control.Monad (fail, forever, void, when)+import Control.Monad (fail, forever, guard, void, when) import Control.Monad.STM (atomically) import Control.Monad.Trans (liftIO) import Data.Char (toLower)@@ -39,6 +39,7 @@   , _stabilization :: Maybe Int      <?> "Minimal time (milliseconds) between the any file event and command update (default: 200)"   , _version       :: Bool           <?> "Print the version number"   , _help          :: Bool+  , _debug         :: Bool           <?> "Show debug information the lower right corner"   } deriving (Show, Generic)  shortName :: String -> Maybe Char@@ -62,6 +63,7 @@   , command       :: Maybe String   , maxLines      :: Int   , stabilization :: NominalDiffTime+  , debug         :: Bool   } deriving (Show, Generic)  watchDirError =@@ -84,6 +86,7 @@               maxLines = fromMaybe 400 $ unHelpful _maxLines               stabPerMs = fromMaybe 200 $ unHelpful _stabilization               stabilization = fromIntegral stabPerMs / 1000+              debug = unHelpful _debug           return $ Options {..}  ansiImage :: Text -> Image@@ -92,6 +95,12 @@     mkLine ss =       foldr (<|>) mempty [text' a s | Segment a s <- ss] +-- | Make a 'Context'-aware 'Widget' with 'Fixed' size+withContext :: (Context -> Widget n) -> Widget n+withContext k = Widget Fixed Fixed $ do+  cxt <- getContext+  render (k cxt)+ -- | Limit the text to @n@ lines (because large buffers make the app slow) limit :: Int -> Text -> Text limit n t@@ -132,11 +141,13 @@  data AppState = AppState   { theText :: Text-  }+  , updateCount :: Integer+  } deriving (Eq, Show)  initState :: AppState initState = AppState   { theText = ""+  , updateCount = 0   }  data View = TheView@@ -145,8 +156,20 @@ theView :: ViewportScroll View theView = viewportScroll TheView -drawApp :: AppState -> [Widget View]-drawApp AppState {..} = pure $ viewport TheView Both $ raw $ ansiImage theText+drawApp :: Options -> AppState -> [Widget View]+drawApp Options {..} AppState {..} = concat+  [ guard debug >> pure debugWidget+  , pure $ viewport TheView Both $ raw $ ansiImage theText+  ]+  where+    debugText = "Update count: " <> Text.pack (show updateCount)+    debugAttr = defAttr `withForeColor` black `withBackColor` white+    debugWidget =+      withContext $ \cxt ->+        translateBy+          (Location+             (availWidth cxt - Text.length debugText, availHeight cxt - 1)) $+        raw $ text' debugAttr debugText  withSize :: ((Int, Int) -> EventM View ()) -> EventM View () withSize k = mapM_ k . fmap extentSize =<< lookupExtent TheView@@ -154,7 +177,7 @@ updateApp :: Options -> AppState -> EventM View (Next AppState) updateApp opts s = do   newText <- liftIO $ runCMD opts-  continue $ s {theText = newText}+  continue $ s {theText = newText, updateCount = updateCount s + 1}  stepApp :: Options -> AppState -> BrickEvent View () -> EventM View (Next AppState) stepApp _ s (keyPressed 'q' -> True)        = halt s@@ -173,7 +196,7 @@ myApp :: Options -> App AppState () View myApp opts =   App-  { appDraw = drawApp+  { appDraw = drawApp opts   , appHandleEvent = stepApp opts   , appStartEvent = return   , appAttrMap = const $ attrMap defAttr []
trackit.cabal view
@@ -1,5 +1,5 @@ name:                trackit-version:             0.2.1+version:             0.3 synopsis:            A command-line tool for live monitoring description:         @trackit@ is a command-line tool that listens for changes                      in a user-supplied directory. Whenever there is a change,