Table on Windows displays `?`
Code:
Terminal()
.println(table {
header { row("Column 1", "Column 2") }
body { row("1", "2") }
})
Result:
This happens when your terminal isn't rendering unicode characters. Make sure your file encoding is utf-8 and your terminal is also utf-8. You can also use ascii-only characters with borderType = BorderType.ASCII 1 2
I'm not sure there's anything mordant can do about that.
I managed to fix this in my app by setting the console output code page to 65001, using JNA.
https://github.com/juraj-hrivnak/Pakku/blob/main/src/commonMain/kotlin/teksturepako/pakku/cli/FixSystemOutEncoding.kt#L24-L28
Maybe Mordant could optionally do this?
FTR, in Amper we call this function in our RootCommand:
/**
* Some Windows encoding used by default doesn't support symbols used in `show dependencies` output
* Updating it to UTF-8 solves the issue.
*
* See https://github.com/ajalt/mordant/issues/249 for details.
*/
private fun fixSystemOutEncodingOnWindows() {
if ("win" !in System.getProperty("os.name").lowercase()) return
if (System.out.charset() == Charsets.UTF_8) return
// Set console code page to 65001 = UTF-8
val success = Kernel32.INSTANCE.SetConsoleOutputCP(65001)
if (success) {
// Replace System.out and System.err with PrintStreams using UTF-8
System.setOut(PrintStream(System.out, true, Charsets.UTF_8))
System.setErr(PrintStream(System.err, true, Charsets.UTF_8))
} else {
terminal.warning("Failed to set UTF-8 as console output encoding: ${Kernel32Util.getLastErrorMessage()}")
}
}