blob: 74badf31e295c5930fe74098d25dca446135b933 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
}
}
}
|