ヒストリ機能を付加しようと修正中。
@@ -15,6 +15,7 @@ | ||
15 | 15 | import java.util.ArrayList; |
16 | 16 | import java.util.Arrays; |
17 | 17 | import java.util.HashMap; |
18 | +import java.util.LinkedList; | |
18 | 19 | import java.util.Map; |
19 | 20 | import java.util.TreeSet; |
20 | 21 |
@@ -36,6 +37,9 @@ | ||
36 | 37 | GroupCommand _groupCommand = new GroupCommand(); |
37 | 38 | TableCommand _tableCommand = new TableCommand(); |
38 | 39 | |
40 | + LinkedList<String> cmdHistory = new LinkedList<>(); | |
41 | + LinkedList<String> aggregatedHistory = new LinkedList<>(); | |
42 | + | |
39 | 43 | CommandFragment _commandStorage = new CommandFragment("."); |
40 | 44 | |
41 | 45 | private static String DEFAULT_BOOK_NAME = "myBook"; |
@@ -99,9 +103,11 @@ | ||
99 | 103 | this._books.put(book.getName(), book); |
100 | 104 | |
101 | 105 | // コンソールから1行づつ読み込んで処理する |
106 | + InputStreamReader isr = null; | |
102 | 107 | BufferedReader br = null; |
103 | 108 | try { |
104 | - br = new BufferedReader(new InputStreamReader(System.in, "JISAutoDetect")); | |
109 | + isr = new InputStreamReader(System.in, "JISAutoDetect"); | |
110 | + br = new BufferedReader(isr); | |
105 | 111 | } catch (UnsupportedEncodingException e1) { |
106 | 112 | e1.printStackTrace(); |
107 | 113 | } |
@@ -114,6 +120,8 @@ | ||
114 | 120 | Book currentBook = _books.get(_currentBookName); |
115 | 121 | System.out.print("[" + _currentBookName + "]" + currentBook.getResolver().getCurrentSheet().getName() + ": "); |
116 | 122 | |
123 | + | |
124 | + System.out.println(Integer.toString(isr.read())); | |
117 | 125 | // 入力がなくなったら終了 |
118 | 126 | if ((line = br.readLine().trim()) == null) { |
119 | 127 | break; |
@@ -135,6 +143,10 @@ | ||
135 | 143 | } else { |
136 | 144 | _cellCommand.processCell(_books.get(_currentBookName), line); |
137 | 145 | } |
146 | + System.out.println(line); | |
147 | + cmdHistory.add(line); | |
148 | + aggregatedHistory.remove(line); | |
149 | + aggregatedHistory.add(line); | |
138 | 150 | } catch (Exception e) { |
139 | 151 | e.printStackTrace(); |
140 | 152 | } |
@@ -255,6 +267,14 @@ | ||
255 | 267 | System.out.println(_commandStorage.getHelp()); |
256 | 268 | } |
257 | 269 | |
270 | + private void doHistory(String argStr) { | |
271 | + StringBuilder sb = new StringBuilder(); | |
272 | + for (String s : cmdHistory) { | |
273 | + sb.append(s).append("\n"); | |
274 | + } | |
275 | + System.out.println(sb); | |
276 | + } | |
277 | + | |
258 | 278 | private void doCellList(String argStr) { |
259 | 279 | Sheet sheet = _books.get(_currentBookName).getResolver().getCurrentSheet(); |
260 | 280 | _cellCommand.listCells(sheet); |
@@ -7,6 +7,8 @@ | ||
7 | 7 | {".quit", "doQuit", ".quit\nこのプログラムを終了します。"}, |
8 | 8 | {".help", "doHelp", ".help\nヘルプを表示します。"}, |
9 | 9 | |
10 | + {".history", "doHistory", ".history\nコマンド履歴を表示します。"}, | |
11 | + | |
10 | 12 | {".book.add", "doBookAdd", ".book.add <Book名>\n新しいブックを追加します。"}, |
11 | 13 | {".book.current", "doBookCurrent", ".book.current <Book名>\nカレントブックを変更します。"}, |
12 | 14 | {".book.list", "doBookList", ".book.list\nBookをリストします。"}, |