Skip to content

Commit

Permalink
Merge pull request #4304 from sixfourtwelve/ucm-welcome-hint
Browse files Browse the repository at this point in the history
Add logic to flip welcome hint message
  • Loading branch information
aryairani authored Sep 7, 2023
2 parents a8e45bb + 2c1ab8b commit 3565bfa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
7 changes: 7 additions & 0 deletions codebase2/codebase-sqlite/U/Codebase/Sqlite/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ module U.Codebase.Sqlite.Queries

-- * projects
projectExists,
doProjectsExist,
projectExistsByName,
loadProject,
loadProjectByName,
Expand Down Expand Up @@ -3224,6 +3225,12 @@ projectExists projectId =
)
|]

-- | Check if any projects exist
doProjectsExist :: Transaction Bool
doProjectsExist =
queryOneCol
[sql| SELECT EXISTS (SELECT 1 FROM project) |]

-- | Does a project exist by this name?
projectExistsByName :: ProjectName -> Transaction Bool
projectExistsByName name =
Expand Down
24 changes: 14 additions & 10 deletions unison-cli/src/Unison/CommandLine/Welcome.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import Prelude hiding (readFile, writeFile)

data Welcome = Welcome
{ onboarding :: Onboarding, -- Onboarding States
unisonVersion :: Text
unisonVersion :: Text,
showWelcomeHint :: Bool
}

-- Previously Created is different from Previously Onboarded because a user can
Expand All @@ -34,12 +35,12 @@ data Onboarding
| PreviouslyOnboarded
deriving (Show, Eq)

welcome :: CodebaseInitStatus -> Text -> Welcome
welcome initStatus unisonVersion =
Welcome (Init initStatus) unisonVersion
welcome :: CodebaseInitStatus -> Text -> Bool -> Welcome
welcome initStatus unisonVersion showWelcomeHint =
Welcome (Init initStatus) unisonVersion showWelcomeHint

run :: Welcome -> [Either Event Input]
run Welcome {onboarding = onboarding, unisonVersion = version} = do
run Welcome {onboarding = onboarding, unisonVersion = version, showWelcomeHint = showWelcomeHint} = do
go onboarding []
where
go :: Onboarding -> [Either Event Input] -> [Either Event Input]
Expand All @@ -58,8 +59,8 @@ run Welcome {onboarding = onboarding, unisonVersion = version} = do
where
authorMsg = toInput authorSuggestion
-- These are our two terminal Welcome conditions, at the end we reverse the order of the desired input commands otherwise they come out backwards
Finished -> reverse (toInput getStarted : acc)
PreviouslyOnboarded -> reverse (toInput getStarted : acc)
Finished -> reverse (toInput (getStarted showWelcomeHint) : acc)
PreviouslyOnboarded -> reverse (toInput (getStarted showWelcomeHint) : acc)

toInput :: P.Pretty P.ColorText -> Either Event Input
toInput pretty =
Expand Down Expand Up @@ -110,9 +111,12 @@ authorSuggestion =
P.wrap $ P.blue "https://www.unison-lang.org/learn/tooling/configuration/"
]

getStarted :: P.Pretty P.ColorText
getStarted =
getStarted :: Bool -> P.Pretty P.ColorText
getStarted showWelcomeHint =
P.wrap "📚 Read the official docs at https://www.unison-lang.org/learn/"
<> P.newline
<> P.newline
<> P.wrap "Type 'project.create' to get started."
<> P.wrap (if showWelcomeHint
then "Hint: Type 'projects' to list all your projects, or 'project.create' to start something new."
else "Type 'project.create' to get started.")

6 changes: 3 additions & 3 deletions unison-cli/unison/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,13 @@ launch ::
(Path.Absolute -> STM ()) ->
CommandLine.ShouldWatchFiles ->
IO ()
launch dir config runtime sbRuntime codebase inputs serverBaseUrl mayStartingPath initResult notifyRootChange notifyPathChange shouldWatchFiles =
launch dir config runtime sbRuntime codebase inputs serverBaseUrl mayStartingPath initResult notifyRootChange notifyPathChange shouldWatchFiles = do
showWelcomeHint <- Codebase.runTransaction codebase Queries.doProjectsExist
let isNewCodebase = case initResult of
CreatedCodebase -> NewlyCreatedCodebase
OpenedCodebase -> PreviouslyCreatedCodebase

(ucmVersion, _date) = Version.gitDescribe
welcome = Welcome.welcome isNewCodebase ucmVersion
welcome = Welcome.welcome isNewCodebase ucmVersion showWelcomeHint
in CommandLine.main
dir
welcome
Expand Down

0 comments on commit 3565bfa

Please sign in to comment.