From 9144a70d6a09b1ea20573d7053738650b2cd9377 Mon Sep 17 00:00:00 2001 From: Simon Hengel Date: Thu, 13 Jul 2023 13:59:20 +0700 Subject: [PATCH] pager: Match arbitrary input as a fallback This is useful e.g.: - on cyclic imports (the actual format varies across GHC versions) - when you specify invalid command line options --- sensei.cabal | 1 + src/Pager.hs | 10 ++++------ test/PagerSpec.hs | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 test/PagerSpec.hs diff --git a/sensei.cabal b/sensei.cabal index 46bb619..f6ae42d 100644 --- a/sensei.cabal +++ b/sensei.cabal @@ -220,6 +220,7 @@ test-suite spec HTTPSpec Language.Haskell.GhciWrapperSpec OptionsSpec + PagerSpec ReadHandleSpec RunSpec SessionSpec diff --git a/src/Pager.hs b/src/Pager.hs index f4bab4e..8fea16f 100644 --- a/src/Pager.hs +++ b/src/Pager.hs @@ -18,9 +18,7 @@ pager input = do readMVar pid >>= terminateProcess void $ wait tid where - less = proc "less" ["--RAW", "--QUIT-AT-EOF", "--pattern", pattern] - patterns = - [ "^.*\\w:\\d+:\\d+:.+$" - , "^Module imports form a cycle:$" - ] - pattern = intercalate "|" patterns + less = proc "less" $ "--RAW" : "--QUIT-AT-EOF" : matchOptions + +matchOptions :: [String] +matchOptions = ["--incsearch", "--pattern", "^.*\\w:\\d+:\\d+:.+$|"] diff --git a/test/PagerSpec.hs b/test/PagerSpec.hs new file mode 100644 index 0000000..7bc687e --- /dev/null +++ b/test/PagerSpec.hs @@ -0,0 +1,15 @@ +module PagerSpec (spec) where + +import Helper + +import Pager + +spec :: Spec +spec = do + describe "matchOptions" $ do + it "contains --incsearch" $ do + -- The `--incsearch` flag changes the behavior of `--pattern` in subtle + -- ways. A user might have `--incsearch` enabled globally. To ensure + -- consistent behavior across environments we always enable + -- `--incsearch`. + matchOptions `shouldContain` ["--incsearch"]