From b53d8c443324597c5d3141d8b9fddcc40c1c4b4a Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 7 Mar 2017 12:14:55 +0000 Subject: [PATCH 1/4] Notify & enable users to stay in the warm shell Notify & enable users to stay in sbt's shell on the warm JVM by hitting [ENTER] while sbt is running. Looks like this; first I run 'sbt about', then I hit [ENTER]: $ sbt about [info] !!! Executing in batch mode !!! For better performance, hit [ENTER] to remain in the sbt shell [info] Loading global plugins from /Users/dnw/.dotfiles/.sbt/0.13/plugins [info] Loading project definition from /s/t/project [info] Set current project to t (in build file:/s/t/) [info] This is sbt 0.13.14-SNAPSHOT [info] The current project is {file:/s/t/}t 0.1.0-SNAPSHOT [info] The current project is built against Scala 2.12.1 [info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, sbt.plugins.Giter8TemplatePlugin [info] sbt, sbt plugins, and build definitions are using Scala 2.10.6 > > Fixes #2987 --- main/command/src/main/scala/sbt/MainLoop.scala | 4 ++++ main/command/src/main/scala/sbt/State.scala | 17 +++++++++++------ notes/0.13.14/stay-in-shell.md | 7 +++++++ 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 notes/0.13.14/stay-in-shell.md diff --git a/main/command/src/main/scala/sbt/MainLoop.scala b/main/command/src/main/scala/sbt/MainLoop.scala index 488decab0..98b99a396 100644 --- a/main/command/src/main/scala/sbt/MainLoop.scala +++ b/main/command/src/main/scala/sbt/MainLoop.scala @@ -65,6 +65,10 @@ object MainLoop { val newLogging = state.globalLogging.newLogger(out, logBacking) transferLevels(state, newLogging) val loggedState = state.copy(globalLogging = newLogging) + def isInteractive = System.console() != null + def hasShell = state.remainingCommands contains "shell" + if (isInteractive && !hasShell) + state.log info "!!! Executing in batch mode !!! For better performance, hit [ENTER] to remain in the sbt shell" try run(loggedState) finally out.close() } diff --git a/main/command/src/main/scala/sbt/State.scala b/main/command/src/main/scala/sbt/State.scala index b7f38fbba..218e136af 100644 --- a/main/command/src/main/scala/sbt/State.scala +++ b/main/command/src/main/scala/sbt/State.scala @@ -176,13 +176,18 @@ object State { /** Provides operations and transformations on State. */ implicit def stateOps(s: State): StateOps = new StateOps { - def process(f: (String, State) => State): State = - s.remainingCommands match { - case Seq() => exit(true) - case Seq(x, xs @ _*) => - log.debug(s"> $x") - f(x, s.copy(remainingCommands = xs, history = x :: s.history)) + def process(f: (String, State) => State): State = { + def doX(x: String, xs: Seq[String]) = { + log.debug(s"> $x") + f(x, s.copy(remainingCommands = xs, history = x :: s.history)) } + def isInteractive = System.console() != null + def hasInput = System.console().reader().ready() + s.remainingCommands match { + case Seq() => if (isInteractive && hasInput) doX("shell", Nil) else exit(true) + case Seq(x, xs @ _*) => doX(x, xs) + } + } def :::(newCommands: Seq[String]): State = s.copy(remainingCommands = newCommands ++ s.remainingCommands) def ::(command: String): State = (command :: Nil) ::: this def ++(newCommands: Seq[Command]): State = s.copy(definedCommands = (s.definedCommands ++ newCommands).distinct) diff --git a/notes/0.13.14/stay-in-shell.md b/notes/0.13.14/stay-in-shell.md new file mode 100644 index 000000000..be4c7f956 --- /dev/null +++ b/notes/0.13.14/stay-in-shell.md @@ -0,0 +1,7 @@ +### Improvements + +- Notifies & enables users to stay in sbt's shell on the warm JVM by hitting \[ENTER\] while sbt is running. [#2987][]/[#2996][] by [@dwijnand][] + +[#2987]: https://github.com/sbt/sbt/issues/2987 +[#2996]: https://github.com/sbt/sbt/pull/2996 +[@dwijnand]: https://github.com/dwijnand From 019f92dc937a451b270d213562f4169e48c642e2 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 7 Mar 2017 13:01:44 +0000 Subject: [PATCH 2/4] Switch from log.info and !!! to log.warn Good idea, Lars. Thanks. --- main/command/src/main/scala/sbt/MainLoop.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/command/src/main/scala/sbt/MainLoop.scala b/main/command/src/main/scala/sbt/MainLoop.scala index 98b99a396..915902b1f 100644 --- a/main/command/src/main/scala/sbt/MainLoop.scala +++ b/main/command/src/main/scala/sbt/MainLoop.scala @@ -68,7 +68,7 @@ object MainLoop { def isInteractive = System.console() != null def hasShell = state.remainingCommands contains "shell" if (isInteractive && !hasShell) - state.log info "!!! Executing in batch mode !!! For better performance, hit [ENTER] to remain in the sbt shell" + state.log warn "Executing in batch mode; for better performance, hit [ENTER] to remain in the sbt shell" try run(loggedState) finally out.close() } From 1c614fd6999d2c641d684fa7dab98357c650a737 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 7 Mar 2017 13:30:56 +0000 Subject: [PATCH 3/4] Instruct how to get into interactive mode directly --- main/command/src/main/scala/sbt/MainLoop.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main/command/src/main/scala/sbt/MainLoop.scala b/main/command/src/main/scala/sbt/MainLoop.scala index 915902b1f..292f8e2b8 100644 --- a/main/command/src/main/scala/sbt/MainLoop.scala +++ b/main/command/src/main/scala/sbt/MainLoop.scala @@ -67,8 +67,10 @@ object MainLoop { val loggedState = state.copy(globalLogging = newLogging) def isInteractive = System.console() != null def hasShell = state.remainingCommands contains "shell" - if (isInteractive && !hasShell) - state.log warn "Executing in batch mode; for better performance, hit [ENTER] to remain in the sbt shell" + if (isInteractive && !hasShell) { + state.log warn "BATCH MODE: for better performance hit [ENTER] to switch to interactive mode" + state.log warn " consider launching sbt without any commands, or explicitly passing 'shell'" + } try run(loggedState) finally out.close() } From e75ebb86b6a4cab3e3bd6a5e9d7ffa845b0748e0 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 7 Mar 2017 13:56:05 +0000 Subject: [PATCH 4/4] Try communicating in actual English --- main/command/src/main/scala/sbt/MainLoop.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main/command/src/main/scala/sbt/MainLoop.scala b/main/command/src/main/scala/sbt/MainLoop.scala index 292f8e2b8..c393be3f3 100644 --- a/main/command/src/main/scala/sbt/MainLoop.scala +++ b/main/command/src/main/scala/sbt/MainLoop.scala @@ -68,7 +68,8 @@ object MainLoop { def isInteractive = System.console() != null def hasShell = state.remainingCommands contains "shell" if (isInteractive && !hasShell) { - state.log warn "BATCH MODE: for better performance hit [ENTER] to switch to interactive mode" + state.log warn "Executing in batch mode." + state.log warn " For better performance, hit [ENTER] to switch to interactive mode, or" state.log warn " consider launching sbt without any commands, or explicitly passing 'shell'" } try run(loggedState) finally out.close()