diff --git a/README.md b/README.md index 95effc9..5ce0b17 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ See `feedback-test --help` for more details. |----|-|-|-|-| | Indication of command starting | ✔️ | ✔️ | C | C | | Indication of time | ✔️ | C | C | C | -| Clear screen between feedback | ✔️ | C | C | ✔️ | +| Clear screen between feedback | ✔️ | C | C | C | | Gitignore-aware | ✔️ | ✖️ | ✔️ | ✖ | | Named feedback loops | ✔️ | ✖️ | ✖ | ✖ | | Configurable feedback loops | ✔️ | ✔️ | ✖ | ✖ | diff --git a/feedback/src/Feedback/Common/OptParse.hs b/feedback/src/Feedback/Common/OptParse.hs index 3e25da2..234b44d 100644 --- a/feedback/src/Feedback/Common/OptParse.hs +++ b/feedback/src/Feedback/Common/OptParse.hs @@ -27,11 +27,30 @@ import Path.IO import Paths_feedback data LoopSettings = LoopSettings - { loopSettingRunSettings :: !RunSettings, + { loopSettingFilterSettings :: !FilterSettings, + loopSettingRunSettings :: !RunSettings, loopSettingOutputSettings :: !OutputSettings } deriving (Show, Eq, Generic) +combineToLoopSettings :: Flags -> Environment -> Maybe OutputConfiguration -> LoopConfiguration -> IO LoopSettings +combineToLoopSettings Flags {..} Environment {} mDefaultOutputConfig LoopConfiguration {..} = do + let filterSettingGitingore = fromMaybe True loopConfigGitignore + let loopSettingFilterSettings = FilterSettings {..} + let runSettingCommand = loopConfigCommand + let runSettingExtraEnv = loopConfigExtraEnv + runSettingWorkingDir <- mapM resolveDir' loopConfigWorkingDir + + let loopSettingRunSettings = RunSettings {..} + let outputConfig = liftA2 (<>) loopConfigOutputConfiguration mDefaultOutputConfig + let loopSettingOutputSettings = combineToOutputSettings flagOutputFlags outputConfig + pure LoopSettings {..} + +data FilterSettings = FilterSettings + { filterSettingGitingore :: !Bool + } + deriving (Show, Eq, Generic) + data RunSettings = RunSettings { runSettingCommand :: !Command, runSettingExtraEnv :: !(Map String String), @@ -39,17 +58,6 @@ data RunSettings = RunSettings } deriving (Show, Eq, Generic) -combineToLoopSettings :: Flags -> Environment -> Maybe OutputConfiguration -> LoopConfiguration -> IO LoopSettings -combineToLoopSettings Flags {..} Environment {} mDefaultOutputConfig LoopConfiguration {..} = do - let runSettingCommand = loopConfigCommand - let runSettingExtraEnv = loopConfigExtraEnv - runSettingWorkingDir <- mapM resolveDir' loopConfigWorkingDir - - let loopSettingRunSettings = RunSettings {..} - let outputConfig = liftA2 (<>) loopConfigOutputConfiguration mDefaultOutputConfig - let loopSettingOutputSettings = combineToOutputSettings flagOutputFlags outputConfig - pure LoopSettings {..} - data OutputSettings = OutputSettings { outputSettingClear :: !Clear } @@ -76,6 +84,7 @@ instance HasCodec Configuration where data LoopConfiguration = LoopConfiguration { loopConfigCommand :: !Command, + loopConfigGitignore :: !(Maybe Bool), loopConfigExtraEnv :: !(Map String String), loopConfigWorkingDir :: !(Maybe FilePath), loopConfigOutputConfiguration :: !(Maybe OutputConfiguration) @@ -91,6 +100,7 @@ instance HasCodec LoopConfiguration where object "LoopConfiguration" $ LoopConfiguration <$> commandObjectCodec .= loopConfigCommand + <*> optionalField "gitignore" "whether to ignore files that are not in the git repo" .= loopConfigGitignore <*> optionalFieldWithOmittedDefault "env" M.empty "extra environment variables to set" .= loopConfigExtraEnv <*> optionalField "working-dir" "where the process will be run" .= loopConfigWorkingDir <*> optionalField "output" "output configuration for this loop" .= loopConfigOutputConfiguration @@ -108,6 +118,7 @@ makeLoopConfiguration :: Command -> LoopConfiguration makeLoopConfiguration c = LoopConfiguration { loopConfigCommand = c, + loopConfigGitignore = Nothing, loopConfigExtraEnv = M.empty, loopConfigWorkingDir = Nothing, loopConfigOutputConfiguration = Nothing diff --git a/feedback/src/Feedback/Loop.hs b/feedback/src/Feedback/Loop.hs index e54d7b8..ab3b74a 100644 --- a/feedback/src/Feedback/Loop.hs +++ b/feedback/src/Feedback/Loop.hs @@ -41,7 +41,7 @@ runFeedbackLoop = -- 0.1 second debouncing, 0.001 was too little let conf = FS.defaultConfig {confDebounce = Debounce 0.1} FS.withManagerConf conf $ \watchManager -> do - eventFilter <- mkEventFilter here + eventFilter <- mkEventFilter here loopSettingFilterSettings stopListeningAction <- FS.watchTree watchManager @@ -54,9 +54,9 @@ runFeedbackLoop = (outputWorker loopSettingOutputSettings outputChan) stopListeningAction -mkEventFilter :: Path Abs Dir -> IO (FS.Event -> Bool) -mkEventFilter here = do - mGitFiles <- gitLsFiles here +mkEventFilter :: Path Abs Dir -> FilterSettings -> IO (FS.Event -> Bool) +mkEventFilter here FilterSettings {..} = do + mGitFiles <- if filterSettingGitingore then gitLsFiles here else pure Nothing pure $ \event -> standardEventFilter here event && maybe True (eventPath event `S.member`) mGitFiles