Skip to content

Commit

Permalink
TermDisplay: simplify, remove url stuff
Browse files Browse the repository at this point in the history
We only need a couple of simple counters rather than concurrent maps
and download buffers that were used in the original coursier code.
  • Loading branch information
kitbellew committed Feb 20, 2025
1 parent 3cf676c commit 50a17f3
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ trait ScalafmtRunner {
options: CliOptions,
inputMethods: Seq[InputMethod],
msg: String,
): Option[TermDisplay] =
if (
options.writeMode != WriteMode.Stdout && inputMethods.lengthCompare(5) > 0
) {
): Option[TermDisplay] = {
val numInputs = inputMethods.length
if (options.writeMode != WriteMode.Stdout && numInputs > 5) {
val termDisplay = new TermDisplay(
options.common.info.printWriter,
msg,
numInputs,
fallbackMode = options.nonInteractive || TermDisplay.defaultFallbackMode,
)
termDisplay.init()
termDisplay.startTask(msg, options.cwd.jfile)
termDisplay.taskLength(msg, inputMethods.length, 0)
termDisplay.start()
Some(termDisplay)
} else None
}

protected def getInputMethods(
options: CliOptions,
Expand Down Expand Up @@ -104,8 +104,8 @@ trait ScalafmtRunner {
.write(formattedCode, code, options)
}.transform { r =>
val ok = r == Success(ExitCode.Ok)
if (ok) termDisplay.foreach(_.taskProgress(termDisplayMessage))
else if (options.check) completed.trySuccess(asExit(r))
termDisplay.foreach(_.done(ok = ok))
if (!ok && options.check) completed.trySuccess(asExit(r))
Success(r)
}
tasks += future
Expand All @@ -116,10 +116,7 @@ trait ScalafmtRunner {
ExitCode.merge(res, asExit(r))
}.onComplete(completed.tryComplete)

completed.future.td { case (td, r) =>
td.completedTask(termDisplayMessage, r == Success(ExitCode.Ok))
td.stop()
}
completed.future.td { case (td, _) => td.end() }
}

}
Loading

0 comments on commit 50a17f3

Please sign in to comment.