Merge pull request #2941 from eed3si9n/wip/2633

Rebase: Add new SBT global setting asciiGraphWidth
This commit is contained in:
eugene yokota 2017-01-22 18:49:14 -05:00 committed by GitHub
commit b47a0e71a1
5 changed files with 19 additions and 9 deletions

View File

@ -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(

View File

@ -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)

View File

@ -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 =>

View File

@ -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) + ".."

View File

@ -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