You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

29 lines
930 B

import java.util.List;
/**
* 作业2:HistoryCommand
* 记录并展示用户输入过的所有命令(用 List<String> 存储)
*/
public class HistoryCommand implements Command {
private final ConsoleView view;
private final List<String> history; // 由 Controller 注入,共享同一个列表
public HistoryCommand(ConsoleView v, List<String> history) {
this.view = v;
this.history = history;
}
@Override public String getName() { return "history"; }
@Override
public void execute(String[] args, List<Article> 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)));
}
}
}