mirror of https://github.com/sbt/sbt.git
Merge pull request #2996 from dwijnand/stay-in-shell
Notify & enable users to stay in the warm shell
This commit is contained in:
commit
a3d776c1c9
|
|
@ -65,6 +65,13 @@ 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 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()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Reference in New Issue