Skip to content

Commit

Permalink
✨ Iconize
Browse files Browse the repository at this point in the history
  • Loading branch information
oschrenk committed Jan 25, 2025
1 parent a859889 commit 844ea23
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
7 changes: 5 additions & 2 deletions Sources/Cli/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ enum Main {
start: Date,
end: Date,
opts: SharedOptions,
eventSelector: EventSelectorI
selector: EventSelectorI,
transformer: EventTransformer
) {
Log.setDebug(opts.debug)

Expand Down Expand Up @@ -35,7 +36,9 @@ enum Main {
eventFilter: eventFilter
)

let events = eventSelector.select(events: unsortedEvents)
let events = selector
.select(events: unsortedEvents)
.map { transformer.transform(event: $0) }
if opts.templatePath.isEmpty {
events.printAsJson()
} else {
Expand Down
6 changes: 5 additions & 1 deletion Sources/Cli/Next.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ struct Next: ParsableCommand {
]
)

Main.run(start: start, end: end, opts: opts, eventSelector: eventSelector)
Main.run(
start: start, end: end, opts: opts,
selector: eventSelector,
transformer: EventTransformer(rules: Loader.readConfig()?.iconize ?? [])
)
}
}
6 changes: 5 additions & 1 deletion Sources/Cli/Today.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ struct Today: ParsableCommand {
]
)

Main.run(start: start, end: end, opts: opts, eventSelector: eventSelector)
Main.run(
start: start, end: end, opts: opts,
selector: eventSelector,
transformer: EventTransformer(rules: Loader.readConfig()?.iconize ?? [])
)
}
}
10 changes: 7 additions & 3 deletions Sources/Model/EventTransformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import Foundation
import swift_lens

class EventTransformer {
let rule: Rule
let rules: [Rule]

init(rule: Rule) {
self.rule = rule
rules = [rule]
}

init(rules: [Rule]) {
self.rules = rules
}

func transform(event: Event) -> Event {
if event.title.label.range(
for rule in rules where event.title.label.range(
of: rule.regex, options: .regularExpression
) != nil {
return event |> (Event.titleLens * Title.iconLens) *~ rule.icon
Expand Down

0 comments on commit 844ea23

Please sign in to comment.