本文整理了Java中org.fusesource.jansi.WindowsAnsiOutputStream
类的一些代码示例,展示了WindowsAnsiOutputStream
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WindowsAnsiOutputStream
类的具体详情如下:
包路径:org.fusesource.jansi.WindowsAnsiOutputStream
类名称:WindowsAnsiOutputStream
[英]A Windows ANSI escape processor, that uses JNA to access native platform API's to change the console attributes.
[中]Windows ANSI escape处理器,使用JNA访问本机平台API以更改控制台属性。
代码示例来源:origin: jline/jline
/**
* Returns an ansi output stream handler. We return whatever was
* passed if we determine we cannot handle ansi based on Kernel32 calls.
*
* @return an @{link AltWindowAnsiOutputStream} instance or the passed
* stream.
*/
private static OutputStream wrapOutputStream(final OutputStream stream) {
if (Configuration.isWindows()) {
// On windows we know the console does not interpret ANSI codes..
try {
return new WindowsAnsiOutputStream(stream);
} catch (Throwable ignore) {
// this happens when JNA is not in the path.. or
// this happens when the stdout is being redirected to a file.
}
// Use the ANSIOutputStream to strip out the ANSI escape sequences.
return new AnsiOutputStream(stream);
}
return stream;
}
代码示例来源:origin: org.fusesource.jansi/jansi
@Override
protected void processSetBackgroundColor(int color, boolean bright) throws IOException {
info.attributes = (short) ((info.attributes & ~0x0070) | ANSI_BACKGROUND_COLOR_MAP[color]);
if (bright) {
info.attributes |= BACKGROUND_INTENSITY;
}
applyAttribute();
}
代码示例来源:origin: org.fusesource.jansi/jansi
@Override
protected void processCursorUp(int count) throws IOException {
getConsoleInfo();
info.cursorPosition.y = (short) Math.max(info.window.top, info.cursorPosition.y - count);
applyCursorPosition();
}
代码示例来源:origin: org.fusesource.jansi/jansi
public WindowsAnsiOutputStream(OutputStream os) throws IOException { // expected diff with WindowsAnsiPrintStream.java
super(os); // expected diff with WindowsAnsiPrintStream.java
getConsoleInfo();
originalColors = info.attributes;
}
代码示例来源:origin: org.fusesource.jansi/jansi
private void getConsoleInfo() throws IOException {
out.flush(); // expected diff with WindowsAnsiPrintStream.java
if (GetConsoleScreenBufferInfo(console, info) == 0) {
throw new IOException("Could not get the screen info: " + WindowsSupport.getLastErrorMessage());
}
if (negative) {
info.attributes = invertAttributeColors(info.attributes);
}
}
代码示例来源:origin: org.fusesource.jansi/jansi
@Override
protected void processRestoreCursorPosition() throws IOException {
// restore only if there was a save operation first
if (savedX != -1 && savedY != -1) {
out.flush(); // expected diff with WindowsAnsiPrintStream.java
info.cursorPosition.x = savedX;
info.cursorPosition.y = savedY;
applyCursorPosition();
}
}
代码示例来源:origin: org.fusesource.jansi/jansi
@Override
protected void processSaveCursorPosition() throws IOException {
getConsoleInfo();
savedX = info.cursorPosition.x;
savedY = info.cursorPosition.y;
}
代码示例来源:origin: org.fusesource.jansi/jansi
private void applyAttribute() throws IOException {
out.flush(); // expected diff with WindowsAnsiPrintStream.java
short attributes = info.attributes;
if (negative) {
attributes = invertAttributeColors(attributes);
}
if (SetConsoleTextAttribute(console, attributes) == 0) {
throw new IOException(WindowsSupport.getLastErrorMessage());
}
}
代码示例来源:origin: locationtech/geogig
public boolean checkAnsiSupported(OutputStream out, String osName) throws Throwable {
if (out != System.out) {
return false;
}
if (osName.startsWith("windows") && osName.endsWith("10")) {
new WindowsAnsiOutputStream(out);
} else if (osName.startsWith("windows") && !osName.endsWith("10")) {
return false;
}
if (System.console() == null) {
return false;
}
return true;
}
代码示例来源:origin: org.fusesource.jansi/jansi
@Override
protected void processCursorLeft(int count) throws IOException {
getConsoleInfo();
info.cursorPosition.x = (short) Math.max(0, info.cursorPosition.x - count);
applyCursorPosition();
}
代码示例来源:origin: org.fusesource.jansi/jansi
@Override
protected void processAttributeRest() throws IOException {
info.attributes = (short) ((info.attributes & ~0x00FF) | originalColors);
this.negative = false;
applyAttribute();
}
代码示例来源:origin: org.fusesource.jansi/jansi
@Override
protected void processDeleteLine(int optionInt) throws IOException {
getConsoleInfo();
SMALL_RECT scroll = info.window.copy();
scroll.top = info.cursorPosition.y;
COORD org = new COORD();
org.x = 0;
org.y = (short)(info.cursorPosition.y - optionInt);
CHAR_INFO info = new CHAR_INFO();
info.attributes = originalColors;
info.unicodeChar = ' ';
if (ScrollConsoleScreenBuffer(console, scroll, scroll, org, info) == 0) {
throw new IOException(WindowsSupport.getLastErrorMessage());
}
}
代码示例来源:origin: org.locationtech.geogig/geogig-cli-core
public boolean checkAnsiSupported(OutputStream out, String osName) throws Throwable {
if (out != System.out) {
return false;
}
if (osName.startsWith("windows") && osName.endsWith("10")) {
new WindowsAnsiOutputStream(out);
} else if (osName.startsWith("windows") && !osName.endsWith("10")) {
return false;
}
if (System.console() == null) {
return false;
}
return true;
}
代码示例来源:origin: org.fusesource.jansi/jansi
@Override
protected void processCursorDown(int count) throws IOException {
getConsoleInfo();
info.cursorPosition.y = (short) Math.min(Math.max(0, info.size.y - 1), info.cursorPosition.y + count);
applyCursorPosition();
}
代码示例来源:origin: org.fusesource.jansi/jansi
@Override
protected void processSetForegroundColor(int color, boolean bright) throws IOException {
info.attributes = (short) ((info.attributes & ~0x0007) | ANSI_FOREGROUND_COLOR_MAP[color]);
if (bright) {
info.attributes |= FOREGROUND_INTENSITY;
}
applyAttribute();
}
代码示例来源:origin: org.fusesource.jansi/jansi
@Override
protected void processInsertLine(int optionInt) throws IOException {
getConsoleInfo();
SMALL_RECT scroll = info.window.copy();
scroll.top = info.cursorPosition.y;
COORD org = new COORD();
org.x = 0;
org.y = (short)(info.cursorPosition.y + optionInt);
CHAR_INFO info = new CHAR_INFO();
info.attributes = originalColors;
info.unicodeChar = ' ';
if (ScrollConsoleScreenBuffer(console, scroll, scroll, org, info) == 0) {
throw new IOException(WindowsSupport.getLastErrorMessage());
}
}
代码示例来源:origin: org.locationtech.geogig/geogig-cli
public boolean checkAnsiSupported(OutputStream out, String osName) throws Throwable {
if (out != System.out) {
return false;
}
if (osName.startsWith("windows") && osName.endsWith("10")) {
new WindowsAnsiOutputStream(out);
} else if (osName.startsWith("windows") && !osName.endsWith("10")) {
return false;
}
if (System.console() == null) {
return false;
}
return true;
}
代码示例来源:origin: org.fusesource.jansi/jansi
@Override
protected void processCursorRight(int count) throws IOException {
getConsoleInfo();
info.cursorPosition.x = (short) Math.min(info.window.width(), info.cursorPosition.x + count);
applyCursorPosition();
}
代码示例来源:origin: org.fusesource.jansi/jansi
@Override
protected void processDefaultTextColor() throws IOException {
info.attributes = (short) ((info.attributes & ~0x000F) | (originalColors & 0xF));
info.attributes = (short) (info.attributes & ~FOREGROUND_INTENSITY);
applyAttribute();
}
代码示例来源:origin: org.fusesource.jansi/jansi
@Override
protected void processEraseLine(int eraseOption) throws IOException {
getConsoleInfo();
int[] written = new int[1];
switch (eraseOption) {
case ERASE_LINE:
COORD leftColCurrRow = info.cursorPosition.copy();
leftColCurrRow.x = 0;
FillConsoleOutputAttribute(console, originalColors, info.size.x, leftColCurrRow, written);
FillConsoleOutputCharacterW(console, ' ', info.size.x, leftColCurrRow, written);
break;
case ERASE_LINE_TO_BEGINING:
COORD leftColCurrRow2 = info.cursorPosition.copy();
leftColCurrRow2.x = 0;
FillConsoleOutputAttribute(console, originalColors, info.cursorPosition.x, leftColCurrRow2, written);
FillConsoleOutputCharacterW(console, ' ', info.cursorPosition.x, leftColCurrRow2, written);
break;
case ERASE_LINE_TO_END:
int lengthToLastCol = info.size.x - info.cursorPosition.x;
FillConsoleOutputAttribute(console, originalColors, lengthToLastCol, info.cursorPosition.copy(), written);
FillConsoleOutputCharacterW(console, ' ', lengthToLastCol, info.cursorPosition.copy(), written);
break;
default:
break;
}
}
内容来源于网络,如有侵权,请联系作者删除!