sb.append(args[i]);
}
// Shell is directly executing a sub/command, we don't setup a terminal and console
// in this case, this avoids us reading from stdin un-necessarily.
CommandSession session = commandProcessor.createSession(in,out, err);
session.put("USER", user);
session.put("APPLICATION", application);
session.put(NameScoping.MULTI_SCOPE_MODE_KEY, Boolean.toString(isMultiScopeMode()));
try {
session.execute(sb);
} catch (Throwable t) {
if (t instanceof CommandException) {
session.getConsole().println(((CommandException) t).getNiceHelp());
} else {
session.getConsole().print(Ansi.ansi().fg(Ansi.Color.RED).toString());
t.printStackTrace(session.getConsole());
session.getConsole().print(Ansi.ansi().fg(Ansi.Color.DEFAULT).toString());
}
}
} else {
// We are going into full blown interactive shell mode.
TerminalFactory terminalFactory = new TerminalFactory();
Terminal terminal = terminalFactory.getTerminal();
Console console = createConsole(commandProcessor, in, out, err, terminal);
CommandSession session = console.getSession();
session.put("LINES", Integer.toString(terminal.getTerminalHeight()));
session.put("COLUMNS", Integer.toString(terminal.getTerminalWidth()));
session.put(".jline.terminal", terminal);
session.put("USER", user);
session.put("APPLICATION", application);
session.put(NameScoping.MULTI_SCOPE_MODE_KEY, Boolean.toString(isMultiScopeMode()));
console.run();
terminalFactory.destroy();
}
}