Skip to content

Commit

Permalink
Update prompts
Browse files Browse the repository at this point in the history
This cleans up the user experience of the CLI by providing a prompt
question to clarify what command was run, indenting the user prompts,
and spacing out the different components with new lines.
  • Loading branch information
mmwtsn committed Mar 13, 2016
1 parent 4e79a83 commit f7f1f7f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
21 changes: 15 additions & 6 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,37 @@ import FileSystem
import Prompt
import ReadWrite

-- Boilerplate messages for prompting user for input
pastMessage, futureMessage :: String
pastMessage = "What did you do since last standup?\n"
futureMessage = "What will you do until the next standup?\n"

-- Create a new instance of Standup from user input with a default done Task
new :: IO ()
new = promptCategory >>= \c ->
new = putStrLn pastMessage >>
promptCategory >>= \c ->
promptAction >>= \a ->
stashPath >>= \path ->
writeStandup path $ Standup [Task c a] [Task "life" "write Haskell!"]

-- Prompt user for Task and append it to the current standup's "done" Task
addDone :: IO ()
addDone = updateStandup stashPath appendDone
addDone = updateStandup pastMessage stashPath appendDone

-- Prompt user for Task and append it to the current standup's "todo" Task
addTodo :: IO ()
addTodo = updateStandup stashPath appendTodo
addTodo = updateStandup futureMessage stashPath appendTodo

-- Remove the default "todo" Task and archive the in-progress standup
standup :: IO ()
standup = updateStandup archivePath replaceDefaultTodo
standup = updateStandup futureMessage archivePath replaceDefaultTodo

-- Prompt user for a Task and attempt to update the in-progress Standup with it
updateStandup :: IO FilePath -> (String -> String -> Standup -> Standup) -> IO ()
updateStandup filePath update = promptCategory >>= \c ->
updateStandup :: String -> IO FilePath
-> (String -> String -> Standup -> Standup)
-> IO ()
updateStandup header filePath update = putStrLn header >>
promptCategory >>= \c ->
promptAction >>= \a ->
filePath >>= \path ->
eitherRead c a path update
Expand Down
4 changes: 2 additions & 2 deletions src/Prompt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ promptBase = getTask promptColor

-- Prompt user for a task category
promptCategory :: IO String
promptCategory = promptBase "Category? "
promptCategory = promptBase " category: "

-- Prompt user for a task action
promptAction :: IO String
promptAction = promptBase "Task? "
promptAction = promptBase " task: "
2 changes: 1 addition & 1 deletion src/ReadWrite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ encodeWithNewLine standup = appendNewLine $ encodePretty' config standup
-- Write a JSON-encoded Standup to disk, overwriting the existing file
writeStandup :: FilePath -> Standup -> IO ()
writeStandup path standup = (BS.writeFile path $ encodeWithNewLine standup)
>> putStr "Updated: \""
>> putStr "\nUpdated: \""
>> putStr path
>> putStrLn "\""

Expand Down

0 comments on commit f7f1f7f

Please sign in to comment.