I recently had a look at ansi, and I saw libraries...
# announcements
a
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
Kotlin does not have octal escapes like java does.
a
So any java library that uses octal escapes also isn’t supported?
n
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
Thanks. I have no idea what happened but now everything works.
r
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
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