Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- configFromFile :: MonadIO io => io ConfigMonoid
- data Attr
- data Color
- data Style
Documentation
configFromFile :: MonadIO io => io ConfigMonoid Source #
Reads the configuration from a JSON or YAML file. The file should be located in one of the following places:
~/.vgrep/config.yaml
,~/.vgrep/config.yml
,~/.vgrep/config.json
or~/.vgrep/config
.
When none of these files exist, no error is raised. When a file exists, but cannot be parsed, a warning is written to stderr.
Supported formats are JSON and YAML. The example YAML config given in the
project directory (config.yaml.example
) is equivalent to the default
config:
>>>
import qualified Vgrep.Environment.Config as C
>>>
Right config <- decodeFileEither "config.yaml.example" :: IO (Either ParseException ConfigMonoid)
>>>
C.fromConfigMonoid config == C.defaultConfig
True
Example YAML config file for defaultConfig
:
colors: line-numbers: fore-color: blue line-numbers-hl: fore-color: blue style: bold normal: {} normal-hl: style: bold file-headers: back-color: green selected: style: standout tabstop: 8 editor: "vi"
Example JSON file for the same config:
{ "colors": { "line-numbers" : { "fore-color": "blue" }, "line-numbers-hl": { "fore-color": "blue", "style": "bold" }, "normal": {}, "normal-hl": { "style": "bold" }, "file-headers": { "back-color": "green" }, "selected": { "style": "standout" } }, "tabstop": 8, "editor": "vi" }
The JSON/YAML keys correspond to the lenses in Vgrep.Environment.Config,
the values for Color
and Style
can be obtained from the
corresponding predefined constants in Graphics.Vty.Attributes.
A JSON-parsable data type for Attr
.
JSON example:
>>>
decodeEither' "{\"fore-color\": \"black\", \"style\": \"standout\"}" :: Either ParseException Attr
Right (Attr {foreColor = Just Black, backColor = Nothing, style = Just Standout})
JSON example without quotes: >>> decodeEither' "{fore-color: black, style: standout}" :: Either ParseException Attr Right (Attr {foreColor = Just Black, backColor = Nothing, style = Just Standout})
YAML example:
>>>
:{
>>>
decodeEither'
>>>
$ "fore-color: \"blue\"\n"
>>>
<> "back-color: \"bright-blue\"\n"
>>>
<> "style: \"reverse-video\"\n"
>>>
:: Either ParseException Attr
>>>
:}
Right (Attr {foreColor = Just Blue, backColor = Just BrightBlue, style = Just ReverseVideo})
YAML example without quotes:
>>>
:{
>>>
decodeEither'
>>>
$ "fore-color: blue\n"
>>>
<> "back-color: bright-blue\n"
>>>
<> "style: reverse-video\n"
>>>
:: Either ParseException Attr
>>>
:}
Right (Attr {foreColor = Just Blue, backColor = Just BrightBlue, style = Just ReverseVideo})
An empty JSON/YAML object yields the default colors:
>>>
decodeEither' "{}" :: Either ParseException Attr
Right (Attr {foreColor = Nothing, backColor = Nothing, style = Nothing})
Instances
Eq Attr Source # | |
Show Attr Source # | |
Generic Attr Source # | |
FromJSON Attr Source # | |
type Rep Attr Source # | |
Defined in Vgrep.Environment.Config.Sources.File type Rep Attr = D1 ('MetaData "Attr" "Vgrep.Environment.Config.Sources.File" "vgrep-0.2.3.0-79CAs1b54BVGsHizAm4Sjp" 'False) (C1 ('MetaCons "Attr" 'PrefixI 'True) (S1 ('MetaSel ('Just "foreColor") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Color)) :*: (S1 ('MetaSel ('Just "backColor") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Color)) :*: S1 ('MetaSel ('Just "style") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Style))))) |
A JSON-parsable data type for Color
.
>>>
decodeEither' "[\"black\",\"red\",\"bright-black\"]" :: Either ParseException [Color]
Right [Black,Red,BrightBlack]
Also works without quotes:
>>>
decodeEither' "[black,red,bright-black]" :: Either ParseException [Color]
Right [Black,Red,BrightBlack]
Fails with error message if the Color
cannot be parsed:
>>>
isLeft (decodeEither' "foo" :: Either ParseException Color)
True
Instances
A JSON-parsable data type for Style
.
>>>
decodeEither' "[\"standout\", \"underline\", \"bold\"]" :: Either ParseException [Style]
Right [Standout,Underline,Bold]
Also works without quotes:
>>>
decodeEither' "[standout, underline, bold]" :: Either ParseException [Style]
Right [Standout,Underline,Bold]
Fails with error message if the Style
cannot be parsed:
>>>
isLeft (decodeEither' "foo" :: Either ParseException Color)
True
Instances
Eq Style Source # | |
Show Style Source # | |
Generic Style Source # | |
FromJSON Style Source # | |
type Rep Style Source # | |
Defined in Vgrep.Environment.Config.Sources.File type Rep Style = D1 ('MetaData "Style" "Vgrep.Environment.Config.Sources.File" "vgrep-0.2.3.0-79CAs1b54BVGsHizAm4Sjp" 'False) ((C1 ('MetaCons "Standout" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "Underline" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "ReverseVideo" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "Blink" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "Dim" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Bold" 'PrefixI 'False) (U1 :: Type -> Type)))) |
Orphan instances
FromJSON Attr Source # | |
FromJSON Command Source # | |
FromJSON KeybindingMap Source # | |
parseJSON :: Value -> Parser KeybindingMap # parseJSONList :: Value -> Parser [KeybindingMap] # | |
FromJSON KeybindingsMonoid Source # | |
parseJSON :: Value -> Parser KeybindingsMonoid # parseJSONList :: Value -> Parser [KeybindingsMonoid] # | |
FromJSON ColorsMonoid Source # | |
parseJSON :: Value -> Parser ColorsMonoid # parseJSONList :: Value -> Parser [ColorsMonoid] # | |
FromJSON ConfigMonoid Source # | |
parseJSON :: Value -> Parser ConfigMonoid # parseJSONList :: Value -> Parser [ConfigMonoid] # |