-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use 'prettyprinter' library #67
Merged
Merged
Changes from 18 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
20d8a2d
Use 'prettyprinter' library for printing
georgefst 4625f30
Fix multi-line 'other's
georgefst da4ff87
Simplify and document annotation processing
georgefst 4b981a5
Remove unused TemplateHaskell pragma
georgefst 48a2359
More compactness - fixes 3 of the tests
georgefst 19b1c18
Simplify further
georgefst 07f82ca
Clean up and document
georgefst 11f99b2
Import Data.Monoid on older GHCs
georgefst 3b44727
Fix CPP syntax
georgefst 3d2460e
Haddock-ify a comment
georgefst c1b084d
Fix remaining tests
georgefst 677eb44
Use colour in executable and example
georgefst 4840dad
Use 'dropWhileEnd' instead of reversing list twice
georgefst f6ae384
Remove ViewPatterns
georgefst 3472c6d
Remove redundant $
georgefst e06aeeb
Use smarter layout algorithm
georgefst 0d4f41e
Include escape codes in output of 'pString' etc.
georgefst aa13ebc
Add missing case in 'isSimple'
georgefst 95a86f6
Make 'pString' lazy again
georgefst c1cc680
[skip ci] Fix typo
georgefst f5700ca
Bump prettyprinter-ansi-terminal version
georgefst 0de7092
Remove ansi-terminal dependency
georgefst 846b488
Use the new prettyprinter module names
georgefst 88f6a16
[skip ci] Alphabetise extensions
georgefst 2cc2093
Add stack extra-deps
georgefst 21f9804
Add note about stack extra-deps.
cdepillabout 56ad278
Update stack.yaml.lock.
cdepillabout 5d78be9
Add CI workflows.
cdepillabout aea27b3
Make sure to compile with the correct flag.
cdepillabout c91b35e
Update the build status shield on the README.
cdepillabout 9566022
Remove .travis.yml.
cdepillabout File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,10 @@ module Text.Pretty.Simple.Internal.Color | |
import Control.Applicative | ||
#endif | ||
|
||
import Data.Text.Lazy.Builder (Builder, fromString) | ||
import Data.Text.Prettyprint.Doc.Render.Terminal | ||
(AnsiStyle, Color(..), bold, colorDull, color) | ||
import Data.Typeable (Typeable) | ||
import GHC.Generics (Generic) | ||
import System.Console.ANSI | ||
(Color(..), ColorIntensity(..), ConsoleIntensity(..), | ||
ConsoleLayer(..), SGR(..), setSGRCode) | ||
|
||
-- | These options are for colorizing the output of functions like 'pPrint'. | ||
-- | ||
|
@@ -39,15 +37,15 @@ import System.Console.ANSI | |
-- | ||
-- If you don't want to use a color for one of the options, use 'colorNull'. | ||
data ColorOptions = ColorOptions | ||
{ colorQuote :: Builder | ||
{ colorQuote :: AnsiStyle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Colours are now expressed with AnsiStyle. This should actually be easier for users to work with, but is obviously a breaking change. |
||
-- ^ Color to use for quote characters (@\"@) around strings. | ||
, colorString :: Builder | ||
, colorString :: AnsiStyle | ||
-- ^ Color to use for strings. | ||
, colorError :: Builder | ||
-- ^ (currently not used) | ||
, colorNum :: Builder | ||
, colorError :: AnsiStyle | ||
-- ^ Color for errors, e.g. unmatched brackets. | ||
, colorNum :: AnsiStyle | ||
-- ^ Color to use for numbers. | ||
, colorRainbowParens :: [Builder] | ||
, colorRainbowParens :: [AnsiStyle] | ||
-- ^ A list of 'Builder' colors to use for rainbow parenthesis output. Use | ||
-- '[]' if you don't want rainbow parenthesis. Use just a single item if you | ||
-- want all the rainbow parenthesis to be colored the same. | ||
|
@@ -75,26 +73,26 @@ defaultColorOptionsDarkBg = | |
|
||
-- | Default color for 'colorQuote' for dark backgrounds. This is | ||
-- 'colorVividWhiteBold'. | ||
defaultColorQuoteDarkBg :: Builder | ||
defaultColorQuoteDarkBg :: AnsiStyle | ||
defaultColorQuoteDarkBg = colorVividWhiteBold | ||
|
||
-- | Default color for 'colorString' for dark backgrounds. This is | ||
-- 'colorVividBlueBold'. | ||
defaultColorStringDarkBg :: Builder | ||
defaultColorStringDarkBg :: AnsiStyle | ||
defaultColorStringDarkBg = colorVividBlueBold | ||
|
||
-- | Default color for 'colorError' for dark backgrounds. This is | ||
-- 'colorVividRedBold'. | ||
defaultColorErrorDarkBg :: Builder | ||
defaultColorErrorDarkBg :: AnsiStyle | ||
defaultColorErrorDarkBg = colorVividRedBold | ||
|
||
-- | Default color for 'colorNum' for dark backgrounds. This is | ||
-- 'colorVividGreenBold'. | ||
defaultColorNumDarkBg :: Builder | ||
defaultColorNumDarkBg :: AnsiStyle | ||
defaultColorNumDarkBg = colorVividGreenBold | ||
|
||
-- | Default colors for 'colorRainbowParens' for dark backgrounds. | ||
defaultColorRainbowParensDarkBg :: [Builder] | ||
defaultColorRainbowParensDarkBg :: [AnsiStyle] | ||
defaultColorRainbowParensDarkBg = | ||
[ colorVividMagentaBold | ||
, colorVividCyanBold | ||
|
@@ -132,26 +130,26 @@ defaultColorOptionsLightBg = | |
|
||
-- | Default color for 'colorQuote' for light backgrounds. This is | ||
-- 'colorVividWhiteBold'. | ||
defaultColorQuoteLightBg :: Builder | ||
defaultColorQuoteLightBg :: AnsiStyle | ||
defaultColorQuoteLightBg = colorVividBlackBold | ||
|
||
-- | Default color for 'colorString' for light backgrounds. This is | ||
-- 'colorVividBlueBold'. | ||
defaultColorStringLightBg :: Builder | ||
defaultColorStringLightBg :: AnsiStyle | ||
defaultColorStringLightBg = colorVividBlueBold | ||
|
||
-- | Default color for 'colorError' for light backgrounds. This is | ||
-- 'colorVividRedBold'. | ||
defaultColorErrorLightBg :: Builder | ||
defaultColorErrorLightBg :: AnsiStyle | ||
defaultColorErrorLightBg = colorVividRedBold | ||
|
||
-- | Default color for 'colorNum' for light backgrounds. This is | ||
-- 'colorVividGreenBold'. | ||
defaultColorNumLightBg :: Builder | ||
defaultColorNumLightBg :: AnsiStyle | ||
defaultColorNumLightBg = colorVividGreenBold | ||
|
||
-- | Default colors for 'colorRainbowParens' for light backgrounds. | ||
defaultColorRainbowParensLightBg :: [Builder] | ||
defaultColorRainbowParensLightBg :: [AnsiStyle] | ||
defaultColorRainbowParensLightBg = | ||
[ colorVividMagentaBold | ||
, colorVividCyanBold | ||
|
@@ -167,141 +165,122 @@ defaultColorRainbowParensLightBg = | |
-- Vivid Bold Colors -- | ||
----------------------- | ||
|
||
colorVividBlackBold :: Builder | ||
colorVividBlackBold :: AnsiStyle | ||
colorVividBlackBold = colorBold `mappend` colorVividBlack | ||
|
||
colorVividBlueBold :: Builder | ||
colorVividBlueBold :: AnsiStyle | ||
colorVividBlueBold = colorBold `mappend` colorVividBlue | ||
|
||
colorVividCyanBold :: Builder | ||
colorVividCyanBold :: AnsiStyle | ||
colorVividCyanBold = colorBold `mappend` colorVividCyan | ||
|
||
colorVividGreenBold :: Builder | ||
colorVividGreenBold :: AnsiStyle | ||
colorVividGreenBold = colorBold `mappend` colorVividGreen | ||
|
||
colorVividMagentaBold :: Builder | ||
colorVividMagentaBold :: AnsiStyle | ||
colorVividMagentaBold = colorBold `mappend` colorVividMagenta | ||
|
||
colorVividRedBold :: Builder | ||
colorVividRedBold :: AnsiStyle | ||
colorVividRedBold = colorBold `mappend` colorVividRed | ||
|
||
colorVividWhiteBold :: Builder | ||
colorVividWhiteBold :: AnsiStyle | ||
colorVividWhiteBold = colorBold `mappend` colorVividWhite | ||
|
||
colorVividYellowBold :: Builder | ||
colorVividYellowBold :: AnsiStyle | ||
colorVividYellowBold = colorBold `mappend` colorVividYellow | ||
|
||
----------------------- | ||
-- Dull Bold Colors -- | ||
----------------------- | ||
|
||
colorDullBlackBold :: Builder | ||
colorDullBlackBold :: AnsiStyle | ||
colorDullBlackBold = colorBold `mappend` colorDullBlack | ||
|
||
colorDullBlueBold :: Builder | ||
colorDullBlueBold :: AnsiStyle | ||
colorDullBlueBold = colorBold `mappend` colorDullBlue | ||
|
||
colorDullCyanBold :: Builder | ||
colorDullCyanBold :: AnsiStyle | ||
colorDullCyanBold = colorBold `mappend` colorDullCyan | ||
|
||
colorDullGreenBold :: Builder | ||
colorDullGreenBold :: AnsiStyle | ||
colorDullGreenBold = colorBold `mappend` colorDullGreen | ||
|
||
colorDullMagentaBold :: Builder | ||
colorDullMagentaBold :: AnsiStyle | ||
colorDullMagentaBold = colorBold `mappend` colorDullMagenta | ||
|
||
colorDullRedBold :: Builder | ||
colorDullRedBold :: AnsiStyle | ||
colorDullRedBold = colorBold `mappend` colorDullRed | ||
|
||
colorDullWhiteBold :: Builder | ||
colorDullWhiteBold :: AnsiStyle | ||
colorDullWhiteBold = colorBold `mappend` colorDullWhite | ||
|
||
colorDullYellowBold :: Builder | ||
colorDullYellowBold :: AnsiStyle | ||
colorDullYellowBold = colorBold `mappend` colorDullYellow | ||
|
||
------------------ | ||
-- Vivid Colors -- | ||
------------------ | ||
|
||
colorVividBlack :: Builder | ||
colorVividBlack = colorHelper Vivid Black | ||
colorVividBlack :: AnsiStyle | ||
colorVividBlack = color Black | ||
|
||
colorVividBlue :: Builder | ||
colorVividBlue = colorHelper Vivid Blue | ||
colorVividBlue :: AnsiStyle | ||
colorVividBlue = color Blue | ||
|
||
colorVividCyan :: Builder | ||
colorVividCyan = colorHelper Vivid Cyan | ||
colorVividCyan :: AnsiStyle | ||
colorVividCyan = color Cyan | ||
|
||
colorVividGreen :: Builder | ||
colorVividGreen = colorHelper Vivid Green | ||
colorVividGreen :: AnsiStyle | ||
colorVividGreen = color Green | ||
|
||
colorVividMagenta :: Builder | ||
colorVividMagenta = colorHelper Vivid Magenta | ||
colorVividMagenta :: AnsiStyle | ||
colorVividMagenta = color Magenta | ||
|
||
colorVividRed :: Builder | ||
colorVividRed = colorHelper Vivid Red | ||
colorVividRed :: AnsiStyle | ||
colorVividRed = color Red | ||
|
||
colorVividWhite :: Builder | ||
colorVividWhite = colorHelper Vivid White | ||
colorVividWhite :: AnsiStyle | ||
colorVividWhite = color White | ||
|
||
colorVividYellow :: Builder | ||
colorVividYellow = colorHelper Vivid Yellow | ||
colorVividYellow :: AnsiStyle | ||
colorVividYellow = color Yellow | ||
|
||
------------------ | ||
-- Dull Colors -- | ||
------------------ | ||
|
||
colorDullBlack :: Builder | ||
colorDullBlack = colorHelper Dull Black | ||
colorDullBlack :: AnsiStyle | ||
colorDullBlack = colorDull Black | ||
|
||
colorDullBlue :: Builder | ||
colorDullBlue = colorHelper Dull Blue | ||
colorDullBlue :: AnsiStyle | ||
colorDullBlue = colorDull Blue | ||
|
||
colorDullCyan :: Builder | ||
colorDullCyan = colorHelper Dull Cyan | ||
colorDullCyan :: AnsiStyle | ||
colorDullCyan = colorDull Cyan | ||
|
||
colorDullGreen :: Builder | ||
colorDullGreen = colorHelper Dull Green | ||
colorDullGreen :: AnsiStyle | ||
colorDullGreen = colorDull Green | ||
|
||
colorDullMagenta :: Builder | ||
colorDullMagenta = colorHelper Dull Magenta | ||
colorDullMagenta :: AnsiStyle | ||
colorDullMagenta = colorDull Magenta | ||
|
||
colorDullRed :: Builder | ||
colorDullRed = colorHelper Dull Red | ||
colorDullRed :: AnsiStyle | ||
colorDullRed = colorDull Red | ||
|
||
colorDullWhite :: Builder | ||
colorDullWhite = colorHelper Dull White | ||
colorDullWhite :: AnsiStyle | ||
colorDullWhite = colorDull White | ||
|
||
colorDullYellow :: Builder | ||
colorDullYellow = colorHelper Dull Yellow | ||
colorDullYellow :: AnsiStyle | ||
colorDullYellow = colorDull Yellow | ||
|
||
-------------------- | ||
-- Special Colors -- | ||
-------------------- | ||
|
||
-- | Change the intensity to 'BoldIntensity'. | ||
colorBold :: Builder | ||
colorBold = setSGRCodeBuilder [SetConsoleIntensity BoldIntensity] | ||
|
||
-- | 'Reset' the console color back to normal. | ||
colorReset :: Builder | ||
colorReset = setSGRCodeBuilder [Reset] | ||
colorBold :: AnsiStyle | ||
colorBold = bold | ||
|
||
-- | Empty string. | ||
colorNull :: Builder | ||
colorNull = "" | ||
|
||
------------- | ||
-- Helpers -- | ||
------------- | ||
|
||
-- | Helper for creating a 'Builder' for an ANSI escape sequence color based on | ||
-- a 'ColorIntensity' and a 'Color'. | ||
colorHelper :: ColorIntensity -> Color -> Builder | ||
colorHelper colorIntensity color = | ||
setSGRCodeBuilder [SetColor Foreground colorIntensity color] | ||
|
||
-- | Convert a list of 'SGR' to a 'Builder'. | ||
setSGRCodeBuilder :: [SGR] -> Builder | ||
setSGRCodeBuilder = fromString . setSGRCode | ||
|
||
colorNull :: AnsiStyle | ||
colorNull = mempty |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two modules have gone, as we now render straight from
Expr
.The remaining
OutputPrinter
should perhaps be renamedExprPrinter
, since the oldOutput
type that was being printed there no longer even exists.