11 #include <ConfigHolder.h>
14 namespace freeRecite
{
19 std::cerr
<< "Can't load " << configHolder
.mgrFile() << std::endl
20 << "The program exit!\n";
23 if(!dictionary
.load()) {
24 std::cerr
<< "Can't load " << configHolder
.dictFile() << std::endl
25 << "The program exit!\n";
37 std::cout
<< "Welcome to Free Recite!"<< std::endl
;
38 std::cout
<< "Type \"help\" for help;p" << std::endl
;
44 case 'n':{ //creat new task
52 case 'r': { //recite for the new works.
69 std::cerr
<< "Bad Command!"<<std::endl
;
78 std::cout
<< "~_~Free Recite:> ";
86 else if(cmd
== "test")
88 else if(cmd
== "recite")
90 else if(cmd
== "modify")
92 else if(cmd
== "showall")
94 else if(cmd
== "help")
100 void CUI::creatNew() {
101 std::string fileName
,taskName
;
102 std::cout
<<"Input the filename of the words. File Name: ";
104 std::ifstream
ifs(fileName
.c_str());
106 std::cout
<< "Can't find the file.";
109 std::set
<std::string
> wordSet
;
110 std::string word
, cmd
;
112 std::getline(ifs
,word
);
113 if(!dictionary
.lookUp(word
) && !word
.empty()) {
114 std::cout
<< '\"' << word
<< '\"'
115 << " can't be fond in your dictionary"<<std::endl
116 << "Remove(R) or Modify(M) it? (R/m)" << std::endl
;
119 if(cmd
== "M" || cmd
== "m")
125 wordSet
.insert(word
);
127 std::cout
<< "Give a task name for it?" << std::endl
;
128 std::cout
<< "(Press Enter will give a default name): ";
131 if(manager
.creatTask(wordSet
,cmd
.c_str())) {
132 std::cout
<< "Creat a task SUCCESS!" << std::endl
;
135 std::cerr
<< "Can't creat a task :}" << std::endl
;
138 void CUI::showAnswer(Scanner
*scanner
) const {
140 <<"********************ANSWER********************"
143 <<"* " <<dictionary
.word()<< std::endl
145 <<"* ["<<dictionary
.phonetics() << "]"<<std::endl
146 <<"* " <<dictionary
.translation() << std::endl
148 <<"* Amount: "<< scanner
->capability()
150 << (scanner
->size()-1) << std::endl
151 <<"**********************************************"
156 void CUI::showResult(bool result
) {
158 std::cout
<<" ** * * "<<std::endl
;
159 std::cout
<<" * * * * "<<std::endl
;
160 std::cout
<<" * * ** "<<std::endl
;
161 std::cout
<<" * * * * "<<std::endl
;
162 std::cout
<<" ** * * "<<std::endl
;
165 std::cout
<<"##### #### #### "<<std::endl
;
166 std::cout
<<"# # # # # "<<std::endl
;
167 std::cout
<<"##### #### #### "<<std::endl
;
168 std::cout
<<"# # # # # "<<std::endl
;
169 std::cout
<<"##### # # # # "<<std::endl
;
175 if((manager
.getActiveTasks()).size() == 0){
176 std::cout
<< "There's no tasks to review!" << std::endl
;
180 std::cout
<< "Which do you want to test [ 0 by default]: ";
182 if(i
>= (manager
.getActiveTasks()).size()) {
183 std::cerr
<< "Error task!" << std::endl
;
188 time_t taskID
= (manager
.getActiveTasks())[i
];
190 if(!tester
.loadWords(taskID
)) {
191 std::cerr
<< "error when load words!" << std::endl
;
196 time_t startTime
= 0;
201 std::string inputStr
;
204 while(tester
.isValid()) {
205 if(dictionary
.lookUp(tester
.getWord())){
207 std::cout
<<"[M]: "<<dictionary
.translation()<<std::endl
;
208 std::cout
<<"Input: ";
210 if(inputStr
== "\\modify")
211 modify(tester
.getWord());
212 else if(inputStr
== "\\stop")
214 else if(inputStr
== "\\exit")
216 result
= ( inputStr
== tester
.getWord() ? true : false );
224 startTime
= endTime
- startTime
;
225 std::cout
<< std::endl
<< "Used Time: "
226 << startTime
/60 << "minutes" << std::endl
;
228 if(manager
.test(taskID
,tester
.getScore())) {
229 std::cout
<<"Your score is " << tester
.getScore() << std::endl
;
230 std::cout
<<"You passed it!"<<std::endl
;
233 std::cout
<<"Your score is " << tester
.getScore() << std::endl
234 <<"You haven't passed it :} "<<std::endl
;
237 time_t nextTime
= manager
.getNextTime(taskID
);
238 if(manager
.getTaskStep(taskID
) == 8)
239 std::cout
<< "Congratulations! You have complish this task!"
242 struct tm
* timeinfo
;
244 timeinfo
= localtime(&nextTime
);
245 strftime(buffer
,30,"%Y.%m.%d %H:%M:%S",timeinfo
);
246 std::cout
<< "Then next reviewing time is: " << buffer
247 << std::endl
<< std::endl
;
254 if((manager
.getActiveTasks()).size() == 0){
255 std::cout
<< "There's no tasks to review!" << std::endl
;
259 std::cout
<< "Which do you want to test [ 0 by default]: ";
261 if(i
>= (manager
.getActiveTasks()).size()) {
262 std::cerr
<< "Error task!" << std::endl
;
267 time_t taskID
= (manager
.getActiveTasks())[i
];
269 if(!reciter
.loadWords(taskID
)) {
270 std::cerr
<< "error when load words!" << std::endl
;
275 time_t startTime
= 0;
280 std::string inputStr
;
282 while(reciter
.isValid()) {
283 if(dictionary
.lookUp(reciter
.getWord())){
284 showAnswer(&reciter
);
285 std::cout
<< "Press E to emphasize,Enter to continue......"
288 if(inputStr
== "\\modify")
289 modify(reciter
.getWord());
290 else if(inputStr
== "\\stop")
292 else if(inputStr
== "\\exit")
294 else if(inputStr
== "E" || inputStr
== "e")
303 startTime
= endTime
- startTime
;
304 std::cout
<< std::endl
<< "Used Time: "
305 << startTime
/60 << "minutes" << std::endl
;
310 bool CUI::modify(const char *word
) {
311 std::string newItem
,inputStr
;
315 newItem
.append("[W]"+inputStr
);
317 newItem
.append("[W]");
318 newItem
.append(word
);
321 std::cout
<<"θ_ɑ_ʌ_ә_є_æ_ɔ_ʃ_ð_ŋ_ʒ"<<std::endl
;
322 std::cout
<<"0_1_2_3_4_5_6_7_8_9_="<<std::endl
;
325 newItem
.append("[T]"+inputStr
);
328 newItem
.append("[M]"+inputStr
);
330 if(!dictionary
.modify(newItem
)) {
331 std::cout
<<"ERROR!" << std::endl
;
334 std::cout
<<"SUCCESS!"<<std::endl
;
338 bool CUI::modify(const std::string
&word
) {
339 std::string newItem
,inputStr
;
343 newItem
.append("[W]"+inputStr
);
345 newItem
.append("[W]"+word
);
347 std::cout
<<"θ_ɑ_ʌ_ә_є_æ_ɔ_ʃ_ð_ŋ_ʒ"<<std::endl
;
348 std::cout
<<"0_1_2_3_4_5_6_7_8_9_="<<std::endl
;
351 newItem
.append("[T]"+inputStr
);
354 newItem
.append("[M]"+inputStr
);
356 if(!dictionary
.modify(newItem
)) {
357 std::cout
<<"ERROR!" << std::endl
;
360 std::cout
<<"SUCCESS!"<<std::endl
;
364 void CUI::showActive() {
366 if(!manager
.refresh()) {
367 std::cout
<< "The configure file is broken!" << std::endl
;
370 if(manager
.getActiveTaskNum() == 0) {
372 std::cout
<< "There's no new task should be review,type \"new\" to creat one."
375 if(manager
.getNextTime() != 0) {
376 time_t nextTime
= manager
.getNextTime();
377 struct tm
* timeinfo
;
379 timeinfo
= localtime(&nextTime
);
380 strftime(buffer
,30,"%Y.%m.%d %H:%M:%S",timeinfo
);
381 std::cout
<< "The nearest reviewing time is at " << buffer
383 << "Please use FreeRecite at that time!"
384 << std::endl
<< std::endl
;
388 std::cout
<< "There's " << manager
.getActiveTaskNum()
389 << " tasks should review." << std::endl
;
390 std::cout
<< "They are:" << std::endl
;
392 for(int i
= 0; i
< manager
.getActiveTaskNum(); ++i
) {
394 std::cout
<< i
<< ": "
395 << manager
.getTaskName(manager
.getActiveTasks()[i
])
399 std::cout
<< std::endl
<< std::endl
<< std::endl
;
404 for(int i
= 0; i
< 10; ++i
)
405 std::cerr
<< std::endl
;
408 void CUI::getLine(std::string
&input
) {
412 while(std::cin
.get(t
),t
!= '\n')
417 std::cout
<< "Welcome to use Free Recite!" << std::endl
418 << "There's server command here:" << std::endl
419 << " exit: Exit Free Recite normally." << std::endl
420 << " new: Creat a new tasks."<<std::endl
421 << " test: Test the tasks." << std::endl
422 << " recite: Recite the task without any mark set."<<std::endl
423 << " help: Get help like this;p"<<std::endl
;
426 } // namespace freeRecite End.