From 7f80d5f81be1b16e5a5131806cd2470db16d7ccd Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Mon, 5 Aug 2024 15:24:16 +0200 Subject: [PATCH] Allow JLine to fall back to a dump terminal Set the `dumb` JLine option to `null` instead of `false` when it is not forced. This allows JLine to fall back to a dumb terminal. --- compiler/src/dotty/tools/repl/JLineTerminal.scala | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/repl/JLineTerminal.scala b/compiler/src/dotty/tools/repl/JLineTerminal.scala index 294f0a331ec2..e4ac1626525e 100644 --- a/compiler/src/dotty/tools/repl/JLineTerminal.scala +++ b/compiler/src/dotty/tools/repl/JLineTerminal.scala @@ -21,11 +21,16 @@ class JLineTerminal extends java.io.Closeable { // Logger.getLogger("org.jline").setLevel(Level.FINEST) private val terminal = - TerminalBuilder.builder() - .dumb(dumbTerminal) // fail early if not able to create a terminal - .build() + var builder = TerminalBuilder.builder() + if System.getenv("TERM") == "dumb" then + // Force dumb terminal if `TERM` is `"dumb"`. + // Note: the default value for the `dumb` option is `null`, which allows + // JLine to fall back to a dumb terminal. This is different than `true` or + // `false` and can't be set using the `dumb` setter. + // This option is used at https://github.com/jline/jline3/blob/894b5e72cde28a551079402add4caea7f5527806/terminal/src/main/java/org/jline/terminal/TerminalBuilder.java#L528. + builder.dumb(true) + builder.build() private val history = new DefaultHistory - def dumbTerminal = Option(System.getenv("TERM")) == Some("dumb") private def blue(str: String)(using Context) = if (ctx.settings.color.value != "never") Console.BLUE + str + Console.RESET