All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codetaco.appcontrol.ui.module.History Maven / Gradle / Ivy

The newest version!
package com.codetaco.appcontrol.ui.module;

import java.util.List;
import java.util.regex.Pattern;

import com.codetaco.appcontrol.ui.ExComContext;
import com.codetaco.appcontrol.ui.HistoryManager;
import com.codetaco.appcontrol.ui.HistoryManager.HistoryRecord;
import com.codetaco.appcontrol.ui.IPluginCommand;
import com.codetaco.argument.annotation.Arg;

/**
 * 

* History class. *

* * @author Chris DeGreef [email protected] */ public class History implements IPluginCommand { /** Constant GROUP="Menu.GROUP" */ static public final String GROUP = Menu.GROUP; /** Constant NAME="history" */ static public final String NAME = "history"; @Arg(shortName = 'm', help = "Only history matching all patterns will be displayed.", caseSensitive = true) private Pattern[] matches; @Arg(shortName = 'c', help = "Limit to this many rows of output.", range = { "1" }, defaultValues = "10") private int count; /** *

* Constructor for History. *

*/ public History() {} private boolean allMatchersMatch(final String output) { if (matches == null) return true; for (final Pattern pattern : matches) if (!pattern.matcher(output).find()) return false; return true; } /** {@inheritDoc} */ @Override public int execute(final ExComContext context) { int outputCount = 0; int startingPoint = 0; context.setRecordingHistory(false); final List history = HistoryManager.getInstance().getHistory(); /* * Scan backwards to know where to start showing when going in the * forward direction. */ for (startingPoint = history.size(); startingPoint > 0; startingPoint--) { final String output = history.get(startingPoint - 1).getContents(); if (allMatchersMatch(output)) if (++outputCount == count) break; } outputCount = 0; for (; startingPoint < history.size(); startingPoint++) { final String output = history.get(startingPoint).getContents(); if (allMatchersMatch(output)) context.getOutline().printf("%1$d: %2$s\n", startingPoint + 1, output); } return 0; } /** {@inheritDoc} */ @Override public String getGroup() { return GROUP; } /** {@inheritDoc} */ @Override public String getName() { return NAME; } /** {@inheritDoc} */ @Override public String getOverview() { return "Show / modify the history of commands"; } /** {@inheritDoc} */ @Override public boolean isOnceAndDone() { return false; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy