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
This commit is contained in:
Dale Wijnand 2017-03-07 12:14:55 +00:00
parent b6466624a8
commit b53d8c4433
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
3 changed files with 22 additions and 6 deletions

View File

@ -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()
}

View File

@ -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)

View File

@ -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