use of org.jline.terminal.Terminal in project flink by apache.
the class CliClientITCase method runSqlStatements.
/**
* Returns printed results for each ran SQL statements.
*
* @param statements the SQL statements to run
* @return the printed results on SQL Client
*/
private List<Result> runSqlStatements(List<String> statements) throws IOException {
final String sqlContent = String.join("", statements);
DefaultContext defaultContext = new DefaultContext(Collections.emptyList(), new Configuration(MINI_CLUSTER_RESOURCE.getClientConfiguration()).set(ExecutionConfigOptions.TABLE_EXEC_LEGACY_CAST_BEHAVIOUR, ExecutionConfigOptions.LegacyCastBehaviour.DISABLED), Collections.singletonList(new DefaultCLI()));
final Executor executor = new LocalExecutor(defaultContext);
InputStream inputStream = new ByteArrayInputStream(sqlContent.getBytes());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
String sessionId = executor.openSession("test-session");
try (Terminal terminal = new DumbTerminal(inputStream, outputStream);
CliClient client = new CliClient(() -> terminal, sessionId, executor, historyPath, HideSqlStatement.INSTANCE)) {
client.executeInInteractiveMode();
String output = new String(outputStream.toByteArray());
return normalizeOutput(output);
}
}
use of org.jline.terminal.Terminal in project flink by apache.
the class CliClientTest method testHistoryFile.
@Test
public void testHistoryFile() throws Exception {
final MockExecutor mockExecutor = new MockExecutor();
String sessionId = mockExecutor.openSession("test-session");
InputStream inputStream = new ByteArrayInputStream("help;\nuse catalog cat;\n".getBytes());
Path historyFilePath = historyTempFile();
try (Terminal terminal = new DumbTerminal(inputStream, new TerminalUtils.MockOutputStream());
CliClient client = new CliClient(() -> terminal, sessionId, mockExecutor, historyFilePath, null)) {
client.executeInInteractiveMode();
List<String> content = Files.readAllLines(historyFilePath);
assertThat(content.size()).isEqualTo(2);
assertThat(content.get(0)).contains("help");
assertThat(content.get(1)).contains("use catalog cat");
}
}
use of org.jline.terminal.Terminal in project flink by apache.
the class CliView method unsetTerminalFullScreen.
private void unsetTerminalFullScreen() {
final Terminal terminal = client.getTerminal();
terminal.puts(Capability.exit_ca_mode);
terminal.puts(Capability.keypad_local);
terminal.puts(Capability.cursor_visible);
}
use of org.jline.terminal.Terminal in project flink by apache.
the class CliView method restoreTerminal.
private void restoreTerminal(Tuple2<Attributes, Map<Signal, SignalHandler>> prev) {
final Terminal terminal = client.getTerminal();
terminal.setAttributes(prev.f0);
prev.f1.forEach(terminal::handle);
}
use of org.jline.terminal.Terminal in project flink by apache.
the class CliView method prepareTerminal.
private Tuple2<Attributes, Map<Signal, SignalHandler>> prepareTerminal() {
final Terminal terminal = client.getTerminal();
final Attributes prevAttributes = terminal.getAttributes();
// adopted from org.jline.builtins.Nano
// see also
// https://en.wikibooks.org/wiki/Serial_Programming/termios#Basic_Configuration_of_a_Serial_Interface
// no line processing
// canonical mode off, echo off, echo newline off, extended input processing off
Attributes newAttr = new Attributes(prevAttributes);
newAttr.setLocalFlags(EnumSet.of(LocalFlag.ICANON, LocalFlag.ECHO, LocalFlag.IEXTEN), false);
// turn off input processing
newAttr.setInputFlags(EnumSet.of(Attributes.InputFlag.IXON, Attributes.InputFlag.ICRNL, Attributes.InputFlag.INLCR), false);
// one input byte is enough to return from read, inter-character timer off
newAttr.setControlChar(Attributes.ControlChar.VMIN, 1);
newAttr.setControlChar(Attributes.ControlChar.VTIME, 0);
newAttr.setControlChar(Attributes.ControlChar.VINTR, 0);
terminal.setAttributes(newAttr);
final Map<Signal, SignalHandler> prevSignals = new HashMap<>();
prevSignals.put(Signal.WINCH, terminal.handle(Signal.WINCH, this::handleSignal));
prevSignals.put(Signal.INT, terminal.handle(Signal.INT, this::handleSignal));
prevSignals.put(Signal.QUIT, terminal.handle(Signal.QUIT, this::handleSignal));
return Tuple2.of(prevAttributes, prevSignals);
}
Aggregations