Skip to content

Commit

Permalink
Show collection id in prompt (#15)
Browse files Browse the repository at this point in the history
* show collection id in prompt

* Update changelog

* upgrade set

* add deps spago is mad about in ci 🤔

* name the project

* fix syntax

* fix some weird missing character 🤔🤔
  • Loading branch information
jisantuc authored Apr 14, 2021
1 parent 90e3440 commit d1a3b5d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Prompt in collection context now includes the collection id [#15](https://github.com/jisantuc/stac-repl/pull/15) (@jisantuc)

## [0.1.1] - 2021-03-22
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion packages.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ in upstream
-------------------------------
-}
let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.14.0-20210318/packages.dhall sha256:98bbacd65191cef354ecbafa1610be13e183ee130491ab9c0ef6e3d606f781b5
https://github.com/purescript/package-sets/releases/download/psc-0.14.0-20210409/packages.dhall sha256:e81c2f2ce790c0e0d79869d22f7a37d16caeb5bd81cfda71d46c58f6199fd33f

in upstream
with stac =
Expand Down
19 changes: 16 additions & 3 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,31 @@
Welcome to a Spago project!
You can edit this file as you like.
-}
{ name = "my-project"
{ name = "stac-repl"
, dependencies =
[ "aff-promise"
, "aff"
, "affjax"
, "ansi"
, "arrays"
, "console"
, "control"
, "effect"
, "monad-control"
, "node-process"
, "either"
, "foldable-traversable"
, "foreign-object"
, "lists"
, "maybe"
, "node-readline"
, "ordered-collections"
, "parsing"
, "prelude"
, "psci-support"
, "refs"
, "stac"
, "strings"
, "tuples"
, "unicode"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
Expand Down
44 changes: 31 additions & 13 deletions src/Repl.purs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ import Types (Cmd(..), Context(..))
greenPrompt :: String -> String
greenPrompt = withGraphics (foreground Green)

rootPrompt :: String
rootPrompt = greenPrompt $ "stac > "

urlPrompt :: String -> String
urlPrompt s = greenPrompt $ "stac " <> s <> " > "

collectionPrompt :: String -> String -> String
collectionPrompt collectionId s = greenPrompt $ "stac " <> s <> " " <> collectionId <> " > "

updateKnownCollections ::
forall m.
MonadEffect m =>
Expand Down Expand Up @@ -112,6 +121,9 @@ execute interface ctxRef cmd = case cmd of
}
)
ctxRef
let
newPrompt = collectionPrompt (toString s) url
setPrompt newPrompt interface
RootContext { rootUrl: Nothing } -> log $ "Can't choose a collection without a root url"
CollectionContext { rootUrl, knownCollections } -> do
log $ "Set context to collection " <> toString s
Expand All @@ -126,6 +138,9 @@ execute interface ctxRef cmd = case cmd of
}
)
ctxRef
let
newPrompt = collectionPrompt (toString s) rootUrl
setPrompt newPrompt interface
prompt interface
ViewCollection s -> do
ctx <- read ctxRef
Expand All @@ -142,17 +157,20 @@ execute interface ctxRef cmd = case cmd of
<> printError err
liftEffect $ prompt interface
UnsetCollection -> do
modify_
( case _ of
RootContext rec -> RootContext rec
CollectionContext { rootUrl, knownCollections } ->
RootContext
{ rootUrl: Just rootUrl, knownCollections
}
)
ctxRef
log "Returning to root context"
prompt interface
ctx <- read ctxRef
validFor toRootUrl ctx \root -> do
modify_
( case _ of
RootContext rec -> RootContext rec
CollectionContext { rootUrl, knownCollections } ->
RootContext
{ rootUrl: Just rootUrl, knownCollections
}
)
ctxRef
log "Returning to root context"
setPrompt (urlPrompt root) interface
prompt interface
SetRootUrl s -> do
modify_
( case _ of
Expand All @@ -161,7 +179,7 @@ execute interface ctxRef cmd = case cmd of
)
ctxRef
let
newPrompt = greenPrompt $ "stac " <> s <> " > "
newPrompt = urlPrompt s
setPrompt newPrompt interface
prompt interface
LocateCollection -> do
Expand Down Expand Up @@ -287,6 +305,6 @@ replProgram :: Effect Interface
replProgram = do
ctxRef <- new $ RootContext { rootUrl: Nothing, knownCollections: mempty }
interface <- createConsoleInterface $ getCompletions ctxRef
setPrompt (greenPrompt "stac > ") interface
setPrompt rootPrompt interface
setLineHandler (lineHandler ctxRef interface) interface
pure $ interface

0 comments on commit d1a3b5d

Please sign in to comment.