Copyright | (c) Frederick Pringle 2023 |
---|---|
License | BSD-3-Clause |
Maintainer | freddyjepringle@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
Utility functions used by all the main Hoyo.* modules.
Synopsis
- cfgBool :: Lens' (ConfigValue 'TBool) Bool
- cfgDefaultBookmark :: Lens' (ConfigValue 'TDefaultBookmark) DefaultBookmark
- cfgCommand :: Lens' (ConfigValue 'TCommand) Command
- cfgList :: Lens' (ConfigValue ('TList t)) [ConfigValue t]
- cfgMaybe :: Lens' (ConfigValue ('TMaybe t)) (Maybe (ConfigValue t))
- failOnError :: Lens' Config Bool
- displayCreationTime :: Lens' Config Bool
- enableClearing :: Lens' Config Bool
- enableReset :: Lens' Config Bool
- backupBeforeClear :: Lens' Config Bool
- defaultBookmarks :: Lens' Config [DefaultBookmark]
- defaultCommand :: Lens' Config (Maybe Command)
- asks' :: MonadReader a m => SimpleGetter a b -> m b
- assert :: HoyoException -> HoyoMonad Bool -> HoyoMonad ()
- assertVerbose :: HoyoException -> HoyoMonad Bool -> HoyoMonad Bool
- maximumDefault :: Ord a => a -> [a] -> a
- catchIOException :: Monad m => IOException -> m (Either HoyoException a)
- backupFile :: (MonadIO m, MonadError HoyoException m) => FilePath -> String -> m ()
- readBool :: MonadError HoyoException m => Text -> m Bool
- readInt :: MonadError HoyoException m => Text -> m Int
- printStdout :: MonadIO m => Text -> m ()
- printStderr :: MonadIO m => Text -> m ()
- pageLines :: MonadIO m => [Text] -> m ()
- formatArgs :: [Text] -> Text
- formatCommand :: Command -> [Text]
- formatBookmark :: Bool -> Int -> Int -> Bookmark -> Text
- formatBookmarks :: Bool -> [Bookmark] -> [Text]
- formatConfigValue :: AnyConfigValue -> Text
- formatOptions :: Options -> [Text]
- formatException :: HoyoException -> Text
- tshow :: Show a => a -> Text
- anyCfgValToJson :: AnyConfigValue -> JSValue
- bookmarksToJSON :: Bool -> [Bookmark] -> JSValue
Lenses for ConfigValue
cfgDefaultBookmark :: Lens' (ConfigValue 'TDefaultBookmark) DefaultBookmark Source #
A lens into a default bookmark config value.
cfgCommand :: Lens' (ConfigValue 'TCommand) Command Source #
A lens into a command config value.
cfgList :: Lens' (ConfigValue ('TList t)) [ConfigValue t] Source #
A lens into a list config value.
cfgMaybe :: Lens' (ConfigValue ('TMaybe t)) (Maybe (ConfigValue t)) Source #
A lens into an optional config value.
Lenses for Config
Utility functions
asks' :: MonadReader a m => SimpleGetter a b -> m b Source #
A version of the lens "use" function for MonadReader
.
assertVerbose :: HoyoException -> HoyoMonad Bool -> HoyoMonad Bool Source #
Throw an error if a check fails AND the "fail_on_error" flag is set.
maximumDefault :: Ord a => a -> [a] -> a Source #
Take the maximum of a list, with a default value if the list is empty.
catchIOException :: Monad m => IOException -> m (Either HoyoException a) Source #
Catch an IOException
and wrap it in a HoyoException
.
Backups
backupFile :: (MonadIO m, MonadError HoyoException m) => FilePath -> String -> m () Source #
Try to back-up a file. Used when the "backup_before_clear" option is set.
Parsing functions
readBool :: MonadError HoyoException m => Text -> m Bool Source #
Try to read a Bool
.
readInt :: MonadError HoyoException m => Text -> m Int Source #
Try to read an Int
.
Printing functions
printStdout :: MonadIO m => Text -> m () Source #
Print to stdout.
printStderr :: MonadIO m => Text -> m () Source #
Print to stderr.
pageLines :: MonadIO m => [Text] -> m () Source #
Page lines if larger than one page and if the output device is a terminal. Otherwise, print.
Formatting functions
formatArgs :: [Text] -> Text Source #
Format a list of arguments into a single Text
, enclosing multi-word arguments in quotes.
formatCommand :: Command -> [Text] Source #
Format a Command
in the same way it would be parsed from the command line.
formatBookmark :: Bool -> Int -> Int -> Bookmark -> Text Source #
Format a Bookmark
. Used for the "list" command and error reporting
during other commands.
formatBookmark displayTime numberWidth bm
returns a pretty representation
of bm
, optionally showing the creation time, and padding the index and
directory to a certain width.
formatBookmarks :: Bool -> [Bookmark] -> [Text] Source #
Format a list of Bookmark
s. Used for the "list" command and error reporting
during other commands
formatBookmark displayTime bms
returns a pretty representation
of bms
, optionally showing the creation time, and padding the indices to
line up.
formatConfigValue :: AnyConfigValue -> Text Source #
Format a config value. Used for the "config print" command.
formatOptions :: Options -> [Text] Source #
Format an Options
object in the same way it would be parsed from the command line.
formatException :: HoyoException -> Text Source #
Format a HoyoException
to display to the user.
anyCfgValToJson :: AnyConfigValue -> JSValue Source #
Convert a configuration value to a JSON value. Used in `hoyo config print --json`.