Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ addons:
matrix:
fast_finish: true
include:
- env: ARGS=""
- env: ARGS="--resolver lts-5"
- env: ARGS="--resolver lts-6"
- env: ARGS="--resolver lts-7"
- env: ARGS="--resolver lts-8"
- env: ARGS="--resolver lts-9"
- env: ARGS="--resolver lts"
- env: ARGS="--resolver nightly"
- env: ARGS="" SKIP_DOCTESTS=false
- env: ARGS="--resolver lts" SKIP_DOCTESTS=false
- env: ARGS="--resolver nightly" SKIP_DOCTESTS=false
- env: ARGS="--resolver lts-10" SKIP_DOCTESTS=false
- env: ARGS="--resolver lts-9" SKIP_DOCTESTS=true
- env: ARGS="--resolver lts-8" SKIP_DOCTESTS=true
- env: ARGS="--resolver lts-7" SKIP_DOCTESTS=true
- env: ARGS="--resolver lts-6" SKIP_DOCTESTS=true
- env: ARGS="--resolver lts-5" SKIP_DOCTESTS=true

before_install:
# Download and unpack the stack executable
Expand All @@ -40,7 +41,8 @@ script:
- stack $ARGS --no-terminal build --pedantic

# Tests
- stack $ARGS --no-terminal test --pedantic
- stack $ARGS --no-terminal test --pedantic :vgrep-test
- $SKIP_DOCTESTS || stack $ARGS --no-terminal test --pedantic :doctest
- stack $ARGS --no-terminal haddock --no-haddock-deps

- stack $ARGS --no-terminal sdist
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

## v0.2.2

* Add support for aeson 1.2.x to enable build with Stackage LTS 10.x

## v0.2.1

* Add support for aeson 1.x to enable build with Stackage LTS 9.x
Expand Down
2 changes: 1 addition & 1 deletion src/Vgrep/Ansi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Vgrep.Ansi.Vty.Attributes
-- root of the 'Formatted' tree.
--
-- >>> renderAnsi Vty.defAttr (bare "Text")
-- HorizText "Text"@(Attr {attrStyle = Default, attrForeColor = Default, attrBackColor = Default},4,4)
-- HorizText "Text"@(Attr {attrStyle = Default, attrForeColor = Default, attrBackColor = Default, attrURL = Default},4,4)
--
renderAnsi :: Attr -> AnsiFormatted -> Vty.Image
renderAnsi attr = \case
Expand Down
13 changes: 7 additions & 6 deletions src/Vgrep/Ansi/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Vgrep.Ansi.Parser
import Control.Applicative
import Data.Attoparsec.Text
import Data.Bits
import Data.Functor
import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as T
Expand All @@ -24,22 +25,22 @@ Directly parses ANSI formatted text using 'ansiFormatted'.
Parsing ANSI color codes:

>>> parseAnsi "Hello \ESC[31mWorld\ESC[m!"
Cat 12 [Text 6 "Hello ",Format 5 (Attr {attrStyle = KeepCurrent, attrForeColor = SetTo (ISOColor 1), attrBackColor = KeepCurrent}) (Text 5 "World"),Text 1 "!"]
Cat 12 [Text 6 "Hello ",Format 5 (Attr {attrStyle = KeepCurrent, attrForeColor = SetTo (ISOColor 1), attrBackColor = KeepCurrent, attrURL = KeepCurrent}) (Text 5 "World"),Text 1 "!"]

More elaborate example with nested foreground and background colors:

>>> parseAnsi "\ESC[m\ESC[40mHello \ESC[31mWorld\ESC[39m!"
Cat 12 [Format 6 (Attr {attrStyle = KeepCurrent, attrForeColor = KeepCurrent, attrBackColor = SetTo (ISOColor 0)}) (Text 6 "Hello "),Format 5 (Attr {attrStyle = KeepCurrent, attrForeColor = SetTo (ISOColor 1), attrBackColor = SetTo (ISOColor 0)}) (Text 5 "World"),Format 1 (Attr {attrStyle = KeepCurrent, attrForeColor = KeepCurrent, attrBackColor = SetTo (ISOColor 0)}) (Text 1 "!")]
Cat 12 [Format 6 (Attr {attrStyle = KeepCurrent, attrForeColor = KeepCurrent, attrBackColor = SetTo (ISOColor 0), attrURL = KeepCurrent}) (Text 6 "Hello "),Format 5 (Attr {attrStyle = KeepCurrent, attrForeColor = SetTo (ISOColor 1), attrBackColor = SetTo (ISOColor 0), attrURL = KeepCurrent}) (Text 5 "World"),Format 1 (Attr {attrStyle = KeepCurrent, attrForeColor = KeepCurrent, attrBackColor = SetTo (ISOColor 0), attrURL = KeepCurrent}) (Text 1 "!")]

Some CSI sequences are ignored, since they are not supported by 'Vty':

>>> parseAnsi "\ESC[A\ESC[B\ESC[31mfoo\ESC[1K\ESC[mbar"
Cat 6 [Format 3 (Attr {attrStyle = KeepCurrent, attrForeColor = SetTo (ISOColor 1), attrBackColor = KeepCurrent}) (Text 3 "foo"),Text 3 "bar"]
Cat 6 [Format 3 (Attr {attrStyle = KeepCurrent, attrForeColor = SetTo (ISOColor 1), attrBackColor = KeepCurrent, attrURL = KeepCurrent}) (Text 3 "foo"),Text 3 "bar"]

Non-CSI sequences are not parsed, but included in the output:

>>> parseAnsi "\ESC]710;font\007foo\ESC[31mbar"
Cat 17 [Text 14 "\ESC]710;font\afoo",Format 3 (Attr {attrStyle = KeepCurrent, attrForeColor = SetTo (ISOColor 1), attrBackColor = KeepCurrent}) (Text 3 "bar")]
Cat 17 [Text 14 "\ESC]710;font\afoo",Format 3 (Attr {attrStyle = KeepCurrent, attrForeColor = SetTo (ISOColor 1), attrBackColor = KeepCurrent, attrURL = KeepCurrent}) (Text 3 "bar")]

-}
parseAnsi :: Text -> AnsiFormatted
Expand All @@ -59,7 +60,7 @@ ansiFormatted :: Parser AnsiFormatted
ansiFormatted = go mempty
where
go :: Attr -> Parser AnsiFormatted
go attr = endOfInput *> pure mempty
go attr = endOfInput $> mempty
<|> formattedText attr

formattedText :: Attr -> Parser AnsiFormatted
Expand All @@ -71,7 +72,7 @@ ansiFormatted = go mempty
pure (format attr' (bare t) <> rest)

rawText :: Parser Text
rawText = atLeastOneTill (== '\ESC') <|> endOfInput *> pure ""
rawText = atLeastOneTill (== '\ESC') <|> endOfInput $> ""

atLeastOneTill :: (Char -> Bool) -> Parser Text
atLeastOneTill = liftA2 T.cons anyChar . takeTill
Expand Down
8 changes: 4 additions & 4 deletions src/Vgrep/Ansi/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ dropFormatted amount txt
| amount <= 0 = txt
| length txt < amount = emptyFormatted
| otherwise = case txt of
Empty -> emptyFormatted
Text _ t -> bare (T.drop amount t)
Format _ attr t -> format' attr (dropFormatted amount t)
Cat _ ts -> cat' (dropChunks amount ts)
Empty -> emptyFormatted
Text _ t -> bare (T.drop amount t)
Format _ attr t -> format' attr (dropFormatted amount t)
Cat _ ts -> cat' (dropChunks amount ts)
where
dropChunks n = \case
[] -> []
Expand Down
4 changes: 2 additions & 2 deletions src/Vgrep/Ansi/Vty/Attributes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ module Vgrep.Ansi.Vty.Attributes

import Data.Bits ((.|.))
import Data.Monoid ((<>))
import Graphics.Vty.Attributes (Attr (..), MaybeDefault (..))
import Graphics.Vty.Attributes (Attr (..), MaybeDefault (..), defAttr)

-- | Combines two 'Attr's. This differs from 'mappend' from the 'Monoid'
-- instance of 'Attr' in that 'Vty.Style's are combined rather than
-- overwritten.
combineStyles :: Attr -> Attr -> Attr
combineStyles l r = Attr
combineStyles l r = defAttr
{ attrStyle = case (attrStyle l, attrStyle r) of
(SetTo l', SetTo r') -> SetTo (l' .|. r')
(l', r') -> l' <> r'
Expand Down
2 changes: 1 addition & 1 deletion src/Vgrep/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Vgrep.App
import Control.Concurrent.Async
import Graphics.Vty (Vty)
import qualified Graphics.Vty as Vty
import Pipes hiding (next)
import Pipes
import Pipes.Concurrent.PQueue
import Pipes.Prelude as P

Expand Down
2 changes: 1 addition & 1 deletion src/Vgrep/App/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Control.Concurrent.Async
import Control.Exception
import Graphics.Vty (Vty)
import qualified Graphics.Vty as Vty
import Pipes hiding (next)
import Pipes
import System.Posix.IO
import System.Posix.Types (Fd)

Expand Down
10 changes: 5 additions & 5 deletions src/Vgrep/Environment/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{-# LANGUAGE TemplateHaskell #-}
module Vgrep.Environment.Config where

import Control.Lens.Compat
import Control.Monad.IO.Class
import Data.Maybe
import Data.Monoid
import Graphics.Vty.Attributes
import Control.Lens.Compat
import Control.Monad.IO.Class
import Data.Maybe
import Data.Monoid
import Graphics.Vty.Attributes
( Attr
, blue
, bold
Expand Down
2 changes: 1 addition & 1 deletion src/Vgrep/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ module Vgrep.Key
, withModifier
)where

import Prelude hiding (Left, Right)
import Control.Applicative
import Data.Set (Set)
import qualified Data.Set as S
import GHC.Generics
import qualified Graphics.Vty.Input.Events as Vty
import Prelude hiding (Left, Right)


-- | A chord of keys and modifiers pressed simultaneously.
Expand Down
2 changes: 1 addition & 1 deletion src/Vgrep/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ parseGrepOutput = catMaybes . fmap parseLine
-- ANSI escape codes in the line text are parsed correctly:
--
-- >>> parseLine "path/to/file:foo\ESC[31mbar\ESC[mbaz"
-- Just (FileLineReference {_file = File {_fileName = "path/to/file"}, _lineReference = LineReference {_lineNumber = Nothing, _lineText = Cat 9 [Text 3 "foo",Format 3 (Attr {attrStyle = KeepCurrent, attrForeColor = SetTo (ISOColor 1), attrBackColor = KeepCurrent}) (Text 3 "bar"),Text 3 "baz"]}})
-- Just (FileLineReference {_file = File {_fileName = "path/to/file"}, _lineReference = LineReference {_lineNumber = Nothing, _lineText = Cat 9 [Text 3 "foo",Format 3 (Attr {attrStyle = KeepCurrent, attrForeColor = SetTo (ISOColor 1), attrBackColor = KeepCurrent, attrURL = KeepCurrent}) (Text 3 "bar"),Text 3 "baz"]}})
--
parseLine :: Text -> Maybe FileLineReference
parseLine line = case parseOnly lineParser line of
Expand Down
2 changes: 1 addition & 1 deletion src/Vgrep/Widget/HorizontalSplit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Vgrep.Widget.HorizontalSplit (

import Control.Applicative (liftA2)
import Control.Lens.Compat
import Graphics.Vty.Image hiding (resize)
import Graphics.Vty.Image

import Vgrep.Environment
import Vgrep.Event
Expand Down
2 changes: 1 addition & 1 deletion src/Vgrep/Widget/Pager.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import qualified Data.Sequence as Seq
import Data.Text (Text)
import qualified Data.Text as T
import Graphics.Vty.Attributes
import Graphics.Vty.Image hiding (resize)
import Graphics.Vty.Image

import Vgrep.Ansi
import Vgrep.Environment
Expand Down
6 changes: 3 additions & 3 deletions src/Vgrep/Widget/Pager/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ import Vgrep.Ansi
-- | Keeps track of the lines of text to display, the current scroll
-- positions, and the set of highlighted line numbers.
data Pager = Pager
{ _column :: Int
{ _column :: Int
-- ^ The current column offset for horizontal scrolling

, _highlighted :: IntMap AnsiFormatted
-- ^ Set of line numbers that are highlighted (i.e. they contain matches)

, _above :: Seq Text
, _above :: Seq Text
-- ^ Zipper: Lines above the screen

, _visible :: Seq Text
, _visible :: Seq Text
-- ^ Zipper: Lines on screen and below

} deriving (Eq, Show)
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md

# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
resolver: lts-9.0
resolver: lts-10.7

# Local packages, usually specified by relative directory name
packages:
Expand Down
10 changes: 5 additions & 5 deletions test/Test/Case.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ runTestCase :: TestCase -> TestTree
runTestCase = \case
TestProperty {..} -> testProperty description $ do
(initialState, initialEnv) <- testData
pure . monadic (`runVgrepForTest` (initialState, initialEnv)) $ do
pure . monadic (`runVgrepForTest` (initialState, initialEnv)) . void $ do
monitor (counterexample (show initialState))
monitor (counterexample (show initialEnv))
params <- testCase
stop =<< assertion params
TestInvariant {..} -> testProperty description $ do
(initialState, initialEnv) <- testData
pure . monadic (`runVgrepForTest` (initialState, initialEnv)) $ do
pure . monadic (`runVgrepForTest` (initialState, initialEnv)) . void $ do
monitor (counterexample (show initialState))
monitor (counterexample (show initialEnv))
before <- use invariant
Expand Down Expand Up @@ -83,16 +83,16 @@ runVgrepForTest
runVgrepForTest action (s, env) = fst (runIdentity (runVgrepT action s env))

monadicVgrep
:: Arbitrary s
:: (Arbitrary s, Testable a)
=> PropertyM (Vgrep s) a
-> Gen Property
monadicVgrep testcase = do
initialState <- arbitrary
initialEnv <- arbitrary
pure (monadic (`runVgrepForTest` (initialState, initialEnv)) testcase)
pure (monadic (`runVgrepForTest` (initialState, initialEnv)) (fmap property testcase))

testPropertyVgrep
:: Arbitrary s
:: (Arbitrary s, Testable a)
=> TestName
-> PropertyM (Vgrep s) a
-> TestTree
Expand Down
8 changes: 4 additions & 4 deletions test/Test/Vgrep/Widget/Results.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# LANGUAGE LambdaCase #-}
module Test.Vgrep.Widget.Results (test) where

import Control.Lens.Compat (Getter, over, to, view, _1)
import Control.Lens.Compat (Getter, over, to, view, (<&>), _1)
import Control.Monad (void)
import Data.Map.Strict ((!))
import qualified Data.Map.Strict as Map
Expand Down Expand Up @@ -34,15 +34,15 @@ test = runTestCases "Results widget"
{ description = "Scrolling one page down jumps to end of screen"
, testData = arbitrary
, testCase = run pageDown
, assertion = const $ get >>= pure . \case
, assertion = const $ get <&> \case
EmptyResults -> True
Results _ _ _ ds _ -> null ds
}
, TestProperty
{ description = "Scrolling one page up jumps to start of screen"
, testData = arbitrary
, testCase = run pageUp
, assertion = const $ get >>= pure . \case
, assertion = const $ get <&> \case
EmptyResults -> True
Results _ bs _ _ _ -> null bs
}
Expand Down Expand Up @@ -121,6 +121,6 @@ assertWidgetFitsOnScreen = do
(linesOnScreen <= height)

numberOfLinesOnScreen :: MonadState Results m => m Int
numberOfLinesOnScreen = get >>= pure . \case
numberOfLinesOnScreen = get <&> \case
EmptyResults -> 0
Results _ bs c ds _ -> length (mconcat [bs, pure c, ds])
4 changes: 2 additions & 2 deletions vgrep.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: vgrep
version: 0.2.1.0
version: 0.2.2.0
synopsis: A pager for grep
description:
@vgrep@ is a pager for navigating through @grep@ output.
Expand Down Expand Up @@ -70,7 +70,7 @@ library
, Vgrep.Widget.Results.Internal
, Vgrep.Widget.Type
build-depends: base >= 4.7 && < 5
, aeson (>= 0.11 && < 1.2) || (>= 0.9 && < 0.10)
, aeson (>= 0.11 && < 1.3) || (>= 0.9 && < 0.10)
, async >= 2.0.2
, attoparsec >= 0.12.1.6
, containers >= 0.5.6.2
Expand Down