Skip to content

Commit

Permalink
Fix things for #133
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jun 16, 2017
1 parent cc688bd commit ae265f7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.IOException;
import java.util.function.IntConsumer;

import com.sun.jna.LastErrorException;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import org.jline.terminal.Cursor;
Expand Down Expand Up @@ -45,7 +46,12 @@ protected int getConsoleOutputCP() {

@Override
protected void setConsoleOutputCP(int cp) {
Kernel32.INSTANCE.SetConsoleCP(cp);
try {
Kernel32.INSTANCE.SetConsoleOutputCP(cp);
} catch (LastErrorException e) {
// Not sure why it throws exceptions, just log at trace
Log.trace("Error setting console output code page", e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ interface Kernel32 extends StdCallLibrary {
// HWND WINAPI GetConsoleWindow(void);
Pointer GetConsoleWindow();

// UINT WINAPI GetConsoleCP(void)
int GetConsoleCP();

// UINT WINAPI GetConsoleOutputCP(void)
int GetConsoleOutputCP();

Expand Down Expand Up @@ -188,6 +191,10 @@ void SetConsoleCursorInfo(Pointer in_hConsoleOutput,
// _In_ UINT wCodePageID);
void SetConsoleCP(int in_wCodePageID) throws LastErrorException;

// BOOL WINAPI SetConsoleOutputCP(
// _In_ UINT wCodePageID);
void SetConsoleOutputCP(int in_wCodePageID) throws LastErrorException;

// BOOL WINAPI SetConsoleCursorPosition(
// _In_ HANDLE hConsoleOutput,
// _In_ COORD dwCursorPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.jline.utils.ShutdownHooks;
import org.jline.utils.Signals;

import java.io.BufferedWriter;
import java.io.BufferedOutputStream;
import java.io.FilterInputStream;
import java.io.InputStream;
import java.io.IOError;
Expand Down Expand Up @@ -70,7 +70,7 @@ public AbstractWindowsTerminal(OutputStream output, String name, boolean nativeS
this.consoleOutputCP = getConsoleOutputCP();
setConsoleOutputCP(CODE_PAGE);
this.reader = new NonBlockingReader(getName(), new org.jline.utils.InputStreamReader(input, CHARSET));
this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(output, CHARSET)));
this.writer = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(output), CHARSET));
parseInfoCmp();
// Attributes
attributes.setLocalFlag(Attributes.LocalFlag.ISIG, true);
Expand Down

0 comments on commit ae265f7

Please sign in to comment.