import java.util.List; /** * 作业2:HistoryCommand * 记录并展示用户输入过的所有命令(用 List 存储) */ public class HistoryCommand implements Command { private final ConsoleView view; private final List history; // 由 Controller 注入,共享同一个列表 public HistoryCommand(ConsoleView v, List history) { this.view = v; this.history = history; } @Override public String getName() { return "history"; } @Override public void execute(String[] args, List
articles) { if (history.isEmpty()) { view.printInfo("暂无历史记录。"); return; } view.printBold("── 历史命令 (" + history.size() + " 条) ──"); for (int i = 0; i < history.size(); i++) { view.printInfo(String.format("%3d %s", i + 1, history.get(i))); } } }