Ignore:
Timestamp:
04/07/11 15:41:50 (13 years ago)
Author:
tbretz
Message:
Use ReadlineColor for unified look and feel.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Shell.cc

    r10285 r10305  
    425425// --------------------------------------------------------------------------
    426426//
    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 function
    435 //!    Takes a function of type bool(*)() as argument
    436 //!
    437 //! @param title
    438 //!    A title streamed in bold before the output starts
    439 //!
    440 //! @returns
    441 //!    The return value of the function
    442 //
    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 command
    480 //! c is issued.
    481 //!
    482 //! @returns
    483 //!    always true
    484 //
    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 //! @returns
    500 //!    always true
    501 //
    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 class
    536 //!
    537 //! @returns
    538 //!    always true
    539 //!
    540 //! @todo
    541 //!    Update output
    542 //
    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-defined
    564 //! by the Shell class.
    565 //!
    566 //! @returns
    567 //!    always true
    568 //!
    569 //! @todo
    570 //!    Get it up-to-date
    571 //
    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 //
    597427//! Processes the command provided by the Shell-class.
    598428//!
     
    607437    //  int rl_add_defun (const char *name, rl_command_func_t *function, int key)
    608438
    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;
    622441
    623442    if (Readline::Process(str))
    624443        return true;
    625 
    626     // ------------ ReadlineWindow -------------
    627 
    628     if (str=="a" || str=="attrs")
    629         return PrintAttributes();
    630444
    631445    // ----------- ReadlineNcurses -----------
Note: See TracChangeset for help on using the changeset viewer.