org.aesh.terminal.tty.Size Java Examples

The following examples show how to use org.aesh.terminal.tty.Size. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExecPty.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
@Override
public Size getSize() throws IOException {
    if (OSUtils.IS_HPUX) {
        return doGetOptimalSize(exec(OSUtils.STTY_COMMAND, "size"));
    } else if (OSUtils.IS_SUNOS) {
        String config = doGetConfig();
        return new Size(doGetInt("columns", config), doGetInt("rows", config));
    } else {
        try {
            return doGetOptimalSize(exec(OSUtils.STTY_COMMAND, OSUtils.STTY_F_OPTION, getName(), "size"));
        } catch (IOException ex) {
            // Try a fallback without -f
            return doGetOptimalSize(exec(OSUtils.STTY_COMMAND, "size"));
        }
    }

}
 
Example #2
Source File: LineDisciplineTerminal.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
public LineDisciplineTerminal(String name,
                              String type,
                              OutputStream masterOutput) throws IOException {
    super(name, type);
    PipedInputStream input = new LinePipedInputStream(PIPE_SIZE);
    this.slaveInputPipe = new PipedOutputStream(input);
    // This is a hack to fix a problem in gogo where closure closes
    // streams for commands if they are instances of PipedInputStream.
    // So we need to get around and make sure it's not an instance of
    // that class by using a dumb FilterInputStream class to wrap it.
    this.slaveInput = new FilterInputStream(input) {};
    this.slaveOutput = new FilteringOutputStream();
    this.masterOutput = masterOutput;
    this.attributes = new Attributes();
    this.size = new Size(160, 50);
}
 
Example #3
Source File: HttpTtyConnection.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public HttpTtyConnection(Charset charset, Size size) {
    this.charset = charset;
    this.size = size;
    this.eventDecoder = new EventDecoder(3, 4, 26);
    this.decoder = new Decoder(512, charset, eventDecoder);
    this.stdout = new TtyOutputMode(new Encoder(charset, this::write));

    this.device = new HttpDevice("vt100");
    attributes = new Attributes();
}
 
Example #4
Source File: TelnetTtyConnection.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Override
protected void onSize(int width, int height) {
  this.size = new Size(width, height);
  if (sizeHandler != null) {
    sizeHandler.accept(size);
  }
}
 
Example #5
Source File: TelnetTtyConnection.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Override
protected void onOpen(TelnetConnection conn) {
  this.conn = conn;

  //set default size for now
    size = new Size(80, 24);

  // Kludge mode
  conn.writeWillOption(Option.ECHO);
  conn.writeWillOption(Option.SGA);

  //
  if (inBinary) {
    conn.writeDoOption(Option.BINARY);
  }
  if (outBinary) {
    conn.writeWillOption(Option.BINARY);
  }

  // Window size
  conn.writeDoOption(Option.NAWS);

  // Get some info about user
  conn.writeDoOption(Option.TERMINAL_TYPE);

  attributes = new Attributes();

  //
  checkAccept();
}
 
Example #6
Source File: ExecPtyTest.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseSizeHPUX() throws IOException {
    if(Config.isOSPOSIXCompatible()) {
        String input = new String(Files.readAllBytes(
                Config.isOSPOSIXCompatible() ?
                        new File("src/test/resources/ttytype_hpux.txt").toPath() :
                        new File("src\\test\\resources\\ttytype_hpux.txt").toPath()));

        Size size = ExecPty.doGetHPUXSize(input);

        assertEquals(47, size.getHeight());
        assertEquals(112, size.getWidth());
    }
}
 
Example #7
Source File: ExecPtyTest.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseSize() throws IOException {
    assertEquals(new Size(244, 85), ExecPty.doGetSize(linuxSttySample));
    assertEquals(new Size(244, 85), ExecPty.doGetSize(solarisSttySample));
    assertEquals(new Size(244, 85), ExecPty.doGetSize(aixSttySample));
    assertEquals(new Size(244, 85), ExecPty.doGetSize(macOsSttySample));
    assertEquals(new Size(244, 85), ExecPty.doGetSize(netBsdSttySample));
    assertEquals(new Size(244, 85), ExecPty.doGetSize(freeBsdSttySample));
    assertEquals(new Size(244, 85), ExecPty.doGetSize(hpuxSttySample));
}
 
Example #8
Source File: ReadlineTest.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompleteResultsMultipleLines() {
    List<Completion> completions = new ArrayList<>();
    completions.add(completeOperation -> {
        if(completeOperation.getBuffer().equals("ff")) {
            completeOperation.addCompletionCandidate("ffoo");
        }
        else if(completeOperation.getBuffer().endsWith("f")) {
            completeOperation.addCompletionCandidate(completeOperation.getBuffer()+"oo");
        }
        else if(completeOperation.getBuffer().endsWith("foo")) {
            completeOperation.addCompletionCandidate(completeOperation.getBuffer()+"foo");
            completeOperation.addCompletionCandidate(completeOperation.getBuffer()+"foo bar");
        }
        else if(completeOperation.getBuffer().endsWith("b")) {
            completeOperation.addCompletionCandidate(completeOperation.getBuffer()+"bar bar");
            completeOperation.addCompletionCandidate(completeOperation.getBuffer()+"bar baar");
        }
    });

    Size termSize = new Size(10, 10);
    TestConnection term =
            new TestConnection(EditModeBuilder.builder().create(), completions, termSize);

    term.read("ff");
    term.read(Key.CTRL_I);
    term.assertBuffer("ffoo ");
    term.read(Key.ENTER);
    term.readline(completions);
    term.read("11111111111f");
    term.read(Key.CTRL_I);
    term.assertBuffer("11111111111foo ");
}
 
Example #9
Source File: ReadlineTest.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyPrompt() {
    TestConnection term = new TestConnection(new Prompt(""));
    term.read("foo");
    term.getSizeHandler().accept(new Size(80,80));

    assertEquals("foofoo", term.getOutputBuffer());
}
 
Example #10
Source File: TerminalUtil.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public static Size terminalSize() {
    TerminalConnection connection = terminal();
    if(connection != null)
        return connection.size();
    else
        return new Size(-1,-1);
}
 
Example #11
Source File: AbstractPosixTerminal.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public Size getSize() {
    try {
        return pty.getSize();
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #12
Source File: TtyCommand.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public Size size() {
    return size;
}
 
Example #13
Source File: TestConnection.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
public TestConnection(TestReadline readline, EditMode editMode, List<Completion> completions, Size size, Prompt prompt,
                       Attributes attributes, EnumMap<ReadlineFlag, Integer> flags) {
     if(editMode == null)
         editMode = EditModeBuilder.builder().create();
     bufferBuilder = new StringBuilder();
     stdOutHandler = ints ->
             bufferBuilder.append(Parser.stripAwayAnsiCodes(Parser.fromCodePoints(ints)));

     if(size == null)
         this.size = new Size(80, 20);
     else
         this.size = size;

     if(prompt != null)
         this.prompt = prompt;

     if(attributes != null)
         this.attributes = attributes;

     if(this.attributes != null)
         eventDecoder = new EventDecoder(this.attributes);
     else {
         eventDecoder = new EventDecoder();
         this.attributes = new Attributes();
     }

     device = DeviceBuilder.builder().name("ansi").build();
     decoder = new Decoder(512, Charset.defaultCharset(), eventDecoder);


     out = new LinkedList<>();
     if(readline == null) {
         this.readline = new TestReadline(editMode);
         if(completions != null)
             readline(completions);
         else if(flags != null)
             readline(flags);
         else
             readline();
     }
     else
         this.readline = readline;
}
 
Example #14
Source File: TestConnection.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public Consumer<Size> getSizeHandler() {
    return sizeHandler;
}
 
Example #15
Source File: TestConnection.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public void setSizeHandler(Consumer<Size> handler) {
    this.sizeHandler = handler;
}
 
Example #16
Source File: HttpTtyConnection.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
public void setSizeHandler(Consumer<Size> handler) {
    this.sizeHandler = handler;
}
 
Example #17
Source File: HttpTtyConnection.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
public Consumer<Size> getSizeHandler() {
    return sizeHandler;
}
 
Example #18
Source File: ConsoleBufferTest.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public Size size() {
    return new Size(80, 20);
}
 
Example #19
Source File: ConsoleBufferTest.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public Consumer<Size> getSizeHandler() {
    return null;
}
 
Example #20
Source File: TestConnection.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public Size size() {
    return size;
}
 
Example #21
Source File: TtyCommand.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public Consumer<Size> getSizeHandler() {
    return sizeHandler;
}
 
Example #22
Source File: TtyCommand.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public void setSizeHandler(Consumer<Size> handler) {
    sizeHandler = handler;
}
 
Example #23
Source File: HttpTtyConnection.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public Size size() {
    return size;
}
 
Example #24
Source File: TelnetTtyConnection.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public Size size() {
  return size;
}
 
Example #25
Source File: CliShell.java    From galleon with Apache License 2.0 4 votes vote down vote up
@Override
public Size size() {
    return connection.size();
}
 
Example #26
Source File: TelnetTtyConnection.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public Consumer<Size> getSizeHandler() {
  return sizeHandler;
}
 
Example #27
Source File: TelnetTtyConnection.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public void setSizeHandler(Consumer<Size> handler) {
  this.sizeHandler = handler;
}
 
Example #28
Source File: CLICommandInvocationBuilder.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public Size size() {
    return console == null ? new Size(80, 40) : console.getConnection().size();
}
 
Example #29
Source File: CygwinPty.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
static Size doGetSize(String cfg) throws IOException {
    return new Size(doGetInt("columns", cfg), doGetInt("rows", cfg));
}
 
Example #30
Source File: AeshConsoleBuffer.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public Size size() {
    return size;
}