aboutsummaryrefslogtreecommitdiffstats
path: root/src/keys.c
Commit message (Collapse)AuthorAgeFilesLines
* Update copyright ranges for 2022Lukas Fleischer2022-03-111-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add generic-prev-view key bindingAurora2021-04-111-0/+3
| | | | | | | This can be used to cycle backwards through windows (similarly to generic-change-view). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Allow undefined actions in keys configuration fileLars Henriksen2021-04-111-116/+214
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the keys file there are three possibilities for each action: 1. One or several keys are assigned to it 2. It is marked as UNDEFINED (new) 3. It is missing from the file On load of the keys file, calcurse respectively 1. Assigns the key(s) 2. Assigns "UNDEFINED" (new) 3. Assigns a default key if possible If default keys were assigned, the user is informed of the number of actions affected, and the keys file is updated. After load each action must either have keys assigned or be undefined. If not, calcurse exits with a failure. If there are syntax/semantic errors in the file, calcurse rejects the file and exits. When an interactive user leaves the keys configuration menu, a warning is issued if any action is UNDEFINED. The keys file is always updated. Addresses GitHub issue #298. Additionally: Description of concepts and data structures used for keyboard keys and virtual keys (actions) as well as name changes and comments to improve readability. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2020-01-301-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Refactor cut and paste registersLars Henriksen2020-01-131-2/+0
| | | | | | | | | | Register REG_BLACK_HOLE can neither be copied into nor pasted from and has been removed from the input routine. Register 36 was not used. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Refactor keys_format_label()Lukas Fleischer2019-01-191-24/+9
| | | | | | | Simplify the key formatting function and enforce display width properly using the UTF8 chopping function. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Bind RETURN to view-item by defaultLukas Fleischer2019-01-191-2/+2
| | | | | | | | | Also, use the modern key name instead of the backwards compatibility name. Addresses GitHub issue #168. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Key bindings for UTF-8 encoded charactersLars Henriksen2018-06-031-11/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Internally characters (keys) have two representations: integers and key names. Key names are characters strings, usually the name of the character; e.g., the character A has the representations 65 and "A", and the tab character the representations 9 and "TAB". The function keys_int2str() turns the integer representation of a key/character into the key name. For display purposes the key names are usually confined to have display width at most three. Some curses pseudo-keys have longer key names; e.g., the back-tab character is "KEY_BTAB". A long key name makes a character difficult to recognize in the status bar menu. The key name of a multibyte, UTF-8 encoded character is the conventional Unicode name of the code point; e.g., the character ü has key name "U+00FC" because ü is the code point 0xFC. Most of these look alike in the status bar menu. The patch makes the key name of a multibyte character look like that of a singlebyte character: the character itself, i.e. the key name of the character ü is "ü". The main tool is implementation of a utf8_encode() routine. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Rename utf8_ord() to utf8_decode()Lars Henriksen2018-06-031-1/+1
| | | | | | | Purely for readability and in preparation for the counterpart utf8_encode(). Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Always NUL-terminate buffer in keys_fill_missing()Lukas Fleischer2018-05-261-0/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix buffer overflow in keys_action_allkeys()Lukas Fleischer2018-05-261-4/+9
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix end-of-string calculationLars Henriksen2018-05-241-1/+1
| | | | | | | | In keys_fill_missing() a pointer is walked through a string of space-separated character names, but misses the string-terminating null character. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Detect error on character inputLars Henriksen2017-10-291-1/+5
| | | | | | | | | | Previously an error from the character input routine wgetch() was silently ignored. It should still be ignored, but must explicitly be detected in order to be ignored. The issue came up in connection with terminal window resize. For whatever reasons ncurses returns ERR (as well as KEY_RESIZE) when wgetch() asks for input after a resize. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Support key bindings for all escape keysLars Henriksen2017-10-231-79/+89
| | | | | | | | | | | | | | | | | | | | | All key names for ordinary ASCII keys as well as for escape keys (pseudo keys) are cached in a lookup-table, keynames[], at startup. Mapping between key names (strings) and key codes (integers) in keys_str2int and keys_int2str) is performed through this table. The key names used are those returned by the keyname() function of ncurses. But to accommodate some of the names to the three-letter space available in the status menu, four ordinary keys and the most common escape keys have calcurse abbreviated names: ESC, TAB, RET, SPC and LFT, HOM, PgU, INS, F1, etc. All keys known by ncurses can be bound. Thus the check for not recognized keys in the key configuration menu becomes superfluous. The only keys that cannot be bound, are those escape keys not known to ncurses, i.e. not described by the terminfo database for the terminal type in use. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Updates for UTF-8 key bindingsLars Henriksen2017-10-231-32/+26
| | | | | | | | | | | | | | | | | | | | | Code point mapping adjusted for multibyte characters to avoid the ncurses range 0-KEY_MAX. This includes three fixes: 1) test sequence in keys_assign_binding(), 2) reassemble multi-byte character in keys_wgetch(), 3) check for already in use in keys_assign_binding(). Rearrangement of code. The introduction of allocated memory in keys_int2str() has as a consequence that check for recognized ncurses pseudo characters now are in two places: keys_str2int() and custom_keys_config(). The latter was moved from keys_wgetch() to improve user information. More informative warning messages in custom_keys_config(). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add a function to wait for any key pressLukas Fleischer2017-09-031-0/+5
| | | | | | | Introduce a new function keys_wait_for_any_key() and use it instead of wgetch() whenever the return value is discarded. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add support for UTF-8 key bindingsLukas Fleischer2017-08-301-27/+107
| | | | | | | | | | | | | | | | A new function keys_wgetch() reads full UTF-8 characters instead of single ASCII characters only. Key bindings for regular ASCII characters are stored in a hash map while the actions of keys with higher code points are stored in a linked list for space efficiency. The key serialization methods are updated to handle UTF-8 characters as well; extended UTF-8 characters (characters not in the ASCII range) are serialized by using the hexadecimal representation of the corresponding code points (e.g. "U+00E4"). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Rename keys_getch() to keys_get()Lukas Fleischer2017-08-301-2/+2
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2017-01-121-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2016-01-301-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Introduce starts_with() and starts_with_ci()Lukas Fleischer2015-02-241-39/+27
| | | | | | | | Create user-defined functions to check whether a string contains a certain prefix instead of messing around with strncmp() and strncasecmp(). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Update copyright rangesLukas Fleischer2015-02-071-1/+1
| | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use wins_set_bindings() for the configuration menuLukas Fleischer2014-07-181-6/+41
| | | | | | | Make use of the general key binding context switching implementation for the configuration main menu. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Make bindings always fill the whole status barLukas Fleischer2014-07-181-0/+2
| | | | | | | Compute padding for key bindings in the status bar such that they use all available space (without exceeding the given page size). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* keys.c: Merge keydef and binding_labelsLukas Fleischer2014-07-171-100/+51
| | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Rework key binding context switchingLukas Fleischer2014-07-171-10/+61
| | | | | | | Store key binding contexts using another data structure to optimize space usage and execution time. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add a key binding to reload appointments and todosLukas Fleischer2014-07-161-1/+3
| | | | | | | This allows for reloading the appointment and todo item files without having to restart calcurse. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add command promptLukas Fleischer2013-07-171-0/+2
| | | | | | | | | | This adds support for vim-style command mode. The command mode can be entered with pressing ":" (by default, the key binding is configurable). Currently, no command is supported. Support for various commands will be added later. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use tabs instead of spaces for indentationLukas Fleischer2013-04-141-432/+448
| | | | | | | | | | | This completes our switch to the Linux kernel coding style. Note that we still use deeply nested constructs at some places which need to be fixed up later. Converted using the `Lindent` script from the Linux kernel code base, along with some manual fixes. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Fix braces in if-else statementsLukas Fleischer2013-02-171-11/+10
| | | | | | | | | | From the Linux kernel coding guidelines: Do not unnecessarily use braces where a single statement will do. [...] This does not apply if one branch of a conditional statement is a single statement. Use braces in both branches. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Update copyright rangesLukas Fleischer2013-02-041-1/+1
| | | | | | | Add 2013 to the copyright range for all source and documentation files. Reported-by: Frederic Culot <frederic@culot.org> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* keys.c: Remove several unneeded assertionsLukas Fleischer2012-12-061-3/+3
| | | | | | Seen when compiling with clang and "-Wtautological-compare". Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* keys_save_bindings(): Skip unset key bindingsLukas Fleischer2012-12-051-2/+6
| | | | | | | Saving unset key bindings currently results in a segmentation fault or invalid key specifiers being stored. Skip these entries to avoid this. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add new default key binding for generic-pasteLukas Fleischer2012-07-071-1/+1
| | | | | | Use "p" as an additional (vim-style) default binding for generic-paste. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Merge cut/deleteLukas Fleischer2012-07-071-2/+0
| | | | | | | Remove the cut function and merge it into the del-item command. This allows for vim-style cutting/pasting. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add support for copy/paste registersLukas Fleischer2012-07-071-4/+20
| | | | | | | | | | | | | | | | | This adds support for vim-style copy/paste registers which allows cutting and copying multiple items without having to overwrite the copy/paste buffer. Registers can be specified using the quote key ('"'). To access a register, type '"x' before a command where "x" is the name of a register. If you want to copy the currently selected item into register 1, type '"1c'. Valid registers are 0-9, a-z, "-" and "_". Note that the latter is the so-called black hole register, which works similar to the black hole register in vim. The register prefix key is currently hardcoded and cannot be configured. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add a key binding for generic-copyLukas Fleischer2012-07-061-0/+2
| | | | | | This finally adds full copy-paste support. Implements FR#15. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Do not bind "c" to "generic-config-menu" by defaultLukas Fleischer2012-07-061-1/+1
| | | | | | | | The "c" key will be used for the generic-copy command in the future. The configuration menu isn't needed a lot, so binding it to "C" only seems legit. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* src/keys.c: Fix help strings for generic-{cut,paste}Lukas Fleischer2012-06-181-2/+2
| | | | | Reported-by: rafael ff1 <rafael.f.f1@gmail.com> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* src/keys.c: Add vim-style default bindings for generic-*Lukas Fleischer2012-06-131-4/+4
| | | | | | | | | | Add vim-style key bindings for generic-prev-day, generic-next-day, generic-prev-week and generic-next-week in a fashion similar to what we use for generic-*-month and generic-*-year. The key "t"/"T" for generic-prev-day/generic-next-day is somewhat less than perfect but this is okay given that we're running out of keys... Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add key bindings to go to the previous/next month/yearLukas Fleischer2012-06-131-0/+17
| | | | | | | | | | In addition to generic key bindings for moving one day (week) forward/backward, define similar bindings for moving a month or a year. Of course, count prefixes are allowed here as well. Also add status bar hints and help texts. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Rename displacement enumeration elementsLukas Fleischer2012-06-131-7/+7
| | | | | | | | | | * Rename "LEFT" to "DAY_PREV", "RIGHT" to "DAY_NEXT", "UP" to "WEEK_PREV" and "DOWN" to "WEEK_NEXT" to reflect the semantics of these operations. Remove the unneeded "MOVES" element. * Reorder code to improve consistency. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use mvwaddstr() instead of mvwprintw()Baptiste Jonglez2012-05-311-2/+2
| | | | | | | | | | | | | When we only want to display a string at a specific place of the screen, there's no need to use the more complex mvwprintw(), use mvwaddstr() instead. This should be slightly more efficient, and, above all, it prevents weird things to happen if our string contains a '%', being interpreted as an unwanted format string. Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Switch to Linux kernel coding styleLukas Fleischer2012-05-211-340/+273
| | | | | | | | | | | | | | Convert our code base to adhere to Linux kernel coding style using Lindent, with the following exceptions: * Use spaces, instead of tabs, for indentation. * Use 2-character indentations (instead of 8 characters). Rationale: We currently have too much levels of indentation. Using 8-character tabs would make huge code parts unreadable. These need to be cleaned up before we can switch to 8 characters. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add dummy help for cut and pasteBaptiste Jonglez2012-05-141-0/+4
| | | | | | | | It looks like cutting and pasting are only half-implemented: this only avoids a segfault when trying to get help on these functions. Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Declare several parameters/variables constantLukas Fleischer2012-05-081-8/+8
| | | | | | | | | | | | Add the "const" keyword to parameters and variables that are never modified. Most of these were spotted by "-Wwrite-strings". We cast the second parameter to execvp() explicitly as it expects a "char *const[]" where it should expect a "const char *const[]" (according to the documentation, this is due to compatibility reasons). This should be changed once we come up with a better solution. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* src/keys.c: Use generic list implementationLukas Fleischer2012-04-051-77/+36
| | | | | | | | Be consistent and replace the custom linked list implementation we used here by the generic list implementation we use everywhere else. This reduces code complexity, while slightly improving memory overhead. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Mark localized string literals constantLukas Fleischer2012-04-051-1/+1
| | | | | | | Translated strings returned by gettext() are statically allocated and shouldn't be modified. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Revert a bunch of strncmp() conversionsLukas Fleischer2012-03-301-1/+1
| | | | | | | | | | | All strncmp() usages were replaced by (evidently) equivalent strcmp() invocations in commit 2c9499bf272e06a62902711c6c20621ef3f80e64. However, some of the strncmp() calls were perfectly justified and we actually broke iCal import and "C-"-style key bindings by converting them to strcmp(). Fix this by reverting all affected conversions. Reported-by: Baptiste Jonglez <baptiste@jonglez.org> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Update copyright rangesLukas Fleischer2012-03-261-1/+1
| | | | | | Add 2012 to the copyright range for all source and documentation files. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>