12 namespace freeRecite
{
14 CUI::CUI(const std::string
&dir
)
16 manager
= new Manager
;
17 if(!manager
->load(dir
)) {
18 std::cerr
<< "Can't load the configure file from " << dir
<< std::endl
19 << "The program exit!\n";
22 dict
= new Dict(dir
+ "freeRecite.dict");
23 if(!dict
->loadDict()) {
24 std::cerr
<< "Can't load the dic from " << dir
<< std::endl
25 << "The program exit!\n";
39 std::cout
<< "Welcome to Free Recite!"<< std::endl
;
40 std::cout
<< "Type \"help\" for help;p" << std::endl
;
46 case 'n':{ //creat new task
54 case 'r': { //recite for the new works.
71 std::cerr
<< "Bad Command!"<<std::endl
;
80 std::cout
<< "~_~Free Recite:> ";
88 else if(cmd
== "test")
90 else if(cmd
== "recite")
92 else if(cmd
== "modify")
94 else if(cmd
== "showall")
96 else if(cmd
== "help")
102 void CUI::creatNew() {
103 std::string fileName
,taskName
;
104 std::cout
<<"Input the filename of the words. File Name: ";
106 std::ifstream
ifs(fileName
.c_str());
108 std::cout
<< "Can't find the file.";
111 std::set
<std::string
> wordSet
;
112 std::string word
, cmd
;
114 std::getline(ifs
,word
);
115 if(!dict
->lookUp(word
) && !word
.empty()) {
116 std::cout
<< '\"' << word
<< '\"'
117 << " can't be fond in your dict"<<std::endl
118 << "Remove(R) or Modify(M) it? (R/m)" << std::endl
;
121 if(cmd
== "M" || cmd
== "m")
127 wordSet
.insert(word
);
129 std::cout
<< "Give a task name for it?" << std::endl
;
130 std::cout
<< "(Press Enter will give a default name): ";
133 if(manager
->creatTask(wordSet
,cmd
.c_str())) {
134 std::cout
<< "Creat a task SUCCESS!" << std::endl
;
137 std::cerr
<< "Can't creat a task :}" << std::endl
;
140 void CUI::testProcess(Reciter
&tester
) {
147 std::string inputStr
;
149 std::cout
<< "Step 1: interpretation To key!" << std::endl
;
150 while(tester
.isValid()) {
151 if(dict
->lookUp(tester
.getWord())){
152 std::cout
<<"[W]: "<<dict
->word()<<std::endl
;
153 std::cout
<<"Press Enter to show the interpretation..."<<std::endl
;
155 if(inputStr
== "\\modify")
156 modify(tester
.getWord());
157 else if(inputStr
== "\\stop")
159 else if(inputStr
== "\\exit")
163 <<"********************ANSWER********************"<<std::endl
165 <<"* " <<dict
->word()<< std::endl
167 <<"* ["<<dict
->phonetics() << "]"<<std::endl
168 <<"* " <<dict
->translation() << std::endl
170 <<"* Amount: "<< tester
.capability()<<" Unrecited Num: "
171 <<(tester
.size()-1) << std::endl
172 <<"**********************************************"<<std::endl
174 std::cout
<<std::endl
<<std::endl
175 <<"Have you remembered it(Y/n)?";
177 if(inputStr
!= "N" || inputStr
!= "n") {
178 std::cout
<<" ** * * "<<std::endl
;
179 std::cout
<<" * * * * "<<std::endl
;
180 std::cout
<<" * * ** "<<std::endl
;
181 std::cout
<<" * * * * "<<std::endl
;
182 std::cout
<<" ** * * "<<std::endl
;
186 std::cout
<<"##### #### #### "<<std::endl
;
187 std::cout
<<"# # # # # "<<std::endl
;
188 std::cout
<<"##### #### #### "<<std::endl
;
189 std::cout
<<"# # # # # "<<std::endl
;
190 std::cout
<<"##### # # # # "<<std::endl
;
195 std::cout
<<"**" << tester
.getWord()<<"** can't find in the Dictionary."
196 <<"modify(M) or remove(R) it? M/r"<<std::endl
;
204 std::cout
<< "Step 2: interpretation To key!" << std::endl
;
205 while(tester
.isValid()) {
206 if(dict
->lookUp(tester
.getWord())){
207 std::cout
<<"[M]: "<<dict
->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 testResult
= ( inputStr
== tester
.getWord() ? true : false );
219 <<"********************ANSWER********************"<<std::endl
221 <<"* " <<dict
->word()<< std::endl
223 <<"* ["<<dict
->phonetics() << "]"<<std::endl
224 <<"* " <<dict
->translation() << std::endl
226 <<"* Amount: "<< tester
.capability()<<" Unrecited Num: "
227 << (tester
.size()-1) << std::endl
228 <<"**********************************************"<<std::endl
231 std::cout
<<" ** * * "<<std::endl
;
232 std::cout
<<" * * * * "<<std::endl
;
233 std::cout
<<" * * ** "<<std::endl
;
234 std::cout
<<" * * * * "<<std::endl
;
235 std::cout
<<" ** * * "<<std::endl
;
238 std::cout
<<"##### #### #### "<<std::endl
;
239 std::cout
<<"# # # # # "<<std::endl
;
240 std::cout
<<"##### #### #### "<<std::endl
;
241 std::cout
<<"# # # # # "<<std::endl
;
242 std::cout
<<"##### # # # # "<<std::endl
;
244 tester
.test(testResult
);
247 std::cout
<<"**" << tester
.getWord()<<"** can't find in the Dictionary."
248 <<"modify(M) or remove(R) it? M/r"<<std::endl
;
255 starTime
= endTime
- starTime
;
256 std::cout
<< std::endl
<< "Used Time: "
257 << starTime
/60 << "minutes" << std::endl
;
262 if((manager
->getActiveTasks()).size() == 0){
263 std::cout
<< "There's no tasks to review!" << std::endl
;
267 std::cout
<< "Which do you want to test [ 0 by default]: ";
269 if(i
>= (manager
->getActiveTasks()).size()) {
270 std::cerr
<< "Error task!" << std::endl
;
275 time_t taskID
= (manager
->getActiveTasks())[i
];
277 if(!tester
.loadWords(taskID
,manager
->getDir().c_str())) {
278 std::cerr
<< "error when load words!" << std::endl
;
283 if(manager
->test(taskID
,tester
.getScore())) {
284 std::cout
<<"Your score is " << tester
.getScore() << std::endl
;
285 std::cout
<<"You passed it!"<<std::endl
;
288 std::cout
<<"Your score is " << tester
.getScore() << std::endl
289 <<"You haven't passed it :} "<<std::endl
;
292 time_t nextTime
= manager
->getNextTime(taskID
);
293 if(manager
->getTaskStep(taskID
) == 8)
294 std::cout
<< "Congratulations! You have complish this task!" << std::endl
;
296 struct tm
* timeinfo
;
298 timeinfo
= localtime(&nextTime
);
299 strftime(buffer
,30,"%Y.%m.%d %H:%M:%S",timeinfo
);
300 std::cout
<< "Then next reviewing time is: " << buffer
301 << std::endl
<< std::endl
;
311 if((manager
->getActiveTasks()).size() == 0)
314 std::cout
<< "Which do you want to test: ";
316 if(i
>= (manager
->getActiveTasks()).size()) {
317 std::cerr
<< "Error task!" << std::endl
;
322 if(!tester
.loadWords((manager
->getActiveTasks())[i
],manager
->getDir().c_str())) {
323 std::cerr
<< "error when load words!" << std::endl
;
328 std::cout
<< "Do you want to do it again?(y/N)";
330 while(std::cin
>>YN
,YN
=="Y"||YN
=="y") {
336 bool CUI::modify(const char *word
) {
337 std::string newItem
,inputStr
;
341 newItem
.append("[W]"+inputStr
);
343 newItem
.append("[W]");
344 newItem
.append(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(!dict
->modify(newItem
)) {
357 std::cout
<<"ERROR!" << std::endl
;
360 std::cout
<<"SUCCESS!"<<std::endl
;
365 bool CUI::modify(const std::string
&word
) {
366 std::string newItem
,inputStr
;
370 newItem
.append("[W]"+inputStr
);
372 newItem
.append("[W]"+word
);
374 std::cout
<<"θ_ɑ_ʌ_ә_є_æ_ɔ_ʃ_ð_ŋ_ʒ"<<std::endl
;
375 std::cout
<<"0_1_2_3_4_5_6_7_8_9_="<<std::endl
;
378 newItem
.append("[T]"+inputStr
);
381 newItem
.append("[M]"+inputStr
);
383 if(!dict
->modify(newItem
)) {
384 std::cout
<<"ERROR!" << std::endl
;
387 std::cout
<<"SUCCESS!"<<std::endl
;
391 void CUI::showActive() {
393 if(!manager
->refresh()) {
394 std::cout
<< "The configure file is broken!" << std::endl
;
397 if(manager
->getActiveTaskNum() == 0) {
400 std::cout
<< "There's no new task should be review,type \"new\" to creat one."
403 if(manager
->getNextTime() != 0) {
404 time_t nextTime
= manager
->getNextTime();
405 struct tm
* timeinfo
;
407 timeinfo
= localtime(&nextTime
);
408 strftime(buffer
,30,"%Y.%m.%d %H:%M:%S",timeinfo
);
409 std::cout
<< "The nearest reviewing time is at " << buffer
411 << "Please use FreeRecite at that time!"
412 << std::endl
<< std::endl
;
416 std::cout
<< "There's " << manager
->getActiveTaskNum()
417 << " tasks should review." << std::endl
;
418 std::cout
<< "They are:" << std::endl
;
420 for(int i
= 0; i
< manager
->getActiveTaskNum(); ++i
) {
422 std::cout
<< i
<< ": "
423 << manager
->getTaskName(manager
->getActiveTasks()[i
])
427 std::cout
<< std::endl
<< std::endl
<< std::endl
;
432 for(int i
= 0; i
< 10; ++i
)
433 std::cerr
<< std::endl
;
436 void CUI::getLine(std::string
&input
) {
440 while(std::cin
.get(t
),t
!= '\n')
445 std::cout
<< "Welcome to use Free Recite!" << std::endl
446 << "There's server command here:" << std::endl
447 << " exit: Exit Free Recite normally." << std::endl
448 << " new: Creat a new tasks."<<std::endl
449 << " test: Test the tasks." << std::endl
450 << " recite: Recite the task without any mark set."<<std::endl
451 << " help: Get help like this;p"<<std::endl
;
454 } // namespace freeRecite End.