https://kotlinlang.org logo
#announcements
Title
# announcements
a

Allan Wang

06/22/2019, 6:47 AM
I recently had a look at ansi, and I saw libraries like jansi. They use escape codes such as
"\033[0m"
in java. However, it doesn’t seem to be a valid string in kotlin. Using the library also doesn’t seem to work for me, whereas if I replace
\033
with
\u001B
, everything works fine. Is there a reason for this, or a reason why the library doesn’t work when it is used?
y

yawkat

06/22/2019, 12:47 PM
Kotlin does not have octal escapes like java does.
a

Allan Wang

06/22/2019, 6:23 PM
So any java library that uses octal escapes also isn’t supported?
n

nulldev

06/23/2019, 5:26 AM
No, octal escapes are compiled into their character representations when the library is built. So when using a Java library, Kotlin would see the character representation (which Kotlin can understand just fine) instead of the octal escape.
a

Allan Wang

06/23/2019, 7:33 PM
Thanks. I have no idea what happened but now everything works.
r

Ryan Mentley

06/24/2019, 6:24 PM
The degree to which Java compiles the escapes into characters can be surprising, too...
Copy code
$ cat Test.java && echo -e "\n" && javac Test.java && javap Test.class
\u0070\u0075\u0062\u006c\u0069\u0063
\u0063\u006c\u0061\u0073\u0073\u0020\u0054\u0065\u0073\u0074
\u007b\u007d

Compiled from "Test.java"
public class Test {
  public Test();
}
a

Allan Wang

06/24/2019, 6:37 PM
Looking back I realized there was something wrong with the library. They have an install and uninstall function that checks for ascii support and I guess they detected the wrong setting and used another format. Using system out worked as is
35 Views