jline.WindowsTerminal类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中jline.WindowsTerminal类的一些代码示例,展示了WindowsTerminal类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WindowsTerminal类的具体详情如下:
包路径:jline.WindowsTerminal
类名称:WindowsTerminal

WindowsTerminal介绍

[英]Terminal implementation for Microsoft Windows. Terminal initialization in #init is accomplished by extracting the jline_version.dll, saving it to the system temporary directoy (determined by the setting of the java.io.tmpdir System property), loading the library, and then calling the Win32 APIs [SetConsoleMode](http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dllproc/base/setconsolemode.asp) and [GetConsoleMode](http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dllproc/base/getconsolemode.asp) to disable character echoing.

By default, the #wrapInIfNeeded(java.io.InputStream) method will attempt to test to see if the specified InputStream is System#in or a wrapper around FileDescriptor#in, and if so, will bypass the character reading to directly invoke the readc() method in the JNI library. This is so the class can read special keys (like arrow keys) which are otherwise inaccessible via the System#in stream. Using JNI reading can be bypassed by setting the jline.WindowsTerminal.directConsole system property to false.
[中]Microsoft Windows的终端实现。#init中的终端初始化是通过提取jline_版本来完成的。dll,将其保存到系统临时目录(由java.io.tmpdir系统属性的设置确定),加载库,然后调用Win32 API[SetConsoleMode](http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dllproc/base/setconsolemode.asp)和{$1$}来禁用字符回音。
默认情况下,#wrapinifRequired(java.io.InputStream)方法将尝试测试指定的InputStream是System#in还是FileDescriptor#in的包装器,如果是,将绕过字符读取直接调用JNI库中的readc()方法。这样,该类就可以读取特殊的键(如箭头键),否则无法通过流中的系统访问这些键。通过将jline.WindowsTerminal.directConsole系统属性设置为false,可以绕过使用JNI读取。

代码示例

代码示例来源:origin: jline/jline

@Override
public void init() throws Exception {
  super.init();
  setAnsiSupported(Configuration.getBoolean(ANSI, true));
  //
  // FIXME: Need a way to disable direct console and sysin detection muck
  //
  setDirectConsole(Configuration.getBoolean(DIRECT_CONSOLE, true));
  this.originalMode = getConsoleMode();
  setConsoleMode(originalMode & ~ENABLE_ECHO_INPUT.code);
  setEchoEnabled(false);
}

代码示例来源:origin: jline/jline

@Override
public int getHeight() {
  int h = getWindowsTerminalHeight();
  return h < 1 ? DEFAULT_HEIGHT : h;
}

代码示例来源:origin: jline/jline

@Override
public int getWidth() {
  int w = getWindowsTerminalWidth();
  return w < 1 ? DEFAULT_WIDTH : w;
}

代码示例来源:origin: jline/jline

public void disableInterruptCharacter() {
  setConsoleMode(getConsoleMode() &
    ~(ENABLE_PROCESSED_INPUT.code));
}

代码示例来源:origin: jline/jline

/**
 * Restore the original terminal configuration, which can be used when
 * shutting down the console reader. The ConsoleReader cannot be
 * used after calling this method.
 */
@Override
public void restore() throws Exception {
  // restore the old console mode
  setConsoleMode(originalMode);
  super.restore();
}

代码示例来源:origin: jline/jline

@Override
public String getOutputEncoding() {
  int codepage = getConsoleOutputCodepage();
  //http://docs.oracle.com/javase/6/docs/technotes/guides/intl/encoding.doc.html
  String charsetMS = "ms" + codepage;
  if (java.nio.charset.Charset.isSupported(charsetMS)) {
    return charsetMS;
  }
  String charsetCP = "cp" + codepage;
  if (java.nio.charset.Charset.isSupported(charsetCP)) {
    return charsetCP;
  }
  Log.debug("can't figure out the Java Charset of this code page (" + codepage + ")...");
  return super.getOutputEncoding();
}

代码示例来源:origin: jline/jline

@Override
public InputStream wrapInIfNeeded(InputStream in) throws IOException {
  if (directConsole && isSystemIn(in)) {
    return new InputStream() {
      private byte[] buf = null;
      int bufIdx = 0;
      @Override
      public int read() throws IOException {
        while (buf == null || bufIdx == buf.length) {
          buf = readConsoleInput();
          bufIdx = 0;
        }
        int c = buf[bufIdx] & 0xFF;
        bufIdx++;
        return c;
      }
    };
  } else {
    return super.wrapInIfNeeded(in);
  }
}

代码示例来源:origin: org.apache.geronimo.gshell.support/gshell-terminal

@Override
  public int getTerminalWidth() {
    int width = super.getTerminalWidth();
    if (width < 1) {
      width = 80;
    }
    return width;
  }
}

代码示例来源:origin: jline/jline

public void enableInterruptCharacter() {
  setConsoleMode(getConsoleMode() |
    ENABLE_PROCESSED_INPUT.code);
}

代码示例来源:origin: com.typesafe.sbt/incremental-compiler

/**
 * Restore the original terminal configuration, which can be used when
 * shutting down the console reader. The ConsoleReader cannot be
 * used after calling this method.
 */
@Override
public void restore() throws Exception {
  // restore the old console mode
  setConsoleMode(originalMode);
  super.restore();
}

代码示例来源:origin: com.typesafe.sbt/incremental-compiler

@Override
public String getOutputEncoding() {
  int codepage = getConsoleOutputCodepage();
  //http://docs.oracle.com/javase/6/docs/technotes/guides/intl/encoding.doc.html
  String charsetMS = "ms" + codepage;
  if (java.nio.charset.Charset.isSupported(charsetMS)) {
    return charsetMS;
  }
  String charsetCP = "cp" + codepage;
  if (java.nio.charset.Charset.isSupported(charsetCP)) {
    return charsetCP;
  }
  Log.debug("can't figure out the Java Charset of this code page (" + codepage + ")...");
  return super.getOutputEncoding();
}

代码示例来源:origin: com.typesafe.sbt/incremental-compiler

@Override
public InputStream wrapInIfNeeded(InputStream in) throws IOException {
  if (directConsole && isSystemIn(in)) {
    return new InputStream() {
      private byte[] buf = null;
      int bufIdx = 0;
      @Override
      public int read() throws IOException {
        while (buf == null || bufIdx == buf.length) {
          buf = readConsoleInput();
          bufIdx = 0;
        }
        int c = buf[bufIdx] & 0xFF;
        bufIdx++;
        return c;
      }
    };
  } else {
    return super.wrapInIfNeeded(in);
  }
}

代码示例来源:origin: org.apache.servicemix.kernel.gshell/org.apache.servicemix.kernel.gshell.core

@Override
  public int getTerminalWidth() {
    int width = super.getTerminalWidth();
    if (width < 1) {
      width = 80;
    }
    return width;
  }
}

代码示例来源:origin: com.typesafe.sbt/incremental-compiler

@Override
public void init() throws Exception {
  super.init();
  setAnsiSupported(Configuration.getBoolean(ANSI, true));
  //
  // FIXME: Need a way to disable direct console and sysin detection muck
  //
  setDirectConsole(Configuration.getBoolean(DIRECT_CONSOLE, true));
  this.originalMode = getConsoleMode();
  setConsoleMode(originalMode & ~ENABLE_ECHO_INPUT.code);
  setEchoEnabled(false);
}

代码示例来源:origin: jline/jline

@Override
public void setEchoEnabled(final boolean enabled) {
  // Must set these four modes at the same time to make it work fine.
  if (enabled) {
    setConsoleMode(getConsoleMode() |
      ENABLE_ECHO_INPUT.code |
      ENABLE_LINE_INPUT.code |
      ENABLE_WINDOW_INPUT.code);
  }
  else {
    setConsoleMode(getConsoleMode() &
      ~(ENABLE_LINE_INPUT.code |
        ENABLE_ECHO_INPUT.code |
        ENABLE_WINDOW_INPUT.code));
  }
  super.setEchoEnabled(enabled);
}

代码示例来源:origin: com.typesafe.sbt/incremental-compiler

@Override
public int getHeight() {
  int h = getWindowsTerminalHeight();
  return h < 1 ? DEFAULT_HEIGHT : h;
}

代码示例来源:origin: com.typesafe.sbt/incremental-compiler

@Override
public int getWidth() {
  int w = getWindowsTerminalWidth();
  return w < 1 ? DEFAULT_WIDTH : w;
}

代码示例来源:origin: com.typesafe.sbt/incremental-compiler

public void disableInterruptCharacter() {
  setConsoleMode(getConsoleMode() &
    ~(ENABLE_PROCESSED_INPUT.code));
}

代码示例来源:origin: com.typesafe.sbt/incremental-compiler

public void enableInterruptCharacter() {
  setConsoleMode(getConsoleMode() |
    ENABLE_PROCESSED_INPUT.code);
}

代码示例来源:origin: com.typesafe.sbt/incremental-compiler

@Override
public void setEchoEnabled(final boolean enabled) {
  // Must set these four modes at the same time to make it work fine.
  if (enabled) {
    setConsoleMode(getConsoleMode() |
      ENABLE_ECHO_INPUT.code |
      ENABLE_LINE_INPUT.code |
      ENABLE_WINDOW_INPUT.code);
  }
  else {
    setConsoleMode(getConsoleMode() &
      ~(ENABLE_LINE_INPUT.code |
        ENABLE_ECHO_INPUT.code |
        ENABLE_WINDOW_INPUT.code));
  }
  super.setEchoEnabled(enabled);
}

相关文章