use of org.apache.karaf.shell.impl.console.JLineTerminal in project karaf by apache.
the class Main method run.
private void run(final SessionFactory sessionFactory, String command, final InputStream in, final PrintStream out, final PrintStream err, ClassLoader cl) throws Exception {
try (org.jline.terminal.Terminal jlineTerminal = TerminalBuilder.terminal()) {
final Terminal terminal = new JLineTerminal(jlineTerminal);
try (Session session = createSession(sessionFactory, command.length() > 0 ? null : in, out, err, terminal)) {
session.put("USER", user);
session.put("APPLICATION", application);
discoverCommands(session, cl, getDiscoveryResource());
if (command.length() > 0) {
// Shell is directly executing a sub/command, we don't setup a console
// in this case, this avoids us reading from stdin un-necessarily.
session.put(NameScoping.MULTI_SCOPE_MODE_KEY, Boolean.toString(isMultiScopeMode()));
session.put(Session.PRINT_STACK_TRACES, "execution");
try {
session.execute(command);
} catch (Throwable t) {
ShellUtil.logException(session, t);
}
} else {
// We are going into full blown interactive shell mode.
session.run();
}
}
}
}
use of org.apache.karaf.shell.impl.console.JLineTerminal in project karaf by apache.
the class LocalConsoleManager method start.
public void start() throws Exception {
final Terminal terminal = TerminalBuilder.builder().nativeSignals(true).signalHandler(Terminal.SignalHandler.SIG_IGN).build();
final Subject subject = createLocalKarafSubject();
this.session = JaasHelper.doAs(subject, (PrivilegedAction<Session>) () -> {
String encoding = getEncoding();
session = sessionFactory.create(terminal.input(), new PrintStream(terminal.output()), new PrintStream(terminal.output()), new JLineTerminal(terminal), encoding, LocalConsoleManager.this::close);
session.put(Session.IS_LOCAL, true);
registration = bundleContext.registerService(Session.class, session, null);
String name = "Karaf local console user " + ShellUtil.getCurrentUserName();
boolean delayconsole = Boolean.parseBoolean(System.getProperty(KARAF_DELAY_CONSOLE));
if (delayconsole) {
watcher = new DelayedStarted(session, name, bundleContext, System.in);
new Thread(watcher, name).start();
} else {
new Thread(session, name).start();
}
return session;
});
// TODO: register the local session so that ssh can add the agent
// registration = bundleContext.register(CommandSession.class, console.getSession(), null);
}
Aggregations