jtdaugherty / brick

A declarative Unix terminal UI library written in Haskell
Other
1.58k stars 165 forks source link

Add keybindingINIList output to Brick.Keybindings.Pretty #513

Open xsebek opened 2 weeks ago

xsebek commented 2 weeks ago

I want to show users the current/default keybindings configuration. The output should look like this:

[keybindings]

;;;; Section name

;; Description of binding customized by user
quit = Alt-F4

;; Description of binding with default
; help = F1

In Swarm, I wrote keyBindingINI (which uses helper keybindingEventINI) by following the example of keybindingTextTable. The code is essentially duplicated, though I opted to ignore non-customizable bindings for the INI output.

It would be nice if this was provided by Brick, as an inverse to keybindingsFromIni.

jtdaugherty commented 2 weeks ago

I am open to adding something like this to brick. If I did, it would be shaped something like this:

data INIGenerationConfig =
    INIGenerationConfig { includeDescriptions :: Bool
                        , includeCustomizedBindings :: Bool
                        }

defaultINIGenerationConfig :: INIGenerationConfig
defaultINIGenerationConfig =
    INIGenerationConfig { includeDescriptions = True
                        , includeCustomizedBindings = True
                        }

keybindingsToIni :: INIGenerationConfig -> KeyConfig k -> Text

and would produce a hunk of INI text compatible with keybindingsFromIni.

Would that work for your purposes?

xsebek commented 2 weeks ago

@jtdaugherty sounds good to me. I assume you meant includeNonCustomizableBindings.

Should I create a PR or do you want to do it?

jtdaugherty commented 2 weeks ago

I assume you meant includeNonCustomizableBindings.

No, I meant includeCustomizedBindings, as in, whether to include bindings that have been changed from their defaults. I don't think a setting to control whether non-customizable bindings are included would be useful, since this is about producing an INI, and the only purpose of that is to customize bindings so the only ones worth including are the ones that can indeed be customized. Does that make sense?

Should I create a PR or do you want to do it?

If you would like to do so, that would be great - I don't know when I'll have time to get to it, so if you are more motivated or have more time, please be my guest.

Thanks!

jtdaugherty commented 2 weeks ago

Also, a minor note that I didn't mention since I was going to change it in the implementation anyway: I'd rather use # for comments in the generated INI than ;.

jtdaugherty commented 2 weeks ago

Also, I realized I forgot an argument. The function signature should be

keybindingsToIni :: INIGenerationConfig -> Text -> KeyConfig k -> Text

to include the name of the INI section that should be generated in the output.