Skip to content

Commit

Permalink
Add :silent command to toggle automatic printing of outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
natsukagami committed Dec 19, 2024
1 parent b084a23 commit d60224f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/repl/ParseResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ object Reset {
val command: String = ":reset"
}

/** Toggle automatic printing of results */
case object Silent extends Command:
val command: String = ":silent"

/** `:quit` exits the repl */
case object Quit extends Command {
val command: String = ":quit"
Expand All @@ -113,6 +117,7 @@ case object Help extends Command {
|:imports show import history
|:reset [options] reset the repl to its initial state, forgetting all session entries
|:settings <options> update compiler options, if possible
|:reset disable/enable automatic printing of results
""".stripMargin
}

Expand All @@ -137,6 +142,7 @@ object ParseResult {
TypeOf.command -> (arg => TypeOf(arg)),
DocOf.command -> (arg => DocOf(arg)),
Settings.command -> (arg => Settings(arg)),
Silent.command -> (_ => Silent),
)

def apply(source: SourceFile)(using state: State): ParseResult = {
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ class ReplDriver(settings: Array[String],
rootCtx = setupRootCtx(tokenize(arg).toArray, rootCtx)
state.copy(context = rootCtx)

case Silent => state.copy(quiet = !state.quiet)

case Quit =>
// end of the world!
state
Expand Down

0 comments on commit d60224f

Please sign in to comment.