com-lihaoyi / Ammonite

Scala Scripting
http://ammonite.io
MIT License
2.61k stars 372 forks source link

IllegalArgumentException: Unknown ansi-escape [0;93m at index 19 inside string cannot be parsed into an fansi.Str #1328

Open jk-1 opened 1 year ago

jk-1 commented 1 year ago

I'm trying to run simple ssh-ping command using ammonite but it fails.

ssh-ping is part of small optional Ubuntu package ssh-tools.

On Mate terminal command output when pinging non-existing host is this:

ssh-ping -q -W 2 -c 1 -p 22 myhost
SSHPING myhost

--- myhost ping statistics ---
1 requests transmitted, 0 requests received, 100% request loss

Output is very colored and there is no option in ssh-ping to turn off colors.

Running this with standard Scala REPL works fine:

scala
Welcome to Scala 2.12.8 (OpenJDK 64-Bit Server VM, Java 11.0.18).
Type in expressions for evaluation. Or try :help.

scala> import scala.sys.process._
import scala.sys.process._

scala>  val res = "ssh-ping -q -W 2 -c 1 -p 22 myhost".!!
res: String =
"SSHPING myhost

--- myhost ping statistics ---
1 requests transmitted, 0 requests received, 100% request loss
"

scala> 

But when trying to run the same with Ammonite, I get repeatedly this exception:

amm
Loading...
Welcome to the Ammonite Repl 2.4.0 (Scala 2.12.13 Java 11.0.18)
jk-kptmp@ import scala.sys.process._  
import scala.sys.process._ 

jk-kptmp@ val res = "ssh-ping -q -W 2 -c 1 -p 22 myhost".!! 
java.lang.IllegalArgumentException: Unknown ansi-escape [0;93m at index 19 inside string cannot be parsed into an fansi.Str
  fansi.ErrorMode$Throw$.handle(Fansi.scala:419)
  fansi.ErrorMode$Throw$.handle(Fansi.scala:407)
  fansi.Str$.apply(Fansi.scala:272)
  fansi.Str$.implicitApply(Fansi.scala:227)
  pprint.Renderer.$anonfun$rec$33(Renderer.scala:149)
  pprint.Result$.fromString(Result.scala:53)
  pprint.Renderer.rec(Renderer.scala:149)
  pprint.PPrinter.tokenize(PPrinter.scala:104)
  ammonite.repl.FullReplAPI$Internal.print(FullReplAPI.scala:106)
  ammonite.repl.FullReplAPI$Internal.print$(FullReplAPI.scala:61)
  ammonite.repl.FullReplAPI$$anon$1.print(FullReplAPI.scala:34)

It also fails with Ammonite and os.lib's os.proc(...).call(...)-function.

Versions: Ubuntu 20.04, Ammonite Repl 2.4.0 (Scala 2.12.13 Java 11.0.18)

I opened this issue here because don't know whether this is fansi issue, ammonite issue or common for both packages.

robcd commented 7 months ago

Hi. Something similar happens to me when I try to use the requests-scala library to .get an image file, from the repl cmdline - it works fine in a .sc script.

% amm Loading... Welcome to the Ammonite Repl 3.0.0-M1 (Scala 3.3.3 Java 21.0.2) @ val response = requests.get("https://httpbin.org/image/webp") java.lang.IllegalArgumentException: Unknown ansi-escape at index 754 inside string cannot be parsed into an fansi.Str