mirror of https://github.com/sbt/sbt.git
configurable shell prompt
for example:
Command.ShellPrompt := {
s => Project.extract(s).cid + "> "
}
This commit is contained in:
parent
df1c9c00c7
commit
329709c750
|
|
@ -30,6 +30,7 @@ object Command
|
|||
|
||||
val Logged = AttributeKey[Logger]("log")
|
||||
val HistoryPath = SettingKey[Option[File]]("history")
|
||||
val ShellPrompt = SettingKey[State => String]("shell-prompt")
|
||||
val Analysis = AttributeKey[inc.Analysis]("analysis")
|
||||
val Watch = SettingKey[Watched]("continuous-watch")
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ package sbt
|
|||
import Scope.{GlobalScope,ThisScope}
|
||||
import Project.{AppConfig, Config, Initialize, ScopedKey, Setting, ThisProject, ThisProjectRef}
|
||||
import Configurations.{Compile => CompileConf, Test => TestConf}
|
||||
import Command.HistoryPath
|
||||
import Command.{HistoryPath, ShellPrompt}
|
||||
import EvaluateTask.{resolvedScoped, streams}
|
||||
import complete._
|
||||
import inc.Analysis
|
||||
|
|
@ -204,6 +204,7 @@ object Default
|
|||
|
||||
def core = Seq(
|
||||
CrossPaths :== true,
|
||||
ShellPrompt in GlobalScope :== (_ => "> "),
|
||||
Aggregate in GlobalScope :== Aggregation.Enabled,
|
||||
Name <<= ThisProject(_.id),
|
||||
Version :== "0.1",
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ package sbt
|
|||
import compile.EvalImports
|
||||
import sbt.complete.{DefaultParsers, Parser}
|
||||
|
||||
import Command.{applyEffect,Analysis,HistoryPath,Logged,Watch}
|
||||
import Command.{applyEffect,Analysis,HistoryPath,Logged,ShellPrompt,Watch}
|
||||
import scala.annotation.tailrec
|
||||
import scala.collection.JavaConversions._
|
||||
import Function.tupled
|
||||
|
|
@ -109,9 +109,10 @@ object BuiltinCommands
|
|||
|
||||
def shell = Command.command(Shell, ShellBrief, ShellDetailed) { s =>
|
||||
val historyPath = (s get HistoryPath.key) getOrElse Some((s.baseDir / ".history").asFile)
|
||||
val prompt = (s get ShellPrompt.key) match { case Some(pf) => pf(s); case None => "> " }
|
||||
val parser = Command.combine(s.processors)
|
||||
val reader = new FullReader(historyPath, parser(s))
|
||||
val line = reader.readLine("> ")
|
||||
val line = reader.readLine(prompt)
|
||||
line match {
|
||||
case Some(line) => s.copy(onFailure = Some(Shell), commands = line +: Shell +: s.commands)
|
||||
case None => s
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ package sbt
|
|||
import java.net.URI
|
||||
import Project._
|
||||
import Types.Endo
|
||||
import Command.{HistoryPath,Watch}
|
||||
import Command.{HistoryPath,ShellPrompt,Watch}
|
||||
import CommandSupport.logger
|
||||
import compile.Eval
|
||||
|
||||
|
|
@ -72,11 +72,14 @@ object Project extends Init[Scope]
|
|||
|
||||
val data = structure.data
|
||||
val historyPath = HistoryPath in ref get data flatMap identity
|
||||
val prompt = ShellPrompt in ref get data
|
||||
val commands = (Commands in ref get data).toList.flatten[Command].map(_ tag (ProjectCommand, true))
|
||||
val newProcessors = commands ++ BuiltinCommands.removeTagged(s.processors, ProjectCommand)
|
||||
val newAttrs = s.attributes.put(Watch.key, makeWatched(data, ref, project)).put(HistoryPath.key, historyPath)
|
||||
s.copy(attributes = newAttrs, processors = newProcessors)
|
||||
s.copy(attributes = setCond(ShellPrompt.key, prompt, newAttrs), processors = newProcessors)
|
||||
}
|
||||
def setCond[T](key: AttributeKey[T], vopt: Option[T], attributes: AttributeMap): AttributeMap =
|
||||
vopt match { case Some(v) => attributes.put(key, v); case None => attributes.remove(key) }
|
||||
def makeSettings(settings: Seq[Setting[_]], delegates: Scope => Seq[Scope], scopeLocal: ScopedKey[_] => Seq[Setting[_]]) =
|
||||
translateUninitialized( make(settings)(delegates, scopeLocal) )
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ trait AttributeMap
|
|||
{
|
||||
def apply[T](k: AttributeKey[T]): T
|
||||
def get[T](k: AttributeKey[T]): Option[T]
|
||||
def remove[T](k: AttributeKey[T]): AttributeMap
|
||||
def contains[T](k: AttributeKey[T]): Boolean
|
||||
def put[T](k: AttributeKey[T], value: T): AttributeMap
|
||||
def keys: Iterable[AttributeKey[_]]
|
||||
|
|
@ -40,6 +41,7 @@ private class BasicAttributeMap(private val backing: Map[AttributeKey[_], Any])
|
|||
def isEmpty: Boolean = backing.isEmpty
|
||||
def apply[T](k: AttributeKey[T]) = backing(k).asInstanceOf[T]
|
||||
def get[T](k: AttributeKey[T]) = backing.get(k).asInstanceOf[Option[T]]
|
||||
def remove[T](k: AttributeKey[T]): AttributeMap = new BasicAttributeMap( backing - k )
|
||||
def contains[T](k: AttributeKey[T]) = backing.contains(k)
|
||||
def put[T](k: AttributeKey[T], value: T): AttributeMap = new BasicAttributeMap( backing.updated(k, value) )
|
||||
def keys: Iterable[AttributeKey[_]] = backing.keys
|
||||
|
|
|
|||
Loading…
Reference in New Issue