mirror of https://github.com/sbt/sbt.git
Remove ammonite-terminal dependency
This commit is contained in:
parent
506cb53f3f
commit
82e64fe7a8
|
|
@ -207,8 +207,7 @@ lazy val cache = project
|
||||||
.settings(
|
.settings(
|
||||||
name := "coursier-cache",
|
name := "coursier-cache",
|
||||||
libraryDependencies ++= Seq(
|
libraryDependencies ++= Seq(
|
||||||
"org.scalaz" %% "scalaz-concurrent" % "7.1.2",
|
"org.scalaz" %% "scalaz-concurrent" % "7.1.2"
|
||||||
"com.lihaoyi" %% "ammonite-terminal" % "0.5.0"
|
|
||||||
),
|
),
|
||||||
previousArtifacts := Set(organization.value %% moduleName.value % binaryCompatibilityVersion),
|
previousArtifacts := Set(organization.value %% moduleName.value % binaryCompatibilityVersion),
|
||||||
binaryIssueFilters ++= {
|
binaryIssueFilters ++= {
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,58 @@ package coursier
|
||||||
import java.io.{File, Writer}
|
import java.io.{File, Writer}
|
||||||
import java.util.concurrent._
|
import java.util.concurrent._
|
||||||
|
|
||||||
import ammonite.terminal.{ TTY, Ansi }
|
|
||||||
|
|
||||||
import scala.annotation.tailrec
|
import scala.annotation.tailrec
|
||||||
import scala.collection.mutable.ArrayBuffer
|
import scala.collection.mutable.ArrayBuffer
|
||||||
|
import scala.util.Try
|
||||||
|
|
||||||
|
object Terminal {
|
||||||
|
|
||||||
|
// Cut-n-pasted and adapted from
|
||||||
|
// https://github.com/lihaoyi/Ammonite/blob/10854e3b8b454a74198058ba258734a17af32023/terminal/src/main/scala/ammonite/terminal/Utils.scala
|
||||||
|
|
||||||
|
private lazy val pathedTput = if (new File("/usr/bin/tput").exists()) "/usr/bin/tput" else "tput"
|
||||||
|
|
||||||
|
def consoleDim(s: String): Option[Int] =
|
||||||
|
if (new File("/dev/tty").exists()) {
|
||||||
|
import sys.process._
|
||||||
|
Try(Seq("bash", "-c", s"$pathedTput $s 2> /dev/tty").!!.trim.toInt).toOption
|
||||||
|
} else
|
||||||
|
None
|
||||||
|
|
||||||
|
class Ansi(val output: Writer) extends AnyVal {
|
||||||
|
private def control(n: Int, c: Char) = output.write(s"\033[" + n + c)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move up `n` squares
|
||||||
|
*/
|
||||||
|
def up(n: Int): Unit = if (n == 0) "" else control(n, 'A')
|
||||||
|
/**
|
||||||
|
* Move down `n` squares
|
||||||
|
*/
|
||||||
|
def down(n: Int): Unit = if (n == 0) "" else control(n, 'B')
|
||||||
|
/**
|
||||||
|
* Move left `n` squares
|
||||||
|
*/
|
||||||
|
def left(n: Int): Unit = if (n == 0) "" else control(n, 'D')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the current line
|
||||||
|
*
|
||||||
|
* n=0: clear from cursor to end of line
|
||||||
|
* n=1: clear from cursor to start of line
|
||||||
|
* n=2: clear entire line
|
||||||
|
*/
|
||||||
|
def clearLine(n: Int): Unit = control(n, 'K')
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
class TermDisplay(
|
class TermDisplay(
|
||||||
out: Writer,
|
out: Writer,
|
||||||
var fallbackMode: Boolean = sys.env.get("COURSIER_NO_TERM").nonEmpty
|
var fallbackMode: Boolean = sys.env.get("COURSIER_NO_TERM").nonEmpty
|
||||||
) extends Cache.Logger {
|
) extends Cache.Logger {
|
||||||
|
|
||||||
private val ansi = new Ansi(out)
|
private val ansi = new Terminal.Ansi(out)
|
||||||
private var width = 80
|
private var width = 80
|
||||||
private val refreshInterval = 1000 / 60
|
private val refreshInterval = 1000 / 60
|
||||||
private val fallbackRefreshInterval = 1000
|
private val fallbackRefreshInterval = 1000
|
||||||
|
|
@ -170,11 +211,12 @@ class TermDisplay(
|
||||||
t.setDaemon(true)
|
t.setDaemon(true)
|
||||||
|
|
||||||
def init(): Unit = {
|
def init(): Unit = {
|
||||||
try {
|
Terminal.consoleDim("cols") match {
|
||||||
width = TTY.consoleDim("cols")
|
case Some(cols) =>
|
||||||
ansi.clearLine(2)
|
width = cols
|
||||||
} catch { case _: Exception =>
|
ansi.clearLine(2)
|
||||||
fallbackMode = true
|
case None =>
|
||||||
|
fallbackMode = true
|
||||||
}
|
}
|
||||||
|
|
||||||
t.start()
|
t.start()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue