Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Helpers for pretty-printing haskell values, reading command line arguments, working with ANSI colours, files, and time. Uses unsafePerformIO.
Limitations: When running in GHCI, this module must be reloaded to see environmental changes. The colour scheme may be somewhat hard-coded.
Synopsis
- pshow :: Show a => a -> String
- pshow' :: Show a => a -> String
- pprint :: Show a => a -> IO ()
- pprint' :: Show a => a -> IO ()
- progArgs :: [String]
- outputFileOption :: Maybe String
- hasOutputFile :: Bool
- colorOption :: String
- useColorOnStdout :: Bool
- useColorOnStderr :: Bool
- color :: ColorIntensity -> Color -> String -> String
- bgColor :: ColorIntensity -> Color -> String -> String
- colorB :: ColorIntensity -> Color -> WideBuilder -> WideBuilder
- bgColorB :: ColorIntensity -> Color -> WideBuilder -> WideBuilder
- error' :: String -> a
- usageError :: String -> a
- embedFileRelative :: FilePath -> Q Exp
- expandHomePath :: FilePath -> IO FilePath
- expandPath :: FilePath -> FilePath -> IO FilePath
- readFileOrStdinPortably :: String -> IO Text
- readFilePortably :: FilePath -> IO Text
- readHandlePortably :: Handle -> IO Text
- getCurrentLocalTime :: IO LocalTime
- getCurrentZonedTime :: IO ZonedTime
Pretty showing/printing
Command line arguments
The command line arguments that were used at program startup. Uses unsafePerformIO.
outputFileOption :: Maybe String Source #
Read the value of the -o/--output-file command line option provided at program startup, if any, using unsafePerformIO.
hasOutputFile :: Bool Source #
Check whether the -o/--output-file option has been used at program startup with an argument other than "-", using unsafePerformIO.
ANSI color
colorOption :: String Source #
Read the value of the --color or --colour command line option provided at program startup using unsafePerformIO. If this option was not provided, returns the empty string.
useColorOnStdout :: Bool Source #
Check the IO environment to see if ANSI colour codes should be used on stdout. This is done using unsafePerformIO so it can be used anywhere, eg in low-level debug utilities, which should be ok since we are just reading. The logic is: use color if the program was started with --color=yes|always or ( the program was not started with --color=no|never and a NO_COLOR environment variable is not defined and stdout supports ANSI color and -o/--output-file was not used, or its value is "-" ).
useColorOnStderr :: Bool Source #
Like useColorOnStdout, but checks for ANSI color support on stderr, and is not affected by -o/--output-file.
color :: ColorIntensity -> Color -> String -> String Source #
Wrap a string in ANSI codes to set and reset foreground colour.
bgColor :: ColorIntensity -> Color -> String -> String Source #
Wrap a string in ANSI codes to set and reset background colour.
colorB :: ColorIntensity -> Color -> WideBuilder -> WideBuilder Source #
Wrap a WideBuilder in ANSI codes to set and reset foreground colour.
bgColorB :: ColorIntensity -> Color -> WideBuilder -> WideBuilder Source #
Wrap a WideBuilder in ANSI codes to set and reset background colour.
Errors
usageError :: String -> a Source #
A version of errorWithoutStackTrace that adds a usage hint.
Files
embedFileRelative :: FilePath -> Q Exp Source #
Like embedFile, but takes a path relative to the package directory. Similar to embedFileRelative ?
expandPath :: FilePath -> FilePath -> IO FilePath Source #
Convert a possibly relative, possibly tilde-containing file path to an absolute one, given the current directory. ~username is not supported. Leave "-" unchanged. Can raise an error.
readFileOrStdinPortably :: String -> IO Text Source #
Like readFilePortably, but read from standard input if the path is "-".
readFilePortably :: FilePath -> IO Text Source #
Read text from a file, converting any rn line endings to n,, using the system locale's text encoding, ignoring any utf8 BOM prefix (as seen in paypal's 2018 CSV, eg) if that encoding is utf8.