diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 382acbfbe..09f0cc749 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -362,7 +362,8 @@ object Defaults extends BuildCommon { private[this] lazy val configGlobal = globalDefaults(Seq( initialCommands :== "", - cleanupCommands :== "" + cleanupCommands :== "", + asciiGraphWidth :== 40 )) lazy val projectTasks: Seq[Setting[_]] = Seq( diff --git a/main/src/main/scala/sbt/Keys.scala b/main/src/main/scala/sbt/Keys.scala index fcf980d93..6fa80a7f8 100644 --- a/main/src/main/scala/sbt/Keys.scala +++ b/main/src/main/scala/sbt/Keys.scala @@ -179,6 +179,7 @@ object Keys { val compileOrder = SettingKey[CompileOrder]("compile-order", "Configures the order in which Java and sources within a single compilation are compiled. Valid values are: JavaThenScala, ScalaThenJava, or Mixed.", BPlusSetting) val initialCommands = SettingKey[String]("initial-commands", "Initial commands to execute when starting up the Scala interpreter.", AMinusSetting) val cleanupCommands = SettingKey[String]("cleanup-commands", "Commands to execute before the Scala interpreter exits.", BMinusSetting) + val asciiGraphWidth = SettingKey[Int]("asciiGraphWidth", "Determines maximum width of the settings graph in ASCII mode", AMinusSetting) val compileOptions = TaskKey[CompileOptions]("compile-options", "Collects basic options to configure compilers", DTask) val compileInputs = TaskKey[Inputs]("compile-inputs", "Collects all inputs needed for compilation.", DTask) val scalaHome = SettingKey[Option[File]]("scala-home", "If Some, defines the local Scala installation to use for compilation, running, and testing.", ASetting) diff --git a/main/src/main/scala/sbt/internal/Inspect.scala b/main/src/main/scala/sbt/internal/Inspect.scala index 0d1e9ff6a..90cfa5348 100644 --- a/main/src/main/scala/sbt/internal/Inspect.scala +++ b/main/src/main/scala/sbt/internal/Inspect.scala @@ -47,7 +47,7 @@ object Inspect { Project.details(structure, actual, sk.scope, sk.key) case DependencyTreeMode => val basedir = new File(Project.session(s).current.build) - Project.settingGraph(structure, basedir, sk).dependsAscii + Project.settingGraph(structure, basedir, sk).dependsAscii(get(sbt.Keys.asciiGraphWidth)) case UsesMode => Project.showUses(Project.usedBy(structure, true, sk.key)) case DefinitionsMode => diff --git a/main/src/main/scala/sbt/internal/SettingGraph.scala b/main/src/main/scala/sbt/internal/SettingGraph.scala index ec2b62df6..dfd0e2ec3 100644 --- a/main/src/main/scala/sbt/internal/SettingGraph.scala +++ b/main/src/main/scala/sbt/internal/SettingGraph.scala @@ -4,7 +4,7 @@ package sbt package internal -import sbt.internal.util.Show +import sbt.internal.util.{ Show, JLine } import java.io.File import Def.{ compiled, flattenLocals, ScopedKey } @@ -50,10 +50,11 @@ case class SettingGraph( } getOrElse { d.typeName } } getOrElse { "" } - def dependsAscii: String = Graph.toAscii( + def dependsAscii(defaultWidth: Int): String = Graph.toAscii( this, (x: SettingGraph) => x.depends.toSeq.sortBy(_.name), - (x: SettingGraph) => "%s = %s" format (x.definedIn getOrElse { "" }, x.dataString) + (x: SettingGraph) => "%s = %s" format (x.definedIn getOrElse { "" }, x.dataString), + defaultWidth ) } @@ -63,10 +64,8 @@ object Graph { // [info] | +-baz // [info] | // [info] +-quux - def toAscii[A](top: A, children: A => Seq[A], display: A => String): String = { - val defaultWidth = 40 - // TODO: Fix JLine - val maxColumn = math.max( /*JLine.usingTerminal(_.getWidth)*/ 0, defaultWidth) - 8 + def toAscii[A](top: A, children: A => Seq[A], display: A => String, defaultWidth: Int): String = { + val maxColumn = math.max(JLine.usingTerminal(_.getWidth), defaultWidth) - 8 val twoSpaces = " " + " " // prevent accidentally being converted into a tab def limitLine(s: String): String = if (s.length > maxColumn) s.slice(0, maxColumn - 2) + ".." diff --git a/notes/1.0.0/ascii-graph-width.markdown b/notes/1.0.0/ascii-graph-width.markdown new file mode 100644 index 000000000..341577b3e --- /dev/null +++ b/notes/1.0.0/ascii-graph-width.markdown @@ -0,0 +1,9 @@ +[@RomanIakovlev]: https://github.com/RomanIakovlev + +### Fixes with compatibility implications + +### Improvements + +Add new global setting `asciiGraphWidth` that controls the maximum width of the ASCII graphs printed by commands like `inspect tree`. Default value corresponds to the previously hardcoded value of 40 characters. By [@RomanIakovlev][@RomanIakovlev]. + +### Bug fixes