1215 Commits

Author SHA1 Message Date
Lukas Fleischer
1418e40793 Use dummy variables to ignore return values of pair_content()
This prevents from segmentation faults with recent ncurses
implementations. See commit 5722d2e (Fix segmentation fault when
changing colors, 2017-07-28) for details.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-10 14:05:43 +02:00
Quentin Hibon
01142891a7 ical: use the VALUE parameter in DTSTART
According to RFC5545 3.3 (Property Value Data Types):

"If the value type of a property is one of the alternate valid types, then it
MUST be explicitly specified with the "VALUE" parameter."

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-10 14:03:29 +02:00
Lukas Fleischer
b82a3b9276 Allow for passing negative arguments to -d
When specifying date ranges using -d, allow for passing negative values
to indicate that the date range should start a certain number of days
ago.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-12-13 09:06:32 +01:00
Lars Henriksen
f8e6e0d691 Fix no-colour theme
In colour customization, pressing cancel ('ESC' by default) will
deselect all colours and put calcurse in no-color mode. For this
to work, all colour changes must be performed with the routines
custom_apply_attr()/custom_remove_attr(). Fixed for the getstring
cursor, the scroll window border and the week number.

In addition, the week number is unconditionally coloured as the
rest of the calendar contents whether CAL is selected or not.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-12-10 14:33:31 +01:00
Lars Henriksen
9e060b96c2 Scrollbar and right window border
When a scrollbar is on display in APP or TOD windows, the right
vertical border (outside the scrollbar) is not highlighted
when the window is selected.

The scrollbar itself is always highlighted:
- when APP or TOD is deselected
- in configuration windows where borders otherwise are not

The patch moves the scrollbar parameters from arguments of
draw_scrollbar() to the function itself.

The highlight argument to draw_scrollbar() was always 1.
Instead call circumstances are figured out and highlight set
accordingly.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-12-10 14:33:31 +01:00
Lars Henriksen
e733d09ea0 Default colour as foreground colour
In the default colour setup (white on black), white could only
with great difficulty be used as customized foreground colour,
because the colour pair COLR_CUSTOM then was identical to
COLR_DEFAULT (default on default). This made it impossible to
distinguish the selected element in lists.

The patch turns on the video attribute bold when default is chosen
as foreground colour.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-12-10 14:33:31 +01:00
Lars Henriksen
95c5d576fa Update UTF-8 base code
UTF-8 encodes characters in one to four bytes (since 2003).

Because 0 is a valid code point, the decode function utf8_ord()
should return -1, not 0, on error. As a consequence utf8_width()
should return 0 for a continuation byte (as it did previously).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-12-07 09:02:58 +01:00
Lukas Fleischer
16e7aecd29 Do not prompt when non-interactive import fails
When running calcurse in non-interactive mode, we should not expect any
user input. This is even more important in the case of iCal imports
which are used by calcurse-caldav to import events from CalDAV servers.

Partly fixes GitHub issue #73.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-23 08:57:45 +01:00
Lars Henriksen
691d6b33ee Check for the year span 1902-2037
Reintroduce year check for systems with a 32-bit time_t type. Remove the
lower limit (1902) for systems with a 64-bit time_t. This limits
movements in the calendar (for 32-bit systems) and in no way ensures
constistency of data.

Commit a12833e (Handle dates past January 19th, 2038, 2015-01-19)
removed the upper limit (2037) on dates but left the lower limit (1902).
It did not ensure the support of the target system.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-23 08:56:38 +01:00
Lars Henriksen
97c3e7f957 Function cleanup in custom.c
Remove two remnants: custom_color_theme_name() and custom_set_swsiz().
Make static and rename custom_confwin_init() into confwin_init().

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-23 08:56:06 +01:00
Lars Henriksen
aca4e06c5f Fix help for nine actions
Seven actions were absent from display_help(). This meant that
commands like ':help ^P' did not work. They now refer to
general.txt, but are not all described there.

For two actions, generic-copy/paste, the file name was misspelled.

This solves Github issue #44.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-15 06:35:17 +01:00
Lars Henriksen
9443de4783 Remove unused argument from wins_other_status_page
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-03 21:41:28 +01:00
Lars Henriksen
aee9099a44 Detect error on character input
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>
2017-10-29 08:42:03 +01:00
Lars Henriksen
012a0e6670 Fix multiple popup windows
The window was not deleted if an "already in use"-key was detected,
and a new one was created as the loop was reentered.

Create/delete of the popup are moved outside the loop.
A redrawwin() call is needed to have the window displayed again.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-29 08:42:03 +01:00
Lukas Fleischer
e9bddf38e8 Parse time before date in parse_datetime()
Make sure that in cases when the date and time formats conflict, such as
is the case with "0030", the input is interpreted as a time value, not a
date.

Suggested-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-27 08:40:10 +02:00
Lukas Fleischer
301f240881 Make parsing of date-time more strict
In parse_datetime() it was possible to enter any number of dates and
times in any order. Allow just date or time or date followed by time.

Time must be looked for before date because of conflicting time and date
formats.

Suggested-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-26 20:49:30 +02:00
Lukas Fleischer
760c297027 Add parse_date_interactive()
Add a wrapper around parse_date() which picks the current input date
format as well as the currently selected day and passes both values to
parse_date(), alongside with the parameters passed to
parse_date_interactive() itself.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-26 20:49:30 +02:00
Lars Henriksen
2b8d4e983f Remove recognized keys check
All keys known by ncurses can be bound. Thus the check for not
recognized keys in custom_keys_config() becomes superfluous.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-26 08:35:18 +02:00
Lars Henriksen
c0644d5aaf Fix spelling of "frequency"
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-23 21:18:07 +02:00
Lars Henriksen
61e577bf8a Support key bindings for all escape keys
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>
2017-10-23 08:40:25 +02:00
Lars Henriksen
dd5af2f7f4 Updates for UTF-8 key bindings
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>
2017-10-23 08:39:11 +02:00
nobody
164d6efcb7 Make delete key act as delete instead of backspace
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-19 06:11:59 +02:00
Quentin Hibon
debf0f84e0 Add CTRL-G readline shortcut to getstring()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-19 06:11:14 +02:00
Lars Henriksen
eeb7038c13 Do not tie ISO 8601 week numbering to Monday
The week number in the calendar panel is calculated according to
ISO 8601. Hence, Monday is the first day of the week and the
week number changes from Sunday to Monday.

However, calcurse ties the week number not to Monday, but to the
first day of the week as configured for display. Thus, when Sunday
is shown as first day of the week, the week number is correct for
Sunday, but wrong for the rest of the week (one behind).

With this patch the week number always follows the mon-sun week as
required by ISO 8601. A side effect is that when Sunday is displayed
as first day of the week, and Sunday is the selected day, the week
number displayed is invalid for the rest of the week (but changes
to the correct one when the selected day moves forward).

This raises the question whether the week numbering scheme should
follow the "first day of the week" choice and use the American week
numbering scheme instead of ISO 8601 when Sunday is the first day
of the week. But that is for the future.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-17 08:42:40 +02:00
Lukas Fleischer
2fe9c7efce Reload data after resolving save conflict
After resolving a save conflict with the merge tool, we need to reload
the data files to import the result of the conflict resolution.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:23:25 +02:00
Lukas Fleischer
e943a8a4db Unset modification flag after merging
Turn off the local modification flag to avoid a bogus warning when
reloading the data files immediately after the merge process.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:22:22 +02:00
Lukas Fleischer
f69698569f Recompute hashes after saving
After saving the data files, we need to recompute and store the hashes
to make sure the updated contents is reflected.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:21:45 +02:00
Lukas Fleischer
380124c7a2 Factor out hash computation
Move code to compute the hash of a data file to a separate function.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:21:11 +02:00
Lukas Fleischer
7a0134204e Use a shared input/output mutex
Replace the save mutex with a common mutex, which is locked whenever
read or write operations on the data files are performed. Also, since
this mutex is an implementation detail, mark the locking functions
static and remove them from the header file.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:08:54 +02:00
Lukas Fleischer
0f3d1988bf Interrupt periodic save when launching process
To avoid interactions between the periodic save thread and external
processes, stop the periodic save thread before launching an external
program and restart the thread as soon as the program is terminated.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:08:54 +02:00
Lukas Fleischer
57dd3d6b66 Only reload if data files were changed
Instead of blindly reloading data in io_reload_data(), compare the
stored hashes of the data files with hashes of the current file contents
and only reload if any of the hashes differs.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:08:54 +02:00
Lukas Fleischer
ba85d9b6f5 Factor out check for external modifications
Move the check to compare the stored hashes of the data files with the
current hash to a separate function. This makes the code easier to read
and reusable.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:08:54 +02:00
Lukas Fleischer
9137590e7a Do not blindly overwrite files when saving
When reading the data files, compute a cryptographic hash of the file
contents and store it. When saving the files later, ensure that the hash
still matches the current file contents. If it does not, show a warning
to the user and ask whether she wants to execute the merge tool.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:08:53 +02:00
Lukas Fleischer
fb1524b4e2 Use .new as file extension when merging
Using the file name extension .sav and naming the variables "backup" is
slightly misleading, since the affected files actually contain the
updated content and not some old snapshot. Use the term "new" instead.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:08:53 +02:00
Lukas Fleischer
e5a824e576 Factor out merge routine
Move the code, which runs the merge tool with current and updated data
files, to a separate function to make it reusable.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:08:53 +02:00
Lukas Fleischer
74d90e7cbc Add CALCURSE_{EDITOR,PAGER,MERGETOOL} environment variables
Support environment variables specific to calcurse to override $EDITOR,
$PAGER and $MERGETOOL.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:08:53 +02:00
Lars Henriksen
d20f9a5d2e Make the day heading position configurable
The date at the top of the appointments list may be positioned either to
the left, in the middle or to the right. Default is to the right. Can be
configured from the general options menu.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:08:53 +02:00
Lars Henriksen
172efd7179 Remove phase of moon feature
The computation never really worked before and it seems like the feature
is not very helpful, sometimes even confusing (see GitHub issue #21).

The macro ISLEAP is moved to calcurse.h.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:08:53 +02:00
Lars Henriksen
90fe21af88 Fix phase of moon calculation
The reported phase was often one day early because calculations were
based on midnight. For full and new moon this is changed to noon. For
first and last quarter a direct check of the appearance of the half moon
during the selected day is performed.

Comments are relocated and expanded.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:08:53 +02:00
Lars Henriksen
3095bf4214 Add missing string initialization
When introducing the fmt_day_heading() function in commit d56cc7a (Make
heading in appointments panel configurable, 2017-08-19), we forgot to
initialize the dynamic string. This resulted in calling mem_free() with
a garbage pointer, potentially resulting in a segmentation fault. Fix
this by calling string_init() before using the string.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-04 16:34:19 +02:00
Lukas Fleischer
2e584f03e6 Replace remaining uses of wgetch() by keys_wgetch()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-03 16:37:35 +02:00
Lukas Fleischer
53f0f1d2e3 Add a function to wait for any key press
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>
2017-09-03 16:37:35 +02:00
Lukas Fleischer
8373ecfe51 Improve default selection when editing key bindings
When adding a new key binding, automatically select the new binding.
When removing a key binding, keep the selection index (unless the last
binding of a row is removed).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-03 15:51:01 +02:00
Lukas Fleischer
6521d8cc0a Use strncpy() properly in general_option_edit()
Always use strncpy() to copy strings between fixed-size buffers and pass
the buffer size as maximal length parameter.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-03 09:31:33 +02:00
Lukas Fleischer
578091f051 Add support for UTF-8 key bindings
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>
2017-08-30 16:39:23 +02:00
Lukas Fleischer
8544e4a570 Rename keys_getch() to keys_get()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-30 16:26:10 +02:00
Lukas Fleischer
273e32d43d Factor out UTF-8 code point decoding
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-30 16:17:28 +02:00
Lukas Fleischer
6cb26c2f27 Relocate HANDLE_KEY macros
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-30 16:15:39 +02:00
Quentin Hibon
04fb4caf8f Implement CTRL-U in getstring()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-29 20:14:39 +02:00
Lars Henriksen
26aeddd490 Use nl_langinfo() for month and day names
Use the locale setting to fetch the month names and abbreviated day
names.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-28 07:30:38 +02:00