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 null => None
|
||||||
case x => Some(x.trim)
|
case x => Some(x.trim)
|
||||||
}
|
}
|
||||||
def getHistory: Array[String] =
|
|
||||||
JLine.synchronized {
|
|
||||||
reader.getHistory.getHistoryList.toArray(new Array[String](0))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
private object JLine
|
private object JLine
|
||||||
{
|
{
|
||||||
|
|
@ -71,10 +67,13 @@ private object JLine
|
||||||
Control.trapAndLog(log)
|
Control.trapAndLog(log)
|
||||||
{
|
{
|
||||||
historyFile.getParentFile.mkdirs()
|
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)
|
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
|
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) =>
|
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) =>
|
case Some(commands) =>
|
||||||
println(command) //better to print it than to log it
|
commands.foreach(println) //better to print it than to log it
|
||||||
continue(project, command :: tail, failAction)
|
continue(project, commands ::: tail, failAction)
|
||||||
case None => failed(UsageErrorExitCode)
|
case None => failed(UsageErrorExitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -280,7 +280,7 @@ class xMain extends xsbti.AppMain
|
||||||
if(message eq null) None else Some(message)
|
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
|
val lines = historyPath.toList.flatMap(h => xsbt.FileUtilities.readLines(h.asFile) ).toArray
|
||||||
if(lines.isEmpty)
|
if(lines.isEmpty)
|
||||||
|
|
@ -290,15 +290,24 @@ class xMain extends xsbti.AppMain
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
def replaceLastCommand(s: String) {
|
val ListPrefix = ":"
|
||||||
lines(lines.length - 1) = s
|
val history = complete.History(lines, log)
|
||||||
historyPath foreach { h => xsbt.FileUtilities.writeLines(h.asFile, lines) }
|
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] =
|
private def historyCommand(history: complete.History, s: String, log: Logger): Option[String] =
|
||||||
{
|
{
|
||||||
val ContainsPrefix = "?"
|
val ContainsPrefix = "?"
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,16 @@ final class History private(lines: Array[String], log: Logger) extends NotNull
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
act
|
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
|
object History
|
||||||
{
|
{
|
||||||
def apply(lines: Seq[String], log: Logger): History = new History(lines.toArray, log)
|
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) }
|
try { Some(s.toInt) }
|
||||||
catch { case e: NumberFormatException => None }
|
catch { case e: NumberFormatException => None }
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue