Commit 1a85d58
committed
fix: Restore Windows console codepage auto-detection (fixes #1366)
Unicode box-drawing characters have been rendering as garbage on Windows
cmd.exe and PowerShell since JLine 3.22.0 (October 2020).
Root cause: In commit 5739bab, the getConsoleOutputCP() method was removed,
eliminating automatic Windows console codepage detection. JLine defaulted to
UTF-8, but Windows consoles often use CP437, CP850, CP936, etc.
This fix restores codepage auto-detection:
- Added getConsoleCodepage() method that uses reflection to call
Kernel32.GetConsoleOutputCP() from JNI or FFM providers
- Modified computeEncoding() to auto-detect Windows codepage when:
* Running on native Windows (not Cygwin/MSYS)
* No explicit codepage is set
* Falls back gracefully if native providers aren't available
Encoding detection priority (after fix):
1. Explicitly set encoding field
2. System property org.jline.terminal.encoding
3. Explicitly set codepage field
4. System property org.jline.terminal.codepage
5. Auto-detected Windows codepage (NEW)
6. UTF-8 (default fallback)1 parent 3580251 commit 1a85d58
File tree
1 file changed
+32
-0
lines changed- terminal/src/main/java/org/jline/terminal
1 file changed
+32
-0
lines changedLines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1004 | 1004 | | |
1005 | 1005 | | |
1006 | 1006 | | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
1007 | 1011 | | |
1008 | 1012 | | |
1009 | 1013 | | |
| |||
1166 | 1170 | | |
1167 | 1171 | | |
1168 | 1172 | | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
1169 | 1201 | | |
1170 | 1202 | | |
1171 | 1203 | | |
| |||
0 commit comments