hoyo-0.6.0.0: Bookmark directories for cd
Copyright(c) Frederick Pringle 2023
LicenseBSD-3-Clause
Maintainerfreddyjepringle@gmail.com
Safe HaskellNone
LanguageHaskell2010

Hoyo.Utils

Description

Utility functions used by all the main Hoyo.* modules.

Synopsis

Lenses for ConfigValue

cfgBool :: Lens' (ConfigValue 'TBool) Bool Source #

A lens into a boolean config value.

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.

assert :: HoyoException -> HoyoMonad Bool -> HoyoMonad () Source #

Throw an error if a check fails.

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.

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 Bookmarks. 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.

tshow :: Show a => a -> Text Source #

Show a value as a Text instead of a String.

anyCfgValToJson :: AnyConfigValue -> JSValue Source #

Convert a configuration value to a JSON value. Used in `hoyo config print --json`.

bookmarksToJSON :: Bool -> [Bookmark] -> JSValue Source #

Convert a list of Bookmarks to a JSON value. Used in `hoyo list --json`.