org.jline.terminal.Size Java Examples
The following examples show how to use
org.jline.terminal.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: AbstractShellHelperTest.java From ssh-shell-spring-boot with Apache License 2.0 | 6 votes |
@BeforeEach public void each() { h = new SshShellHelper(); List<String> auth = Collections.singletonList("ROLE_ACTUATOR"); lr = mock(LineReader.class); ter = mock(Terminal.class); writer = mock(PrintWriter.class); when(ter.writer()).thenReturn(writer); reader = mock(NonBlockingReader.class); when(ter.reader()).thenReturn(reader); when(lr.getTerminal()).thenReturn(ter); SshContext ctx = new SshContext(new SshShellRunnable(new SshShellProperties(), mockChannelSession(4L), null, null, null, null, null, null, null, null, null, null, null, null), ter, lr, new SshAuthentication("user", "user", null, null, auth)); SshShellCommandFactory.SSH_THREAD_CONTEXT.set(ctx); when(ter.getType()).thenReturn("osx"); when(ter.getSize()).thenReturn(new Size(123, 40)); }
Example #2
Source File: ThreadCommandTest.java From ssh-shell-spring-boot with Apache License 2.0 | 6 votes |
@Test void threads() throws Exception { for (ThreadCommand.ThreadColumn tc : ThreadCommand.ThreadColumn.values()) { assertNotNull(t.threads(ThreadCommand.ThreadAction.LIST, tc, true, true, null)); } assertNotNull(t.threads(ThreadCommand.ThreadAction.DUMP, ThreadCommand.ThreadColumn.NAME, true, true, Thread.currentThread().getId())); assertThrows(IllegalArgumentException.class, () -> assertNotNull(t.threads(ThreadCommand.ThreadAction.DUMP, ThreadCommand.ThreadColumn.NAME, true, true, null))); assertThrows(IllegalArgumentException.class, () -> assertNotNull(t.threads(ThreadCommand.ThreadAction.DUMP, ThreadCommand.ThreadColumn.NAME, true, true, -1L))); when(reader.read(100L)).thenReturn(113); assertEquals("", t.threads(ThreadCommand.ThreadAction.LIST, ThreadCommand.ThreadColumn.NAME, true, false, null)); when(ter.getSize()).thenReturn(new Size(10, 10)); assertEquals("", t.threads(ThreadCommand.ThreadAction.LIST, ThreadCommand.ThreadColumn.NAME, true, false, null)); }
Example #3
Source File: RuntimeClient.java From tesb-studio-se with Apache License 2.0 | 6 votes |
private static void registerSignalHandler(final Terminal terminal, final PtyCapableChannelSession channel) { try { Class<?> signalClass = Class.forName("sun.misc.Signal"); Class<?> signalHandlerClass = Class.forName("sun.misc.SignalHandler"); // Implement signal handler Object signalHandler = Proxy.newProxyInstance(RuntimeClient.class.getClassLoader(), new Class<?>[] { signalHandlerClass }, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Size size = terminal.getSize(); channel.sendWindowChange(size.getColumns(), size.getRows()); return null; } }); signalClass.getMethod("handle", signalClass, signalHandlerClass).invoke(null, signalClass.getConstructor(String.class).newInstance("WINCH"), signalHandler); } catch (Exception e) { // Ignore this exception, if the above failed, the signal API is incompatible with what we're expecting } }
Example #4
Source File: AbstractCommandTest.java From ssh-shell-spring-boot with Apache License 2.0 | 5 votes |
protected void setCtx(String response) throws Exception { LineReader lr = mock(LineReader.class); Terminal t = mock(Terminal.class); when(lr.getTerminal()).thenReturn(t); when(t.getSize()).thenReturn(new Size(300, 20)); when(t.writer()).thenReturn(new PrintWriter("target/rh.tmp")); ParsedLine pl = mock(ParsedLine.class); when(pl.line()).thenReturn(response); when(lr.getParsedLine()).thenReturn(pl); SSH_THREAD_CONTEXT.set(new SshContext(null, t, lr, null)); }
Example #5
Source File: SshShellHelperTest.java From ssh-shell-spring-boot with Apache License 2.0 | 5 votes |
@Test void progress() { when(ter.getSize()).thenReturn(new Size(13, 40)); assertEquals("[> ]", h.progress(0)); assertEquals("[> ]", h.progress(1)); assertEquals("[=> ]", h.progress(10)); assertEquals("[========> ]", h.progress(80)); assertEquals("[========> ]", h.progress(40, 50)); assertEquals("[==========>]", h.progress(100)); assertEquals("[==========>]", h.progress(110)); when(ter.getSize()).thenReturn(new Size(2, 40)); assertEquals("", h.progress(40)); }
Example #6
Source File: SqlLineArgsTest.java From sqlline with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testTableOutputWithZeroMaxWidthAndExistingTerminal() { try { new MockUp<DumbTerminal>() { @Mock public Size getSize() { return new Size(80, 20); } }; final LineReaderBuilder lineReaderBuilder = LineReaderBuilder.builder() .parser(new SqlLineParser(sqlLine)) .terminal(TerminalBuilder.builder().dumb(true).build()); sqlLine.setLineReader(lineReaderBuilder.build()); final String script = "!set maxwidth 0\n" + "!set incremental true\n" + "values (1, cast(null as integer), cast(null as varchar(3)));\n"; checkScriptFile(script, false, equalTo(SqlLine.Status.OK), containsString( "+-------------+-------------+-----+\n" + "| C1 | C2 | C3 |\n" + "+-------------+-------------+-----+\n" + "| 1 | null | |\n" + "+-------------+-------------+-----+\n")); } catch (Exception e) { fail("Test failed with ", e); } }
Example #7
Source File: SqlLineArgsTest.java From sqlline with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testAnsiConsoleFormatWithZeroMaxWidthAndExistingTerminal() { try { new MockUp<DumbTerminal>() { @Mock public Size getSize() { return new Size(80, 20); } }; final LineReaderBuilder lineReaderBuilder = LineReaderBuilder.builder() .parser(new SqlLineParser(sqlLine)) .terminal(TerminalBuilder.builder().dumb(true).build()); sqlLine.setLineReader(lineReaderBuilder.build()); final String script = "!set maxwidth 0\n" + "!set incremental true \n" + "!set outputformat ansiconsole \n" + "!all \n" + "values \n" + "(1, '2') \n" + ";\n"; final String line1 = "" + "C1 C2\n" + "1 2 \n"; checkScriptFile(script, false, equalTo(SqlLine.Status.OK), containsString(line1)); } catch (Exception e) { fail("Test failed with ", e); } }
Example #8
Source File: SshShellHelper.java From ssh-shell-spring-boot with Apache License 2.0 | 4 votes |
@Deprecated public void interactive(InteractiveInput input, long delay, boolean fullScreen, Size size) { interactive(Interactive.builder().input(input).refreshDelay(delay).fullScreen(fullScreen).size(size).build()); }
Example #9
Source File: SystemCommandTest.java From ssh-shell-spring-boot with Apache License 2.0 | 4 votes |
@BeforeEach void setUp() { SshShellHelper helper = mock(SshShellHelper.class); when(helper.terminalSize()).thenReturn(new Size(100, 100)); cmd = new SystemCommand(helper); }
Example #10
Source File: SshShellHelper.java From ssh-shell-spring-boot with Apache License 2.0 | 2 votes |
/** * Get terminal size * * @return size */ public Size terminalSize() { return terminal().getSize(); }
Example #11
Source File: InteractiveInput.java From ssh-shell-spring-boot with Apache License 2.0 | 2 votes |
/** * Get lines to write * * @param size terminal size * @param currentDelay current refresh delay * @return lines */ List<AttributedString> getLines(Size size, long currentDelay);
Example #12
Source File: DemoCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 2 votes |
/** * Terminal size command example * * @return size */ @ShellMethod("Terminal size command") public Size size() { return helper.terminalSize(); }