- Timestamp:
- 04/07/11 15:41:50 (14 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Console.cc
r10183 r10305 16 16 17 17 #include "tools.h" 18 19 #include "ReadlineColor.h" 18 20 19 21 using namespace std; … … 45 47 fLogO.Display(); 46 48 fLogI.Display(); 49 } 50 51 // -------------------------------------------------------------------------- 52 // 53 //! Wrapper to call the correspnding function from ReadlineColor 54 // 55 bool Console::PrintGeneralHelp() 56 { 57 return ReadlineColor::PrintGeneralHelp(fLogI, GetName()); 58 } 59 60 // -------------------------------------------------------------------------- 61 // 62 //! Wrapper to call the correspnding function from ReadlineColor 63 // 64 bool Console::PrintCommands() 65 { 66 return ReadlineColor::PrintCommands(fLogI); 67 } 68 69 // -------------------------------------------------------------------------- 70 // 71 //! Wrapper to call the correspnding function from ReadlineColor 72 // 73 bool Console::PrintKeyBindings() 74 { 75 return ReadlineColor::PrintKeyBindings(fLogI); 76 } 77 78 // -------------------------------------------------------------------------- 79 // 80 //! Processes the command provided by the Shell-class. 81 //! 82 //! @returns 83 //! whether a command was successfully processed or could not be found 84 // 85 bool Console::Process(const string &str) 86 { 87 if (ReadlineColor::Process(fLogI, str)) 88 return true; 89 90 if (Readline::Process(str)) 91 return true; 92 93 return false; 47 94 } 48 95 … … 90 137 } 91 138 92 /*93 // --------------------------------------------------------------------------94 //95 //! Flush the buffer before it is filled with contents produced by the96 //! command processing. This keeps things as seperated as possible,97 //! although there is no gurantee.98 //99 void Console::Shutdown(const char *)100 {101 // Flush the buffer (after readline() returned, before processing commands)102 fLog.Display(true);103 // std::cout << std::endl;104 }105 */106 107 139 // -------------------------------------------------------------------------- 108 140 // … … 114 146 void Console::Run(const char *) 115 147 { 116 // Flush the buffer before we stat out readline loop 148 ReadlineColor::PrintBootMsg(fLogI, GetName()); 149 150 // Flush the buffer before we start out readline loop 117 151 fLogI.Display(true); 118 152 fLogO.Display(true); -
trunk/FACT++/src/Console.h
r10183 r10305 16 16 ~Console(); 17 17 18 // Console 18 19 void SetContinous(bool cont) { fContinous = cont; } 19 20 bool IsContinous() const { return fContinous; } 20 21 22 // I/O 21 23 WindowLog &GetStreamOut() { return fLogO; } 22 24 WindowLog &GetStreamIn() { return fLogI; } … … 25 27 const WindowLog &GetStreamIn() const { return fLogI; } 26 28 29 // Readline 30 bool PrintGeneralHelp(); 31 bool PrintCommands(); 32 bool PrintKeyBindings(); 33 34 bool Process(const std::string &str); 35 27 36 std::string GetLinePrompt() const; 28 37 29 38 void Startup(); 30 39 void EventHook(); 31 //void Shutdown(const char * =0);32 40 void Run(const char * = 0); 33 41 }; -
trunk/FACT++/src/Shell.cc
r10285 r10305 425 425 // -------------------------------------------------------------------------- 426 426 // 427 //! This wrapt the given readline function into a redirection to a file,428 //! which contents is then displayed afterwards in the input panel.429 //!430 //! For convinience the given title is printed in bold before the list.431 //!432 //! This allows to show some readline output in the panel.433 //!434 //! @param function435 //! Takes a function of type bool(*)() as argument436 //!437 //! @param title438 //! A title streamed in bold before the output starts439 //!440 //! @returns441 //! The return value of the function442 //443 bool Shell::RedirectionWrapper(bool (*function)(), const char *title)444 {445 FILE *save = SetStreamOut(tmpfile());446 const bool rc = function();447 FILE *file = SetStreamOut(save);448 449 const bool empty = ftell(file)==0;450 451 rewind(file);452 453 win << endl;454 win << kBold << title << endl;455 456 if (empty)457 {458 win << " <empty>" << endl;459 fclose(file);460 return rc;461 }462 463 while (1)464 {465 const int c = getc(file);466 if (feof(file))467 break;468 win << (char)c;469 }470 win << endl;471 472 fclose(file);473 474 return rc;475 }476 477 // --------------------------------------------------------------------------478 //479 //! Can be overwritten to display user defined commands when the command480 //! c is issued.481 //!482 //! @returns483 //! always true484 //485 bool Shell::PrintCommands()486 {487 win << endl;488 win << " " << kUnderline << " Commands:" << endl;489 win << " No application specific commands defined." << endl;490 win << endl;491 492 return true;493 }494 495 // --------------------------------------------------------------------------496 //497 //! Displays the available ncurses attributes, like color.498 //!499 //! @returns500 //! always true501 //502 bool Shell::PrintAttributes()503 {504 //ostream &win = wout;505 win << endl;506 win << " Attributes:" << endl;507 win << " " << kReset << "kReset" << endl;508 win << " " << kNormal << "kNormal" << endl;509 win << " " << kHighlight << "kHighlight" << endl;510 win << " " << kReverse << "kReverse" << endl;511 win << " " << kUnderline << "kUnderline" << endl;512 win << " " << kBlink << "kBlink" << endl;513 win << " " << kDim << "kDim" << endl;514 win << " " << kBold << "kBold" << endl;515 win << " " << kProtect << "kProtect" << endl;516 win << " " << kInvisible << "kInvisible" << endl;517 win << " " << kAltCharset << "kAltCharset" << kReset << " (kAltCharset)" << endl;518 win << endl;519 win << " Colors:" << endl;520 win << " " << kDefault << "kDefault " << kBold << "+ kBold" << endl;521 win << " " << kRed << "kRed " << kBold << "+ kBold" << endl;522 win << " " << kGreen << "kGreen " << kBold << "+ kBold" << endl;523 win << " " << kYellow << "kYellow " << kBold << "+ kBold" << endl;524 win << " " << kBlue << "kBlue " << kBold << "+ kBold" << endl;525 win << " " << kMagenta << "kMagenta " << kBold << "+ kBold" << endl;526 win << " " << kCyan << "kCyan " << kBold << "+ kBold" << endl;527 win << " " << kWhite << "kWhite " << kBold << "+ kBold" << endl;528 win << " " << endl;529 530 return true;531 }532 533 // --------------------------------------------------------------------------534 //535 //! Displays the keybindings available due to the Shell class536 //!537 //! @returns538 //! always true539 //!540 //! @todo541 //! Update output542 //543 bool Shell::PrintKeyBindings()544 {545 win << endl;546 win << " " << kUnderline << "Key bindings:" << endl;547 win << kBold << " Page-up " << kReset << "Search backward in history" << endl;548 win << kBold << " Page-dn " << kReset << "Search forward in history" << endl;549 win << kBold << " Ctrl-left " << kReset << "One word backward" << endl;550 win << kBold << " Ctrl-right " << kReset << "One word forward" << endl;551 win << kBold << " Ctrl-y " << kReset << "Delete line" << endl;552 win << kBold << " Alt-end/Ctrl-k " << kReset << "Delete until the end of the line" << endl;553 win << kBold << " F1 " << kReset << "Toggle visibility of upper panel" << endl;554 win << endl;555 win << " Default key-bindings are identical with your bash." << endl;556 win << endl;557 558 return true;559 }560 561 // --------------------------------------------------------------------------562 //563 //! Print a general help text which also includes the commands pre-defined564 //! by the Shell class.565 //!566 //! @returns567 //! always true568 //!569 //! @todo570 //! Get it up-to-date571 //572 bool Shell::PrintGeneralHelp()573 {574 win << endl;575 win << " " << kUnderline << "General help:" << endl;576 win << kBold << " h,help " << kReset << "Print this help message" << endl;577 win << kBold << " clear " << kReset << "Clear history buffer" << endl;578 win << kBold << " lh,history " << kReset << "Dump the history buffer to the screen" << endl;579 win << kBold << " v,variable " << kReset << "Dump readline variables" << endl;580 win << kBold << " f,function " << kReset << "Dump readline functions" << endl;581 win << kBold << " m,funmap " << kReset << "Dump readline funmap" << endl;582 win << kBold << " c,command " << kReset << "Dump available commands" << endl;583 win << kBold << " k,keylist " << kReset << "Dump key bindings" << endl;584 win << kBold << " a,attrs " << kReset << "Dump available stream attributes" << endl;585 win << kBold << " .q,quit " << kReset << "Quit" << endl;586 win << endl;587 win << " The command history is automatically loaded and saves to" << endl;588 win << " and from " << GetName() << endl;589 win << endl;590 591 return true;592 }593 594 595 // --------------------------------------------------------------------------596 //597 427 //! Processes the command provided by the Shell-class. 598 428 //! … … 607 437 // int rl_add_defun (const char *name, rl_command_func_t *function, int key) 608 438 609 // ----------- Readline ----------- 610 611 if (str=="lh" || str=="history") 612 return RedirectionWrapper(DumpHistory, "History:"); 613 614 if (str=="v" || str=="variable") 615 return RedirectionWrapper(DumpVariables, "Variables:"); 616 617 if (str=="f" || str=="function") 618 return RedirectionWrapper(DumpFunctions, "Functions:"); 619 620 if (str=="m" || str=="funmap") 621 return RedirectionWrapper(DumpFunmap, "Funmap:"); 439 if (ReadlineColor::Process(win, str)) 440 return true; 622 441 623 442 if (Readline::Process(str)) 624 443 return true; 625 626 // ------------ ReadlineWindow -------------627 628 if (str=="a" || str=="attrs")629 return PrintAttributes();630 444 631 445 // ----------- ReadlineNcurses ----------- -
trunk/FACT++/src/Shell.h
r10183 r10305 3 3 4 4 #include "ReadlineWindow.h" 5 #include "ReadlineColor.h" 5 6 #include "WindowLog.h" 6 7 … … 42 43 void HandleResize(); 43 44 44 // Wrapper function to redirect the output of some readline function45 // into our own stream46 bool RedirectionWrapper(bool (*function)(), const char *title);47 bool PrintAttributes(); /// Show the available attributes48 49 45 /// Helper for the constructor and window resizing to create the windows and panels 50 46 void CreateWindows(WINDOW *w[3], int all=true); … … 61 57 void Refresh() { ShowHide(-2); } 62 58 63 bool PrintGeneralHelp() ;64 bool PrintCommands() ;65 bool PrintKeyBindings() ;59 bool PrintGeneralHelp() { return ReadlineColor::PrintGeneralHelp(win, GetName()); } 60 bool PrintCommands() { return ReadlineColor::PrintCommands(win); } 61 bool PrintKeyBindings() { return ReadlineColor::PrintKeyBindings(win); } 66 62 67 63 bool Process(const std::string &str); 64 65 void Run(const char * = "") 66 { 67 ReadlineColor::PrintBootMsg(win, GetName()); 68 Readline::Run(); 69 } 68 70 69 71 WindowLog &GetStreamOut() { return wout; }
Note:
See TracChangeset
for help on using the changeset viewer.