final Terminal terminal = new SshTerminal(env);
String encoding = env.getEnv().get("LC_CTYPE");
if (encoding != null && encoding.indexOf('.') > 0) {
encoding = encoding.substring(encoding.indexOf('.') + 1);
}
final Console console = new Console(commandProcessor,
threadIO,
in,
new PrintStream(new LfToCrLfFilterOutputStream(out), true),
new PrintStream(new LfToCrLfFilterOutputStream(err), true),
terminal,
encoding,
new Runnable() {
public void run() {
ShellImpl.this.destroy();
}
},
bundleContext);
final CommandSession session = console.getSession();
session.put("APPLICATION", System.getProperty("karaf.name", "root"));
for (Map.Entry<String,String> e : env.getEnv().entrySet()) {
session.put(e.getKey(), e.getValue());
}
session.put("#LINES", new Function() {
public Object execute(CommandSession session, List<Object> arguments) throws Exception {
return Integer.toString(terminal.getHeight());
}
});
session.put("#COLUMNS", new Function() {
public Object execute(CommandSession session, List<Object> arguments) throws Exception {
return Integer.toString(terminal.getWidth());
}
});
session.put(".jline.terminal", terminal);
console.run();
} catch (Exception e) {
LOGGER.warn("Unable to start shell", e);
}
}
}.start();