📄 commandhistory.java
字号:
package org.jnode.shell;
import java.util.Vector;
/** Used to keep an archive of commands.
* @author Matt Paine
*/
public class CommandHistory {
/** Holds the commands. **/
private Vector history = new Vector();
/** Constructs a CommandHistory object. **/
public CommandHistory() {
}
/** Adds a command to the archive.
* @param line The CommandLine to add to the archive.
**/
public void addCommand(String line) {
if( history.contains(line) )
history.remove(line);
history.add(line);
}
/** Returns the number of commands held in the archive.
* @return the number of commands held in the archive.
**/
public int size() {
return history.size();
}
/** Gets a command at a given index.
* TODO: make exception more specific
* @param index The index (starting at zero) of the command to return.
* @return The command at the index given or null if no command found
* (out of bounds index).
**/
public String getCommand(int index) {
String retCommand = null;
try {
retCommand = (String)history.get(index);
} catch (Exception ex) {
}
return retCommand;
}
/** Searches for the most recent command types starting with the specified
* string.
* @param start The string to search for.
* @return The most recent command matching the search string.
**/
public String getCommand(String start) {
return getCommand(findCommand(start));
}
/** Searches the collection for the most recent command starting with the
* specified string.
* @param start the string to search for.
* @return the index number of the specified string (or -1 if not found).
**/
private int findCommand(String start) {
for (int x = 0; x < history.size(); x++) {
String cmdLine = (String)history.get(x);
if (cmdLine != null)
if (cmdLine.startsWith(start))
return x;
}
return -1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -