Skip to content

Commit

Permalink
Add Clear command (#3705)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner authored Jan 3, 2023
1 parent bf0186a commit e5d9662
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions unison-cli/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
- ListLike
- aeson
- aeson-pretty
- ansi-terminal
- async
- base
- bytes
Expand Down
2 changes: 2 additions & 0 deletions unison-cli/src/Unison/Codebase/Editor/HandleInput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,7 @@ loop e = do
Cli.LoadError -> Cli.returnEarly $ SourceLoadFailed path
Cli.LoadSuccess contents -> pure contents
loadUnisonFile (Text.pack path) contents
ClearI -> Cli.respond ClearScreen
AddI requestedNames -> do
description <- inputDescription input
let vars = Set.map Name.toVar requestedNames
Expand Down Expand Up @@ -1591,6 +1592,7 @@ inputDescription input =
ListDependentsI {} -> wat
ListEditsI {} -> wat
LoadI {} -> wat
ClearI {} -> pure "clear"
NamesI {} -> wat
NamespaceDependenciesI {} -> wat
PopBranchI {} -> wat
Expand Down
1 change: 1 addition & 0 deletions unison-cli/src/Unison/Codebase/Editor/Input.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ data Input
| ResolveTypeNameI Path.HQSplit'
| -- edits stuff:
LoadI (Maybe FilePath)
| ClearI
| AddI (Set Name)
| PreviewAddI (Set Name)
| UpdateI OptionalPatch (Set Name)
Expand Down
2 changes: 2 additions & 0 deletions unison-cli/src/Unison/Codebase/Editor/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ data Output
| IntegrityCheck IntegrityResult
| DisplayDebugNameDiff NameChanges
| DisplayDebugCompletions [Completion.Completion]
| ClearScreen

data DisplayDefinitionsOutput = DisplayDefinitionsOutput
{ isTest :: TermReference -> Bool,
Expand Down Expand Up @@ -437,6 +438,7 @@ isFailure o = case o of
ViewOnShare {} -> False
DisplayDebugCompletions {} -> False
DisplayDebugNameDiff {} -> False
ClearScreen -> False

isNumberedFailure :: NumberedOutput -> Bool
isNumberedFailure = \case
Expand Down
19 changes: 19 additions & 0 deletions unison-cli/src/Unison/CommandLine/InputPatterns.hs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@ load =
_ -> Left (I.help load)
)

clear :: InputPattern
clear =
InputPattern
"clear"
[]
I.Visible
[]
( P.wrapColumn2
[ ( makeExample' clear,
"Clears the screen."
)
]
)
( \case
[] -> pure $ Input.ClearI
_ -> Left (I.help clear)
)

add :: InputPattern
add =
InputPattern
Expand Down Expand Up @@ -2324,6 +2342,7 @@ validInputs =
[ help,
helpTopics,
load,
clear,
add,
previewAdd,
update,
Expand Down
5 changes: 5 additions & 0 deletions unison-cli/src/Unison/CommandLine/OutputMessages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import qualified Network.HTTP.Types as Http
import Network.URI (URI)
import qualified Network.URI.Encode as URI
import qualified Servant.Client as Servant
import qualified System.Console.ANSI as ANSI
import qualified System.Console.Haskeline.Completion as Completion
import System.Directory
( canonicalizePath,
Expand Down Expand Up @@ -1847,6 +1848,10 @@ notifyUser dir o = case o of
else ""
in (isCompleteTxt, P.string (Completion.replacement comp))
)
ClearScreen -> do
ANSI.clearScreen
ANSI.setCursorPosition 0 0
pure mempty
where
_nameChange _cmd _pastTenseCmd _oldName _newName _r = error "todo"
expectedEmptyPushDest writeRemotePath =
Expand Down
5 changes: 5 additions & 0 deletions unison-cli/unison-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ library
, ListLike
, aeson
, aeson-pretty
, ansi-terminal
, async
, base
, bytes
Expand Down Expand Up @@ -253,6 +254,7 @@ executable cli-integration-tests
, ListLike
, aeson
, aeson-pretty
, ansi-terminal
, async
, base
, bytes
Expand Down Expand Up @@ -373,6 +375,7 @@ executable transcripts
, ListLike
, aeson
, aeson-pretty
, ansi-terminal
, async
, base
, bytes
Expand Down Expand Up @@ -499,6 +502,7 @@ executable unison
, ListLike
, aeson
, aeson-pretty
, ansi-terminal
, async
, base
, bytes
Expand Down Expand Up @@ -631,6 +635,7 @@ test-suite cli-tests
, ListLike
, aeson
, aeson-pretty
, ansi-terminal
, async
, base
, bytes
Expand Down

0 comments on commit e5d9662

Please sign in to comment.