本文整理匯總了Java中jline.console.history.PersistentHistory類的典型用法代碼示例。如果您正苦於以下問題:Java PersistentHistory類的具體用法?Java PersistentHistory怎麽用?Java PersistentHistory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PersistentHistory類屬於jline.console.history包,在下文中一共展示了PersistentHistory類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: terminate
import jline.console.history.PersistentHistory; //導入依賴的package包/類
public void terminate(boolean terminatedByUser) throws Exception
{
if (!mRunning) {
return;
}
if (mConsoleReader.getHistory() instanceof PersistentHistory) {
try {
((PersistentHistory) mConsoleReader.getHistory()).flush();
}
catch (IOException e) {
error(e.getMessage());
}
}
mRunning = false;
mConsoleSession.destroy();
mPipeThread.interrupt();
if (terminatedByUser) {
info("Terminated by user. Good bye."); //$NON-NLS-1$
}
}
示例2: runShell
import jline.console.history.PersistentHistory; //導入依賴的package包/類
public int runShell() throws Exception {
String raw;
String line;
StringBuffer accumulatedLine = new StringBuffer();
String prompt = "tajo";
String curPrompt = prompt;
boolean newStatement = true;
int code = 0;
sout.write("Try \\? for help.\n");
while((raw = reader.readLine(curPrompt + "> ")) != null) {
// each accumulated line has a space delimiter
if (accumulatedLine.length() > 0) {
accumulatedLine.append(' ');
}
line = raw.trim();
if (line.length() == 0) { // if empty line
continue;
} else if (line.charAt(0) == '/') { // warning for legacy usage
printInvalidCommand(line);
continue;
} else if (line.charAt(0) == '\\') { // command mode
((PersistentHistory)reader.getHistory()).flush();
executeCommand(line);
} else if (line.endsWith(";") && !line.endsWith("\\;")) {
// remove a trailing newline
line = StringUtils.chomp(line).trim();
// get a punctuated statement
String punctuated = accumulatedLine + line;
if (!newStatement) {
// why do two lines are removed?
// First history line indicates an accumulated line.
// Second history line is a just typed line.
reader.getHistory().removeLast();
reader.getHistory().removeLast();
reader.getHistory().add(punctuated);
((PersistentHistory)reader.getHistory()).flush();
}
code = executeStatements(punctuated);
// reset accumulated lines
newStatement = true;
accumulatedLine = new StringBuffer();
curPrompt = prompt;
} else {
line = StringUtils.chomp(raw).trim();
// accumulate a line
accumulatedLine.append(line);
// replace the latest line with a accumulated line
if (!newStatement) { // if this is not first line, remove one more line.
reader.getHistory().removeLast();
} else {
newStatement = false;
}
reader.getHistory().removeLast();
reader.getHistory().add(accumulatedLine.toString());
// use an alternative prompt during accumulating lines
curPrompt = StringUtils.repeat(" ", prompt.length());
continue;
}
}
return code;
}