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:
Mark Harrah 2010-12-19 12:03:10 -05:00
parent 783d732868
commit 625ddd703c
2 changed files with 15 additions and 10 deletions

View File

@ -4,6 +4,8 @@
package sbt
package complete
import java.io.File
object HistoryCommands
{
val Start = "!"
@ -38,7 +40,7 @@ object HistoryCommands
def printHelp(): Unit =
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)
{
printHelp()
@ -46,7 +48,7 @@ object HistoryCommands
}
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)
{
error("No history")
@ -66,7 +68,7 @@ object HistoryCommands
{
val command = historyCommand(history, s)
command.foreach(lines(lines.length - 1) = _)
historyPath foreach { h => IO.writeLines(h.asFile, lines) }
historyPath foreach { h => IO.writeLines(h, lines) }
Some(command.toList)
}
}

View File

@ -2,7 +2,10 @@
* Copyright 2008, 2009 Mark Harrah
*/
package sbt
import jline.{Completor, ConsoleReader}
import jline.{Completor, ConsoleReader}
import java.io.File
abstract class JLine extends LineReader
{
protected[this] val reader: ConsoleReader
@ -37,10 +40,10 @@ private object JLine
try { action }
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)
{
val historyFile = historyLocation.asFile
val historyFile = historyLocation.getAbsoluteFile
ErrorHandling.wideConvert
{
historyFile.getParentFile.mkdirs()
@ -49,7 +52,7 @@ private object JLine
history.setHistoryFile(historyFile)
}
}
def simple(historyPath: Option[Path]): SimpleReader = new SimpleReader(historyPath)
def simple(historyPath: Option[File]): SimpleReader = new SimpleReader(historyPath)
val MaxHistorySize = 500
}
@ -57,14 +60,14 @@ trait LineReader extends NotNull
{
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 =
{
val cr = new ConsoleReader
cr.setBellEnabled(false)
JLine.initializeHistory(cr, historyPath)
cr.addCompletor(new LazyCompletor(completor))
// cr.addCompletor(new LazyCompletor(completor))
cr
}
}
@ -75,7 +78,7 @@ private class LazyCompletor(delegate0: => Completor) extends Completor
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()
JLine.initializeHistory(reader, historyPath)