···
389
+
let text_event_data ?tz event =
390
+
let id = get_id event in
391
+
let start = get_start event in
392
+
let end_ = get_end event in
393
+
let start_date = format_date ?tz start in
395
+
match is_date event with true -> "" | false -> " " ^ format_time ?tz start
397
+
let end_date, end_time =
401
+
match is_date event with
403
+
match next_day start ~next:end_ with
405
+
| false -> (" - " ^ format_date ?tz end_, ""))
407
+
match same_day start end_ with
408
+
| true -> ("", " - " ^ format_time ?tz end_)
409
+
| false -> (" - " ^ format_date ?tz end_, " " ^ format_time ?tz end_)
413
+
match get_summary event with
414
+
| Some summary when summary <> "" -> summary
418
+
match get_location event with
419
+
| Some loc when loc <> "" -> "@" ^ loc
422
+
let calendar_name = get_calendar_name event in
423
+
let date_time = start_date ^ start_time ^ end_date ^ end_time in
424
+
(id, calendar_name, date_time, summary, location)
let format_event ?(format = `Text) ?tz event =
let start = get_start event in
let end_ = get_end event in
394
-
let id = get_id event in
395
-
let start_date = " " ^ format_date ?tz start in
397
-
match is_date event with
399
-
| false -> " " ^ format_time ?tz start
431
+
let id, calendar_name, date_time, summary, location =
432
+
text_event_data ?tz event
401
-
let end_date, end_time =
405
-
match is_date event with
407
-
match next_day start ~next:end_ with
409
-
| false -> (" - " ^ format_date ?tz end_, ""))
411
-
match same_day start end_ with
412
-
| true -> ("", " - " ^ format_time ?tz end_)
414
-
(" - " ^ format_date ?tz end_, " " ^ format_time ?tz end_)))
417
-
match get_summary event with
418
-
| Some summary when summary <> "" -> " " ^ summary
422
-
match get_location event with
423
-
| Some loc when loc <> "" -> " @" ^ loc
426
-
let calendar_name = get_calendar_name event in
427
-
Printf.sprintf "%-45s\t%s\t%s%s%s%s%s%s" id calendar_name start_date
428
-
start_time end_date end_time summary location
434
+
Printf.sprintf "%s\t%s\t%s\t%s\t%s" id calendar_name date_time summary
let format_opt label f opt =
Option.map (fun x -> Printf.sprintf "%s: %s\n" label (f x)) opt
···
(String.escaped id) (String.escaped summary) start_date start_time
end_str location description calendar
583
+
let format_events_with_dynamic_columns ?tz events =
584
+
if events = [] then ""
586
+
let event_data = List.map (text_event_data ?tz) events in
587
+
(* Calculate max width for each column *)
590
+
(fun acc (id, _, _, _, _) -> max acc (String.length id))
593
+
let max_cal_width =
595
+
(fun acc (_, cal, _, _, _) -> max acc (String.length cal))
598
+
let max_date_width =
600
+
(fun acc (_, _, date, _, _) -> max acc (String.length date))
604
+
(* Format each event with calculated widths *)
605
+
let formatted_events =
607
+
(fun (id, cal, date, summary, location) ->
608
+
Printf.sprintf "%-*s %-*s %-*s %s%s" max_id_width id max_cal_width
609
+
cal max_date_width date summary
610
+
(if location <> "" then " " ^ location else ""))
613
+
String.concat "\n" formatted_events
let format_events ?(format = `Text) ?tz events =
···
(List.map (fun e -> format_event ~format:`Sexp ?tz e) events)
632
+
| `Text -> format_events_with_dynamic_columns ?tz events
String.concat "\n" (List.map (fun e -> format_event ~format ?tz e) events)