feat: STATUS support
This commit is contained in:
@@ -10,37 +10,54 @@
|
||||
|
||||
# Functions
|
||||
|
||||
# Set event color based on status
|
||||
|
||||
# @input status: Event status, one of TENTATIVE, CONFIRMED, CANCELLED
|
||||
# @return: Color modifier
|
||||
function color_from_status(status) {
|
||||
return status == "CANCELLED" ? STRIKE CYAN : status == "TENTATIVE" ? FAINT CYAN : CYAN
|
||||
}
|
||||
|
||||
# Return line for all-day event.
|
||||
#
|
||||
# @local variables: color
|
||||
# @input collection: Collection symbol
|
||||
# @input desc: Event description
|
||||
# @input status: Event status, one of TENTATIVE, CONFIRMED, CANCELLED
|
||||
# @return: Single-line string
|
||||
function allday(collection, desc) {
|
||||
return collection " " LIGHT_CYAN ITALIC FAINT " (allday) " OFF CYAN desc OFF
|
||||
function allday(collection, desc, status, color) {
|
||||
color = color_from_status(status)
|
||||
return collection " " LIGHT_CYAN ITALIC FAINT " (allday) " OFF color desc OFF
|
||||
}
|
||||
|
||||
# Return line for multi-day event, or event that starts at midnight, which ends today.
|
||||
#
|
||||
# @local variables: color
|
||||
# @input stop: Time at which the event ends
|
||||
# @input collection: Collection symbol
|
||||
# @input desc: Event description
|
||||
# @input status: Event status, one of TENTATIVE, CONFIRMED, CANCELLED
|
||||
# @return: Single-line string
|
||||
function endstoday(stop, collection, desc) {
|
||||
return collection " " LIGHT_CYAN " -- " stop OFF ": " CYAN desc OFF
|
||||
function endstoday(stop, collection, desc, status) {
|
||||
color = color_from_status(status)
|
||||
return collection " " LIGHT_CYAN " -- " stop OFF ": " color desc OFF
|
||||
}
|
||||
|
||||
# Return line for event that starts sometime today.
|
||||
#
|
||||
# @local variables: color
|
||||
# @input start: Time at which the event starts
|
||||
# @input stop: Time at which the event ends
|
||||
# @input collection: Collection symbol
|
||||
# @input desc: Event description
|
||||
# @input status: Event status, one of TENTATIVE, CONFIRMED, CANCELLED
|
||||
# @return: Single-line string
|
||||
function slice(start, stop, collection, desc) {
|
||||
function slice(start, stop, collection, desc, status) {
|
||||
color = color_from_status(status)
|
||||
if (stop == "00:00")
|
||||
return collection " " LIGHT_CYAN start " -- " OFF ": " CYAN desc OFF
|
||||
return collection " " LIGHT_CYAN start " -- " OFF ": " color desc OFF
|
||||
else
|
||||
return collection " " LIGHT_CYAN start OFF " -- " LIGHT_CYAN stop OFF ": " CYAN desc OFF
|
||||
return collection " " LIGHT_CYAN start OFF " -- " LIGHT_CYAN stop OFF ": " color desc OFF
|
||||
}
|
||||
|
||||
# Print line for a single hour entry.
|
||||
@@ -79,13 +96,14 @@ BEGIN {
|
||||
CYAN = "\033[1;36m"
|
||||
ITALIC = "\033[3m"
|
||||
FAINT = "\033[2m"
|
||||
STRIKE = "\033[9m"
|
||||
OFF = "\033[m"
|
||||
OFS = "|"
|
||||
}
|
||||
$1 == "00:00" && $2 == "00:00" { print today, $1, $3, $4, $5, allday($6, $7); next }
|
||||
$1 == "00:00" { print today, $1, $3, $4, $5, endstoday($2, $6, $7); next }
|
||||
$1 == "00:00" && $2 == "00:00" { print today, $1, $3, $4, $5, allday($6, $7, $8); next }
|
||||
$1 == "00:00" { print today, $1, $3, $4, $5, endstoday($2, $6, $7, $8); next }
|
||||
$1 ~ /^[0-9]{2}:[0-9]{2}$/ {
|
||||
daystart = hrlines($1, $2, daystart)
|
||||
print today, $1, $3, $4, $5, slice($1, $2, $6, $7)
|
||||
print today, $1, $3, $4, $5, slice($1, $2, $6, $7, $8)
|
||||
}
|
||||
END { hrlines(dayend":00", 0, daystart) }
|
||||
|
@@ -129,7 +129,7 @@ END {
|
||||
print "CREATED:" zulu
|
||||
print "SEQUENCE:1"
|
||||
print "LAST-MODIFIED:" zulu
|
||||
print "STATUS:VEVENT"
|
||||
print "STATUS:CONFIRMED"
|
||||
print "DTSTART;VALUE=" from_type ":" from
|
||||
print "DTEND;VALUE=" to_type ":" to
|
||||
if (summary) print_fold("SUMMARY:", summary)
|
||||
|
@@ -1,7 +1,7 @@
|
||||
## src/awk/parse.awk
|
||||
## Parse iCalendar file and print its key aspects:
|
||||
## ```
|
||||
## <start> <end> <fpath> <collection> <summary>
|
||||
## <start> <end> <fpath> <collection> <status> <summary>
|
||||
## ```.
|
||||
##
|
||||
## @assign collection_labels: See configuration of the current program.
|
||||
@@ -72,7 +72,8 @@ function print_data(start, dur, end, summary, cmd, collection, depth, path) {
|
||||
cmd = "date -d '" end "' +\"%s\""
|
||||
cmd | getline end
|
||||
close(cmd)
|
||||
print start, end, fpath, collection, summary
|
||||
status = status ? status : "CONFIRMED"
|
||||
print start, end, fpath, collection, status, summary
|
||||
}
|
||||
|
||||
# AWK program
|
||||
@@ -89,6 +90,7 @@ BEGIN {
|
||||
/^DTSTART/ && inside { start = parse() }
|
||||
/^DTEND/ && inside { end = parse() }
|
||||
/^DURATION/ && inside { end = parse_duration($NF); dur = 1 }
|
||||
/^STATUS/ && inside { status = $NF }
|
||||
/^[^ ]/ && rs { rs = 0 }
|
||||
/^ / && rs { summary = summary substr($0, 2) }
|
||||
/^SUMMARY/ && inside { rs = 1; summary = $0 }
|
||||
|
@@ -22,12 +22,21 @@ function escape(str)
|
||||
|
||||
# AWK program
|
||||
|
||||
BEGIN { FS = "[:;]" }
|
||||
BEGIN { FS = "[:;]"; zulu = strftime("%Y%m%dT%H%M%SZ", systime(), 1) }
|
||||
/^BEGIN:VEVENT$/ { inside = 1 }
|
||||
/^END:VEVENT$/ { inside = 0; if (!duplic) print field ":" escape(value) }
|
||||
/^END:VEVENT$/ {
|
||||
inside = 0
|
||||
if (!duplic)
|
||||
print field ":" escape(value)
|
||||
seq = seq ? seq + 1 : 1
|
||||
print "SEQUENCE:" seq
|
||||
print "LAST-MODIFIED:" zulu
|
||||
}
|
||||
$1 == field && inside { con = 1; duplic = 1; print field ":" escape(value); next }
|
||||
$1 == field && duplic { con = 1; next }
|
||||
/^ / && con { next }
|
||||
/^ / && con { next }
|
||||
/^[^ ]/ && con { con = 0 }
|
||||
/^SEQUENCE/ && inside { seq = $2; next } # store sequence number and skip
|
||||
/^LAST-MODIFIED/ && inside { next }
|
||||
{ print }
|
||||
|
Reference in New Issue
Block a user