Karya, built on 2023-08-29T07:47:28 (patch 7a412d5d6ba4968ca4155ef276a062ccdeb9109a)
Safe HaskellSafe-Inferred

Cmd.Keymap

Description

Support for efficient keymaps.

The sequence of Cmds which return Continue or Done is flexible, but probably inefficient in the presence of hundreds of commands. In addition, it can't warn about Cmds that respond to overlapping Msgs, e.g. respond to the same key.

Keymaps provide an efficient way to respond to a useful subset of Msgs, i.e. those which are considered 'key down' type msgs. The exact definition is in Bindable.

Keys are bound using SimpleMods, which are higher level than the ones in Ui.Key. This provides allows some abstraction between they key bindings and which actual modifiers those imply, and allows the conflation of multiple modifiers.

If you bind to a shifted key, it will be converted to Shift + unshifted by KeyLayouts.to_unshifted. But if you want to bind to the same physical key with and without shift, then you should bind to the unshifted version and add Shift yourself.

Synopsis

binding

plain_key :: Cmd.M m => Key.Key -> Text -> m () -> [Binding m] Source #

Bind a Key with no modifiers.

plain_char :: Cmd.M m => Char -> Text -> m () -> [Binding m] Source #

Bind a Char with no modifiers.

shift_char :: Cmd.M m => Char -> Text -> m () -> [Binding m] Source #

command_char :: Cmd.M m => Char -> Text -> m () -> [Binding m] Source #

Bind a Char with the PrimaryCommand.

secondary_char :: Cmd.M m => Char -> Text -> m () -> [Binding m] Source #

Bind a Char with the SecondaryCommand.

bind_key :: Cmd.M m => [SimpleMod] -> Key.Key -> Text -> m () -> [Binding m] Source #

Bind a key with the given modifiers.

bind_key_status :: [SimpleMod] -> Key.Key -> Text -> m Cmd.Status -> [Binding m] Source #

Bind a key with a Cmd that returns Status.

bind_repeatable :: Cmd.M m => [SimpleMod] -> Key.Key -> Text -> m () -> [Binding m] Source #

Like bind_key, but the binding will be retriggered on key repeat.

bind_click :: Cmd.M m => [SimpleMod] -> Types.MouseButton -> Cmd.MouseOn -> Int -> Text -> (Msg.Msg -> m ()) -> [Binding m] Source #

bind_click passes the Msg to the cmd, since mouse cmds are more likely to want the msg to find out where the click was. clicks is 1 for a single click, 2 for a double click, etc.

bind_drag :: Cmd.M m => [SimpleMod] -> Types.MouseButton -> Cmd.MouseOn -> Text -> (Msg.Msg -> m ()) -> [Binding m] Source #

A bind_drag binds both the click and the drag. It's conceivable to have click and drag bound to different commands, but I don't have any yet.

bind :: Cmd.M m => [SimpleMod] -> Cmd.Bindable -> Text -> (Msg.Msg -> m ()) -> [Binding m] Source #

Like bind_status but the Cmd is expected to return (), which will become Cmd.Done. Since the cmd has already been matched on the bound key this is likely what it would have done anyway.

bind_status :: [SimpleMod] -> Cmd.Bindable -> Text -> (Msg.Msg -> m Cmd.Status) -> [Binding m] Source #

This is the most general Binding constructor: bind any Bindable with any modifiers, and don't assume the cmd returns Done.

A capital letter is shorthand for Shift + Char.toLower c.

Handler

make_keymap :: [Binding m] -> (Cmd.Keymap m, [Text]) Source #

Create a Keymap for efficient lookup and return warnings encountered during construction.

SimpleMod

data SimpleMod Source #

The Msg contains the low level key information, but most commands should probably use these higher level modifiers. That way left and right shifts work the same, and cmds can use Command as customary on the Mac and Control as customary on linux.

Constructors

Shift 
PrimaryCommand

Primary command key: command on Mac, control on Linux and Windows. This should be used for core and global commands.

SecondaryCommand

Secondary comamnd key: control or option on Mac, alt on Linux and Windows. I'm not sure what this should be used for, but perhaps it can be for more specific event text modifications, while PrimaryCommand is for general purpose modifications. Also, it should have non-primitive cmds, so if you override them locally you won't lose anything essential.

Mouse Types.MouseButton

Having mouse here allows for mouse button chording.

Instances

Instances details
Show SimpleMod Source # 
Instance details

Defined in Cmd.Keymap

Eq SimpleMod Source # 
Instance details

Defined in Cmd.Keymap

Ord SimpleMod Source # 
Instance details

Defined in Cmd.Keymap

simple_mod_map :: Map SimpleMod Key.Modifier Source #

Map a SimpleMod to the Key.Modifiers it implies.

Bindable

overlaps :: [Binding m] -> [[Text]] Source #

expand_bindable :: Cmd.Bindable -> [Cmd.Bindable] Source #

A binding that accepts a KeyRepeat should also accept a KeyDown.