protected void doExecute(ConsoleExecutionContext ctx, CommandLine cl) throws Exception { // print the history Iterator iter = ctx.getConsole().getReader().getHistory().getHistoryList().iterator(); int i=1; while (iter.hasNext()) { System.out.println(" " + i + " " + iter.next()); i++; } }
@JRubyMethod(name = "pop") @SuppressWarnings("unchecked") public static IRubyObject s_pop(IRubyObject recv) throws Exception { Ruby runtime = recv.getRuntime(); ConsoleHolder holder = getHolder(runtime); List histList = holder.history.getHistoryList(); // TODO: Not fully implemented. We just return the last value, // without really popping it. String current = (String)histList.get(histList.size() - 1); return runtime.newString(current); }
try { int historyIndex = Integer.valueOf(line.substring(1).trim()).intValue(); oldLine = (String) reader.getHistory().getHistoryList().get(historyIndex - 1); } catch (Exception e) { System.out.println(" " + line + ": event not found");
@JRubyMethod(name = "to_a") public static IRubyObject s_hist_to_a(IRubyObject recv) throws Exception { ConsoleHolder holder = getHolder(recv.getRuntime()); RubyArray histList = recv.getRuntime().newArray(); for (Iterator i = holder.history.getHistoryList().iterator(); i.hasNext();) { histList.append(recv.getRuntime().newString((String) i.next())); } return histList; }
? new ArrayList(consoleHistory.getHistoryList()) : new ArrayList(0);
@JRubyMethod(name = "each") public static IRubyObject s_hist_each(IRubyObject recv, Block block) { ConsoleHolder holder = getHolder(recv.getRuntime()); for (Iterator i = holder.history.getHistoryList().iterator(); i.hasNext();) { block.yield(recv.getRuntime().getCurrentContext(), recv.getRuntime().newString((String) i.next())); } return recv; } }
public Object execute(final CommandContext context) throws Exception { assert context != null; IO io = context.getIo(); // HACK: Get at the shell's history from our variables History history = context.getVariables().get("gshell.internal.history", History.class); assert history != null; // noinspection unchecked List<String> elements = history.getHistoryList(); int i = 0; for (String element : elements) { String index = String.format("%3d", i); io.info(" {} {}", AnsiRenderer.encode(index, AnsiCode.BOLD), element); i++; } return Result.SUCCESS; } }
@JRubyMethod(name = "[]") public static IRubyObject s_hist_get(IRubyObject recv, IRubyObject index) { Ruby runtime = recv.getRuntime(); ConsoleHolder holder = getHolder(runtime); int i = (int) index.convertToInteger().getLongValue(); try { // TODO: MRI behavior is more complicated than that, // there is some magic when dealing with negative indexes. return runtime.newString((String) holder.history.getHistoryList().get(i)); } catch (IndexOutOfBoundsException ioobe) { throw runtime.newIndexError("invalid history index: " + i); } }
@Override protected Object doExecute() throws Exception { History history = (History) session.get(".jline.history"); List<String> elements = history.getHistoryList(); int i = 0; for (String element : elements) { System.out.println( Ansi.ansi() .a(" ") .a(Ansi.Attribute.INTENSITY_BOLD).render("%3d", i).a(Ansi.Attribute.INTENSITY_BOLD_OFF) .a(" ") .a(element) .toString()); i++; } return null; } }