CustomKeybindingDemo: improve comments

This commit is contained in:
Jonathan Daugherty 2022-08-04 19:16:15 -07:00
parent 1ba4c0974d
commit b0fbd7f638

View File

@ -141,22 +141,31 @@ main :: IO ()
main = do main = do
args <- getArgs args <- getArgs
-- If the command line specified the path to an INI file with custom
-- bindings, attempt to load it.
(customBindings, customFile) <- case args of (customBindings, customFile) <- case args of
[iniFilePath] -> do [iniFilePath] -> do
result <- K.keybindingsFromFile allKeyEvents sectionName iniFilePath result <- K.keybindingsFromFile allKeyEvents sectionName iniFilePath
case result of case result of
-- A section was found and had zero more bindings.
Right (Just bindings) -> Right (Just bindings) ->
return (bindings, Just iniFilePath) return (bindings, Just iniFilePath)
-- No section was found at all.
Right Nothing -> do Right Nothing -> do
putStrLn $ "Error: found no section " <> show sectionName <> " in " <> show iniFilePath putStrLn $ "Error: found no section " <> show sectionName <> " in " <> show iniFilePath
exitFailure exitFailure
-- There was some problem parsing the file as an INI
-- file.
Left e -> do Left e -> do
putStrLn $ "Error reading keybindings file " <> show iniFilePath <> ": " <> e putStrLn $ "Error reading keybindings file " <> show iniFilePath <> ": " <> e
exitFailure exitFailure
_ -> return ([], Nothing) _ -> return ([], Nothing)
-- Create a key config that has no customized bindings overriding -- Create a key config that includes the default bindings as well as
-- the default ones. -- the custom bindings we loaded from the INI file, if any.
let kc = K.newKeyConfig allKeyEvents defaultBindings customBindings let kc = K.newKeyConfig allKeyEvents defaultBindings customBindings
void $ M.defaultMain app $ St { _keyConfig = kc void $ M.defaultMain app $ St { _keyConfig = kc