Changeset 10305 for trunk


Ignore:
Timestamp:
04/07/11 15:41:50 (14 years ago)
Author:
tbretz
Message:
Use ReadlineColor for unified look and feel.
Location:
trunk/FACT++/src
Files:
4 edited

Legend:

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

    r10183 r10305  
    1616
    1717#include "tools.h"
     18
     19#include "ReadlineColor.h"
    1820
    1921using namespace std;
     
    4547    fLogO.Display();
    4648    fLogI.Display();
     49}
     50
     51// --------------------------------------------------------------------------
     52//
     53//! Wrapper to call the correspnding function from ReadlineColor
     54//
     55bool Console::PrintGeneralHelp()
     56{
     57    return ReadlineColor::PrintGeneralHelp(fLogI, GetName());
     58}
     59
     60// --------------------------------------------------------------------------
     61//
     62//! Wrapper to call the correspnding function from ReadlineColor
     63//
     64bool Console::PrintCommands()
     65{
     66    return ReadlineColor::PrintCommands(fLogI);
     67}
     68
     69// --------------------------------------------------------------------------
     70//
     71//! Wrapper to call the correspnding function from ReadlineColor
     72//
     73bool 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//
     85bool 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;
    4794}
    4895
     
    90137}
    91138
    92 /*
    93 // --------------------------------------------------------------------------
    94 //
    95 //! Flush the buffer before it is filled with contents produced by the
    96 //! 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 
    107139// --------------------------------------------------------------------------
    108140//
     
    114146void Console::Run(const char *)
    115147{
    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
    117151    fLogI.Display(true);
    118152    fLogO.Display(true);
  • trunk/FACT++/src/Console.h

    r10183 r10305  
    1616    ~Console();
    1717
     18    // Console
    1819    void SetContinous(bool cont) { fContinous = cont; }
    1920    bool IsContinous() const { return fContinous; }
    2021
     22    // I/O
    2123    WindowLog &GetStreamOut() { return fLogO; }
    2224    WindowLog &GetStreamIn()  { return fLogI; }
     
    2527    const WindowLog &GetStreamIn()  const { return fLogI; }
    2628
     29    // Readline
     30    bool PrintGeneralHelp();
     31    bool PrintCommands();
     32    bool PrintKeyBindings();
     33
     34    bool Process(const std::string &str);
     35
    2736    std::string GetLinePrompt() const;
    2837
    2938    void Startup();
    3039    void EventHook();
    31     //void Shutdown(const char * =0);
    3240    void Run(const char * = 0);
    3341};
  • 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 -----------
  • trunk/FACT++/src/Shell.h

    r10183 r10305  
    33
    44#include "ReadlineWindow.h"
     5#include "ReadlineColor.h"
    56#include "WindowLog.h"
    67
     
    4243    void HandleResize();
    4344
    44     // Wrapper function to redirect the output of some readline function
    45     // into our own stream
    46     bool RedirectionWrapper(bool (*function)(), const char *title);
    47     bool PrintAttributes();  /// Show the available attributes
    48 
    4945    /// Helper for the constructor and window resizing to create the windows and panels
    5046    void CreateWindows(WINDOW *w[3], int all=true);
     
    6157    void Refresh() { ShowHide(-2); }
    6258
    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); }
    6662
    6763    bool Process(const std::string &str);
     64
     65    void Run(const char * = "")
     66    {
     67        ReadlineColor::PrintBootMsg(win, GetName());
     68        Readline::Run();
     69    }
    6870
    6971    WindowLog &GetStreamOut() { return wout; }
Note: See TracChangeset for help on using the changeset viewer.