Skip to content

Commit

Permalink
pager: Match arbitrary input as a fallback
Browse files Browse the repository at this point in the history
This is useful e.g.:

- on cyclic imports (the actual format varies across GHC versions)
- when you specify invalid command line options
  • Loading branch information
sol committed Jul 13, 2023
1 parent e2ea217 commit a20ef6f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions sensei.cabal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions src/Pager.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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+:.+$|"]
15 changes: 15 additions & 0 deletions test/PagerSpec.hs
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit a20ef6f

Please sign in to comment.