mirror of https://github.com/sbt/sbt.git
part I of revised approach to commands/projects
no privileged project member of State no separation of Command and Apply, so no pre-filtering on State use entries in State attributes map instead of mixing in traits to project object: HistoryPath, Logger, Analysis, Navigate, Watch, TaskedKey rework Navigation to be standalone instead of mixin
This commit is contained in:
parent
783d732868
commit
625ddd703c
|
|
@ -4,6 +4,8 @@
|
||||||
package sbt
|
package sbt
|
||||||
package complete
|
package complete
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
object HistoryCommands
|
object HistoryCommands
|
||||||
{
|
{
|
||||||
val Start = "!"
|
val Start = "!"
|
||||||
|
|
@ -38,7 +40,7 @@ object HistoryCommands
|
||||||
def printHelp(): Unit =
|
def printHelp(): Unit =
|
||||||
println(helpString)
|
println(helpString)
|
||||||
|
|
||||||
def apply(s: String, historyPath: Option[Path], maxLines: Int, error: String => Unit): Option[List[String]] =
|
def apply(s: String, historyPath: Option[File], maxLines: Int, error: String => Unit): Option[List[String]] =
|
||||||
if(s.isEmpty)
|
if(s.isEmpty)
|
||||||
{
|
{
|
||||||
printHelp()
|
printHelp()
|
||||||
|
|
@ -46,7 +48,7 @@ object HistoryCommands
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
val lines = historyPath.toList.flatMap(h => IO.readLines(h.asFile) ).toArray
|
val lines = historyPath.toList.flatMap( p => IO.readLines(p) ).toArray
|
||||||
if(lines.isEmpty)
|
if(lines.isEmpty)
|
||||||
{
|
{
|
||||||
error("No history")
|
error("No history")
|
||||||
|
|
@ -66,7 +68,7 @@ object HistoryCommands
|
||||||
{
|
{
|
||||||
val command = historyCommand(history, s)
|
val command = historyCommand(history, s)
|
||||||
command.foreach(lines(lines.length - 1) = _)
|
command.foreach(lines(lines.length - 1) = _)
|
||||||
historyPath foreach { h => IO.writeLines(h.asFile, lines) }
|
historyPath foreach { h => IO.writeLines(h, lines) }
|
||||||
Some(command.toList)
|
Some(command.toList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@
|
||||||
* Copyright 2008, 2009 Mark Harrah
|
* Copyright 2008, 2009 Mark Harrah
|
||||||
*/
|
*/
|
||||||
package sbt
|
package sbt
|
||||||
|
|
||||||
import jline.{Completor, ConsoleReader}
|
import jline.{Completor, ConsoleReader}
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
abstract class JLine extends LineReader
|
abstract class JLine extends LineReader
|
||||||
{
|
{
|
||||||
protected[this] val reader: ConsoleReader
|
protected[this] val reader: ConsoleReader
|
||||||
|
|
@ -37,10 +40,10 @@ private object JLine
|
||||||
try { action }
|
try { action }
|
||||||
finally { t.enableEcho() }
|
finally { t.enableEcho() }
|
||||||
}
|
}
|
||||||
private[sbt] def initializeHistory(cr: ConsoleReader, historyPath: Option[Path]): Unit =
|
private[sbt] def initializeHistory(cr: ConsoleReader, historyPath: Option[File]): Unit =
|
||||||
for(historyLocation <- historyPath)
|
for(historyLocation <- historyPath)
|
||||||
{
|
{
|
||||||
val historyFile = historyLocation.asFile
|
val historyFile = historyLocation.getAbsoluteFile
|
||||||
ErrorHandling.wideConvert
|
ErrorHandling.wideConvert
|
||||||
{
|
{
|
||||||
historyFile.getParentFile.mkdirs()
|
historyFile.getParentFile.mkdirs()
|
||||||
|
|
@ -49,7 +52,7 @@ private object JLine
|
||||||
history.setHistoryFile(historyFile)
|
history.setHistoryFile(historyFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
def simple(historyPath: Option[Path]): SimpleReader = new SimpleReader(historyPath)
|
def simple(historyPath: Option[File]): SimpleReader = new SimpleReader(historyPath)
|
||||||
val MaxHistorySize = 500
|
val MaxHistorySize = 500
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,14 +60,14 @@ trait LineReader extends NotNull
|
||||||
{
|
{
|
||||||
def readLine(prompt: String): Option[String]
|
def readLine(prompt: String): Option[String]
|
||||||
}
|
}
|
||||||
private[sbt] final class LazyJLineReader(historyPath: Option[Path], completor: => Completor) extends JLine
|
private[sbt] final class LazyJLineReader(historyPath: Option[File] /*, completor: => Completor*/) extends JLine
|
||||||
{
|
{
|
||||||
protected[this] val reader =
|
protected[this] val reader =
|
||||||
{
|
{
|
||||||
val cr = new ConsoleReader
|
val cr = new ConsoleReader
|
||||||
cr.setBellEnabled(false)
|
cr.setBellEnabled(false)
|
||||||
JLine.initializeHistory(cr, historyPath)
|
JLine.initializeHistory(cr, historyPath)
|
||||||
cr.addCompletor(new LazyCompletor(completor))
|
// cr.addCompletor(new LazyCompletor(completor))
|
||||||
cr
|
cr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -75,7 +78,7 @@ private class LazyCompletor(delegate0: => Completor) extends Completor
|
||||||
delegate.complete(buffer, cursor, candidates)
|
delegate.complete(buffer, cursor, candidates)
|
||||||
}
|
}
|
||||||
|
|
||||||
class SimpleReader private[sbt] (historyPath: Option[Path]) extends JLine
|
class SimpleReader private[sbt] (historyPath: Option[File]) extends JLine
|
||||||
{
|
{
|
||||||
protected[this] val reader = JLine.createReader()
|
protected[this] val reader = JLine.createReader()
|
||||||
JLine.initializeHistory(reader, historyPath)
|
JLine.initializeHistory(reader, historyPath)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue