File 0004-Fix-width-for-noweekend-option.patch of Package gcalcli
From 9c7518290dbf751ad8765b3b2c5415a8f6270a64 Mon Sep 17 00:00:00 2001
From: Mischa Salle <msalle@nikhef.nl>
Date: Wed, 29 Jan 2025 11:24:17 +0100
Subject: [PATCH 4/4] Fix width for noweekend option
day_width was calculated assuming 7 days a week. This is not correct when
noweekend is set. days was already calculated in _GraphEvents, so move it to
instance level and set it in __init__ and use it to calculate the correct width.
---
gcalcli/gcal.py | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/gcalcli/gcal.py b/gcalcli/gcal.py
index 671f2d7..a85ba51 100644
--- a/gcalcli/gcal.py
+++ b/gcalcli/gcal.py
@@ -72,9 +72,11 @@ class GoogleCalendarInterface:
self.details = options.get('details', {})
+ # Number of days to print in calw/calm
+ self.days = 7 if self.options.get('cal_weekend', True) else 5
# Store overall calendar width and width for day table cells
self.width['cal'] = int(options.get('width', 80))
- day_width = int(( self.width['cal'] - 8) / 7)
+ day_width = int(( self.width['cal'] - self.days - 1) / self.days)
# Minimal day table cell is 10
self.width['day'] = day_width if day_width > 9 else 10
@@ -462,16 +464,17 @@ class GoogleCalendarInterface:
event_list = event_list[1:]
day_width_line = self.width['day'] * self.printer.art['hrz']
- days = 7 if self.options['cal_weekend'] else 5
# Get the localized day names... January 1, 2001 was a Monday
- day_names = [date(2001, 1, i + 1).strftime('%A') for i in range(days)]
+ day_names = [date(2001, 1, i + 1).strftime('%A')
+ for i in range(self.days)]
if not self.options['cal_monday'] or not self.options['cal_weekend']:
day_names = day_names[6:] + day_names[:6]
def build_divider(left, center, right):
return (
self.printer.art[left] + day_width_line +
- ((days - 1) * (self.printer.art[center] + day_width_line)) +
+ ( (self.days - 1) * (self.printer.art[center] +
+ day_width_line) ) +
self.printer.art[right]
)
@@ -486,7 +489,7 @@ class GoogleCalendarInterface:
self.printer.msg(month_title_top + '\n', color_border)
month_title = start_datetime.strftime('%B %Y')
- month_width = (self.width['day'] * days) + (days - 1)
+ month_width = (self.width['day'] * self.days) + (self.days - 1)
month_title += ' ' * (month_width - self._printed_len(month_title))
self.printer.art_msg('vrt', color_border)
@@ -521,7 +524,7 @@ class GoogleCalendarInterface:
for i in range(count):
# create and print the date line for a week
- for j in range(days):
+ for j in range(self.days):
if cmd == 'calw':
d = (start_week_datetime +
timedelta(days=j)).strftime('%d %b')
@@ -561,7 +564,7 @@ class GoogleCalendarInterface:
# stop when everything has been printed
done = True
self.printer.art_msg('vrt', color_border)
- for j in range(days):
+ for j in range(self.days):
if not week_events[j]:
# no events today
self.printer.msg(
--
2.43.0