mirror of https://github.com/sbt/sbt.git
show history with !: or !:n
This commit is contained in:
parent
5222234ee1
commit
3462f7c8d6
|
|
@ -36,10 +36,6 @@ abstract class JLine extends LineReader
|
|||
case null => None
|
||||
case x => Some(x.trim)
|
||||
}
|
||||
def getHistory: Array[String] =
|
||||
JLine.synchronized {
|
||||
reader.getHistory.getHistoryList.toArray(new Array[String](0))
|
||||
}
|
||||
}
|
||||
private object JLine
|
||||
{
|
||||
|
|
@ -71,10 +67,13 @@ private object JLine
|
|||
Control.trapAndLog(log)
|
||||
{
|
||||
historyFile.getParentFile.mkdirs()
|
||||
cr.getHistory.setHistoryFile(historyFile)
|
||||
val history = cr.getHistory
|
||||
history.setMaxSize(MaxHistorySize)
|
||||
history.setHistoryFile(historyFile)
|
||||
}
|
||||
}
|
||||
def simple(historyPath: Option[Path], log: Logger): SimpleReader = new SimpleReader(historyPath, log)
|
||||
val MaxHistorySize = 500
|
||||
}
|
||||
class SimpleReader private[sbt] (historyPath: Option[Path], log: Logger) extends JLine
|
||||
{
|
||||
|
|
|
|||
|
|
@ -199,11 +199,11 @@ class xMain extends xsbti.AppMain
|
|||
}
|
||||
|
||||
case action :: tail if action.startsWith(HistoryPrefix) =>
|
||||
historyCommand(action.substring(HistoryPrefix.length).trim, baseProject.historyPath, project.log) match
|
||||
historyCommand(action.substring(HistoryPrefix.length).trim, baseProject.historyPath, JLine.MaxHistorySize, project.log) match
|
||||
{
|
||||
case Some(command) =>
|
||||
println(command) //better to print it than to log it
|
||||
continue(project, command :: tail, failAction)
|
||||
case Some(commands) =>
|
||||
commands.foreach(println) //better to print it than to log it
|
||||
continue(project, commands ::: tail, failAction)
|
||||
case None => failed(UsageErrorExitCode)
|
||||
}
|
||||
|
||||
|
|
@ -280,7 +280,7 @@ class xMain extends xsbti.AppMain
|
|||
if(message eq null) None else Some(message)
|
||||
}
|
||||
}
|
||||
private def historyCommand(s: String, historyPath: Option[Path], log: Logger): Option[String] =
|
||||
private def historyCommand(s: String, historyPath: Option[Path], maxLines: Int, log: Logger): Option[List[String]] =
|
||||
{
|
||||
val lines = historyPath.toList.flatMap(h => xsbt.FileUtilities.readLines(h.asFile) ).toArray
|
||||
if(lines.isEmpty)
|
||||
|
|
@ -290,15 +290,24 @@ class xMain extends xsbti.AppMain
|
|||
}
|
||||
else
|
||||
{
|
||||
def replaceLastCommand(s: String) {
|
||||
lines(lines.length - 1) = s
|
||||
historyPath foreach { h => xsbt.FileUtilities.writeLines(h.asFile, lines) }
|
||||
val ListPrefix = ":"
|
||||
val history = complete.History(lines, log)
|
||||
if(s.startsWith(ListPrefix))
|
||||
{
|
||||
val rest = s.substring(ListPrefix.length)
|
||||
val show = complete.History.number(rest).getOrElse(lines.length)
|
||||
printHistory(history, maxLines, show)
|
||||
Some(Nil)
|
||||
}
|
||||
else {
|
||||
val command = historyCommand(history, s, log)
|
||||
command.foreach(lines(lines.length - 1) = _)
|
||||
historyPath foreach { h => xsbt.FileUtilities.writeLines(h.asFile, lines) }
|
||||
Some(command.toList)
|
||||
}
|
||||
val command = historyCommand(complete.History(lines, log), s, log)
|
||||
command.foreach(replaceLastCommand)
|
||||
command
|
||||
}
|
||||
}
|
||||
private def printHistory(history: complete.History, historySize: Int, show: Int): Unit = history.list(historySize, show).foreach(println)
|
||||
private def historyCommand(history: complete.History, s: String, log: Logger): Option[String] =
|
||||
{
|
||||
val ContainsPrefix = "?"
|
||||
|
|
|
|||
|
|
@ -30,13 +30,16 @@ final class History private(lines: Array[String], log: Logger) extends NotNull
|
|||
}
|
||||
else
|
||||
act
|
||||
|
||||
def list(historySize: Int, show: Int): Seq[String] =
|
||||
lines.toList.drop((lines.size - historySize) max 0).zipWithIndex.map { case (line, number) => " " + number + " " + line }.takeRight(show max 1)
|
||||
}
|
||||
|
||||
object History
|
||||
{
|
||||
def apply(lines: Seq[String], log: Logger): History = new History(lines.toArray, log)
|
||||
|
||||
private def number(s: String): Option[Int] =
|
||||
def number(s: String): Option[Int] =
|
||||
try { Some(s.toInt) }
|
||||
catch { case e: NumberFormatException => None }
|
||||
}
|
||||
Loading…
Reference in New Issue