improvement: consistent use of delimiter

This commit is contained in:
2025-06-18 15:27:40 +02:00
parent 428b9de85c
commit 3b8c412885
9 changed files with 102 additions and 65 deletions

View File

@@ -1,5 +1,7 @@
## src/awk/weekview.awk
## Print view of all appointments of the current week.
## Generates view from
## printf "%s\t%s\t%s\t%s\n" "$i" "$s" "$e" "$description"
##
## @assign startofweek: Date of first day in the week
@@ -7,27 +9,29 @@
# Compose line that will display a day in the week.
#
# @input desc: String with a description of the event
# @return: Single-line string
function c() {
return CYAN substr($0, index($0, ">") + 1) OFF " " RED "/" OFF
function c(desc) {
return CYAN desc OFF " " RED "/" OFF
}
# AWK program
BEGIN {
FS = "\t"
OFS = "\t"
GREEN = "\033[1;32m"
RED = "\033[1;31m"
CYAN = "\033[1;36m"
OFF = "\033[m"
OFS = "|"
}
/^[0-7] 00:00 -- 00:00/ { dayline = dayline " " c(); next }
/^[0-7] 00:00 -- / { dayline = dayline " → " $4 " " c(); next }
/^[0-7] [0-9]{2}:[0-9]{2} -- 00:00/ { dayline = dayline " " $2 " → " c(); next }
/^[0-7] [0-9]{2}:[0-9]{2} -- [0-9]{2}:[0-9]{2}/ { dayline = dayline " " $2 " " $4 " " c(); next }
/^[0-7]$/ && dayline { print "+", startofweek " +" $0-1 " days", "", dayline }
/^[0-7]$/ {
cmd = "date -d '" startofweek " +" $0 " days' +\"%a %e %b %Y\""
$2 == "00:00" && $3 == "00:00" { dayline = dayline " " c($4); next }
$2 == "00:00" { dayline = dayline " → " $3 " " c($4); next }
$3 == "00:00" { dayline = dayline " " $2 " → " c($4); next }
NF == 4 { dayline = dayline " " $2 " " $3 " " c($4); next }
NF == 1 && dayline { print "+", startofweek " +" $1-1 " days", "", dayline }
NF == 1 {
cmd = "date -d '" startofweek " +" $1 " days' +\"%a %e %b %Y\""
cmd | getline dayline
close(cmd)
dayline = GREEN dayline ": " OFF