-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from dirtyhenry/message-input
Support messages and journal of messages
- Loading branch information
Showing
30 changed files
with
1,509 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Foundation | ||
|
||
struct Environment { | ||
static let dotDirectoryName = ".pomodoro-cli" | ||
|
||
static let dotDirectory = FileManager.default | ||
.homeDirectoryForCurrentUser | ||
.appendingPathComponent(dotDirectoryName) | ||
|
||
static let hooksOn = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Foundation | ||
|
||
struct LogWriter { | ||
static let journalFile = "journal.yml" | ||
|
||
func writeLog(pomodoroDescription: PomodoroDescription) { | ||
do { | ||
let journalFileHandle = try FileHandle(forWritingTo: Environment.dotDirectory.appendingPathComponent(LogWriter.journalFile)) | ||
|
||
journalFileHandle.seekToEndOfFile() | ||
journalFileHandle.write(string: pomodoroDescription.description) | ||
journalFileHandle.closeFile() | ||
} catch { | ||
print("An error happened: \(error)") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Foundation | ||
|
||
/// A data struct encapsulating a full description of a Pomodoro. | ||
public struct PomodoroDescription { | ||
static let dateFormatter: DateFormatter = { | ||
let result = DateFormatter() | ||
result.dateStyle = .short | ||
result.timeStyle = .medium | ||
return result | ||
}() | ||
|
||
// MARK: - Creating a pomodoro | ||
|
||
/// Creates a new pomodoro. | ||
/// - Parameters: | ||
/// - duration: the duration of the pomodoro. | ||
/// - message: a message describing the intent of the pomodoro. | ||
public init(duration: TimeInterval, message: String?) { | ||
startDate = Date() | ||
self.duration = duration | ||
self.message = message | ||
} | ||
|
||
let startDate: Date | ||
let duration: TimeInterval | ||
let message: String? | ||
|
||
var endDate: Date { | ||
return startDate.addingTimeInterval(duration) | ||
} | ||
|
||
var formattedStartDate: String { | ||
return PomodoroDescription.dateFormatter.string(from: startDate) | ||
} | ||
|
||
var formattedEndDate: String { | ||
return PomodoroDescription.dateFormatter.string(from: endDate) | ||
} | ||
} | ||
|
||
extension PomodoroDescription: CustomStringConvertible { | ||
/// The description of the Pomodoro, as logged in the journal. | ||
public var description: String { | ||
let lines = [ | ||
"-", | ||
" - startDate: \(formattedStartDate)", | ||
" - endDate: \(formattedEndDate)", | ||
" - message: \(message ?? "n/a")", | ||
] | ||
return lines.joined(separator: "\n").appending("\n") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.