aboutsummaryrefslogtreecommitdiff
path: root/Sources/NorgKit/Models/TaskStatus.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Sources/NorgKit/Models/TaskStatus.swift')
-rw-r--r--Sources/NorgKit/Models/TaskStatus.swift33
1 files changed, 33 insertions, 0 deletions
diff --git a/Sources/NorgKit/Models/TaskStatus.swift b/Sources/NorgKit/Models/TaskStatus.swift
new file mode 100644
index 0000000..74badf3
--- /dev/null
+++ b/Sources/NorgKit/Models/TaskStatus.swift
@@ -0,0 +1,33 @@
+/// A Norg TODO status.
+public enum TaskStatus: String, CaseIterable, Identifiable, Sendable, Hashable, Codable {
+ case undone = " "
+ case done = "x"
+ case needsInput = "?"
+ case urgent = "!"
+ case recurring = "+"
+ case pending = "-"
+ case onHold = "="
+ case cancelled = "_"
+
+ /// Identifier, corresponds to its character.
+ public var id: String { rawValue }
+
+ /// Creates a TaskStatus based on a UTF-8 character.
+ public init?(marker: Character) {
+ self.init(rawValue: String(marker))
+ }
+
+ init?(markerByte byte: UInt8) {
+ switch byte {
+ case UInt8(ascii: " "): self = .undone
+ case UInt8(ascii: "x"): self = .done
+ case UInt8(ascii: "?"): self = .needsInput
+ case UInt8(ascii: "!"): self = .urgent
+ case UInt8(ascii: "+"): self = .recurring
+ case UInt8(ascii: "-"): self = .pending
+ case UInt8(ascii: "="): self = .onHold
+ case UInt8(ascii: "_"): self = .cancelled
+ default: return nil
+ }
+ }
+}