/* sbt -- Simple Build Tool
 * Copyright 2008, 2009  Mark Harrah
 */
package sbt

trait trait LineReader extends java.lang.Object with NotNullLineReader extends NotNullNotNull
{
	def (String)Option[String]readLine(Stringprompt: StringString): Option[String]Option[String]
}
class class Completors extends java.lang.Object with NotNull with ScalaObjectCompletors(val StringprojectAction: StringString, val Iterable[String]projectNames: Iterable[String]Iterable[String],
	val Iterable[String]generalCommands: Iterable[String]Iterable[String], val Iterable[String]propertyActions: Iterable[String]Iterable[String],
	val Iterable[String]prefixes: Iterable[String]Iterable[String]) extends NotNullNotNull
class class JLineReader extends java.lang.Object with sbt.LineReader with ScalaObjectJLineReader(Option[sbt.Path]historyPath: Option[sbt.Path]Option[Path], sbt.Completorscompletors: sbt.CompletorsCompletors, sbt.Loggerlog: sbt.LoggerLogger) extends sbt.LineReaderLineReader
{
	import completors._
	import jline.{ArgumentCompletor, Completor, ConsoleReader, MultiCompletor, NullCompletor, SimpleCompletor}
	
	private val jline.SimpleCompletorgeneralCompletor = (Iterable[String])jline.SimpleCompletorsimpleCompletor(=> Iterable[String]generalCommands)
	private val jline.ArgumentCompletorprojectCompletor = (Iterable[String],Iterable[String])jline.ArgumentCompletorsimpleArgumentCompletor(=> StringprojectAction (String)List[String]:: object NilNil, => Iterable[String]projectNames)
		
	private val jline.MultiCompletorcompletor = jline.MultiCompletornew jline.MultiCompletorMultiCompletor()
	
	private val jline.ConsoleReaderreader =
	{
		val jline.ConsoleReadercr = jline.ConsoleReadernew jline.ConsoleReaderConsoleReader
		jline.ConsoleReadercr.(Boolean)UnitsetBellEnabled(Boolean(false)false)
		for(((sbt.Path) => Unit)UnithistoryLocation <- Option[sbt.Path]historyPath)
		{
			val java.io.FilehistoryFile = sbt.PathhistoryLocation.=> java.io.FileasFile
			object sbt.ControlControl.(sbt.Logger)(=> Unit)UnittrapAndLog(sbt.Loggerlog)
			{
				java.io.FilehistoryFile.()java.io.FilegetParentFile.()Booleanmkdirs()
				jline.ConsoleReadercr.()jline.HistorygetHistory.(java.io.File)UnitsetHistoryFile(java.io.FilehistoryFile)
			}
		}
		jline.ConsoleReadercr.(jline.Completor)BooleanaddCompletor(=> jline.MultiCompletorcompletor)
		jline.ConsoleReadercr
	}
	
	/** Used for a single argument so that the argument can have spaces in it.*/
	object object JLineReader.this.SingleArgumentDelimiterSingleArgumentDelimiter extends object jline.ArgumentCompletorArgumentCompletor.jline.ArgumentCompletor.AbstractArgumentDelimiterAbstractArgumentDelimiter
	{
		def (String,Int)BooleanisDelimiterChar(Stringbuffer: StringString, Intpos: IntInt) =
			(Stringbuffer.(Int)CharcharAt(Intpos) (Char)Boolean== Char(' ')' ') (Boolean)Boolean&& Stringbuffer.(Int,Int)java.lang.Stringsubstring(Int(0)0, Intpos).()java.lang.Stringtrim.(Int)IntindexOf(Int(32)' ') (Int)Boolean== -Int(-1)1
	}
	
	private def (Iterable[String])jline.SimpleCompletorsimpleCompletor(Iterable[String]completions: Iterable[String]Iterable[String]) = (Array[java.lang.String])jline.SimpleCompletornew jline.SimpleCompletorSimpleCompletor(Iterable[String]completions.=> List[String]toList.Array[String]toArray)
	private def (Iterable[String],Iterable[String])jline.ArgumentCompletorsimpleArgumentCompletor(Iterable[String]first: Iterable[String]Iterable[String], Iterable[String]second: Iterable[String]Iterable[String]) =
		(jline.Completor,jline.Completor)jline.ArgumentCompletorsingleArgumentCompletor((Iterable[String])jline.SimpleCompletorsimpleCompletor(Iterable[String]first), (Iterable[String])jline.SimpleCompletorsimpleCompletor(Iterable[String]second))
	private def (jline.Completor,jline.Completor)jline.ArgumentCompletorsingleArgumentCompletor(jline.Completorfirst: jline.CompletorCompletor, jline.Completorsecond: jline.CompletorCompletor) =
	{
		val Array[jline.Completor]completors = (jline.Completor*)Array[jline.Completor]Array(jline.Completorfirst, jline.Completorsecond, jline.NullCompletornew jline.NullCompletorNullCompletor)
		val jline.ArgumentCompletorc = (Array[jline.Completor],jline.ArgumentCompletor.ArgumentDelimiter)jline.ArgumentCompletornew jline.ArgumentCompletorArgumentCompletor(Array[jline.Completor]completors, object JLineReader.this.SingleArgumentDelimiterSingleArgumentDelimiter)
		jline.ArgumentCompletorc.(Boolean)UnitsetStrict(Boolean(true)true)
		jline.ArgumentCompletorc
	}
	private def (jline.Completor,jline.Completor)jline.ArgumentCompletorrepeatedArgumentCompletor(jline.Completorfirst: jline.CompletorCompletor, jline.Completorrepeat: jline.CompletorCompletor) =
	{
		val jline.ArgumentCompletorc = (Array[jline.Completor])jline.ArgumentCompletornew jline.ArgumentCompletorArgumentCompletor((jline.Completor*)Array[jline.Completor]Array(jline.Completorfirst, jline.Completorrepeat))
		jline.ArgumentCompletorc.(Boolean)UnitsetStrict(Boolean(true)true)
		jline.ArgumentCompletorc
	}
	
	private def (Iterable[String])jline.ArgumentCompletorpropertyCompletor(Iterable[String]propertyNames: Iterable[String]Iterable[String]) =
		(Iterable[String],Iterable[String])jline.ArgumentCompletorsimpleArgumentCompletor(=> Iterable[String]propertyActions, Iterable[String]propertyNames)
	private def (jline.Completor)jline.ArgumentCompletorprefixedCompletor(jline.CompletorbaseCompletor: jline.CompletorCompletor) =
		(jline.Completor,jline.Completor)jline.ArgumentCompletorsingleArgumentCompletor((Iterable[String])jline.SimpleCompletorsimpleCompletor(=> Iterable[String]prefixes.=> List[String]toList.Array[String]toArray), jline.CompletorbaseCompletor)
	def (Iterable[String],Iterable[String],Iterable[(String, Iterable[String])])UnitsetVariableCompletions(Iterable[String]taskNames: Iterable[String]Iterable[String], Iterable[String]propertyNames: Iterable[String]Iterable[String], Iterable[(String, Iterable[String])]extra: Iterable[(String, Iterable[String])]Iterable[(String, Iterable[String])] )
	{
		import scala.collection.immutable.TreeSet
		val jline.SimpleCompletortaskCompletor = (Iterable[String])jline.SimpleCompletorsimpleCompletor((String*)(implicit (String) => Ordered[String])scala.collection.immutable.SortedSet[String]TreeSet(Iterable[String]taskNames.=> Seq[String]toSeq : _*))
		val Iterable[jline.ArgumentCompletor]extraCompletors = for( (((String, Iterable[String])) => jline.ArgumentCompletor)Iterable[jline.ArgumentCompletor](Stringfirst, Iterable[String]repeat) <- Iterable[(String, Iterable[String])]extra) yield (jline.Completor,jline.Completor)jline.ArgumentCompletorrepeatedArgumentCompletor((Iterable[String])jline.SimpleCompletorsimpleCompletor(Stringfirst (String)List[String]:: object NilNil), (Iterable[String])jline.SimpleCompletorsimpleCompletor(Iterable[String]repeat))
		val List[jline.Completor]baseCompletors = => jline.SimpleCompletorgeneralCompletor (jline.Completor)List[jline.Completor]:: jline.SimpleCompletortaskCompletor (jline.Completor)List[jline.Completor]:: => jline.ArgumentCompletorprojectCompletor (jline.ArgumentCompletor)List[jline.ArgumentCompletor]:: (Iterable[String])jline.ArgumentCompletorpropertyCompletor(Iterable[String]propertyNames) (jline.ArgumentCompletor)List[jline.ArgumentCompletor]:: Iterable[jline.ArgumentCompletor]extraCompletors.=> List[jline.ArgumentCompletor]toList
		val jline.MultiCompletorbaseCompletor = (Array[jline.Completor])jline.MultiCompletornew jline.MultiCompletorMultiCompletor(List[jline.Completor]baseCompletors.Array[jline.Completor]toArray)
		=> jline.MultiCompletorcompletor.(Array[jline.Completor])UnitsetCompletors( (jline.Completor*)Array[jline.Completor]Array(jline.MultiCompletorbaseCompletor, (jline.Completor)jline.ArgumentCompletorprefixedCompletor(jline.MultiCompletorbaseCompletor)) )
	}
	def (String)Option[String]readLine(Stringprompt: StringString) =
		=> jline.ConsoleReaderreader.(java.lang.String)java.lang.StringreadLine(Stringprompt) Option[String]match
		{
			None.typecase Null(null)null => object NoneNone
			Some[java.lang.String]case java.lang.Stringx => (java.lang.String)Some[java.lang.String]Some(java.lang.Stringx)
		}
}