
javarepl.console.commands.SearchHistory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javarepl Show documentation
Show all versions of javarepl Show documentation
Java REPL is a simple Read-Eval-Print-Loop for Java language.
package javarepl.console.commands;
import javarepl.completion.CommandCompleter;
import javarepl.console.ConsoleHistory;
import javarepl.console.ConsoleLogger;
import static com.googlecode.totallylazy.Strings.contains;
import static com.googlecode.totallylazy.Strings.startsWith;
import static javarepl.Utils.listValues;
import static javarepl.console.commands.ShowHistory.numberedHistory;
public final class SearchHistory extends Command {
private static final String COMMAND = ":h?";
private final ConsoleLogger logger;
private final ConsoleHistory history;
public SearchHistory(ConsoleLogger logger, ConsoleHistory history) {
super(COMMAND + " - searches the history", startsWith(COMMAND), new CommandCompleter(COMMAND));
this.logger = logger;
this.history = history;
}
public void execute(String expression) {
String searchTerm = parseStringCommand(expression).second().getOrElse("");
logger.success(listValues("History search for '" + searchTerm + "'", numberedHistory(history).filter(contains(searchTerm))));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy