TTermManip.h

Go to the documentation of this file.
00001 // @(#)root/editline:$Id: TTermManip.h 30960 2009-11-03 11:43:23Z axel $
00002 // Author: Axel Naumann, 2009
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef INCLUDE_TTERMMANIP_H
00013 #define INCLUDE_TTERMMANIP_H
00014 
00015 #include <map>
00016 #include <cstring>
00017 #include <stdio.h>
00018 
00019 extern "C" typedef int (*PutcFunc_t)(int);
00020 
00021 // setupterm must be called before TTermManip can be created!
00022 class TTermManip {
00023 public:
00024    TTermManip();
00025    ~TTermManip() { ResetTerm(); }
00026 
00027    bool SetColor(unsigned char r, unsigned char g, unsigned char b);
00028    bool SetColor(int idx);
00029 
00030    int GetColorIndex(unsigned char r, unsigned char g, unsigned char b);
00031 
00032    void
00033    StartUnderline() {
00034       if (!fCurrentlyUnderlined) {
00035          WriteTerm(fStartUnderline);
00036          fCurrentlyUnderlined = true;
00037       }
00038    }
00039 
00040 
00041    void
00042    StopUnderline() {
00043       if (fCurrentlyUnderlined) {
00044          WriteTerm(fStopUnderline);
00045          fCurrentlyUnderlined = false;
00046       }
00047    }
00048 
00049    void StartBold();
00050    void StopBold();
00051 
00052 
00053    bool ResetTerm();
00054    void SetDefaultColor();
00055 
00056 private:
00057    class Color {
00058    public:
00059       Color(unsigned char r = 0, unsigned char g = 0, unsigned char b = 0):
00060          fR((r* 1001) / 256),
00061          fG((g* 1001) / 256),
00062          fB((b* 1001) / 256) {
00063          // Re-normalize RGB components from 0 to 255 to 0 to 1000
00064       }
00065 
00066 
00067       bool
00068       operator <(const Color& c) const {
00069          return fR < c.fR
00070                 || (fR == c.fR && (fG < c.fG
00071                                    || (fG == c.fG && fB < c.fB)));
00072       }
00073 
00074 
00075       int fR, fG, fB;
00076    };
00077 
00078    char* GetTermStr(const char* cap);
00079    int GetTermNum(const char* cap);
00080 
00081    bool WriteTerm(char* termstr);
00082 
00083    bool WriteTerm(char* termstr, int i);
00084 
00085    static int
00086    DefaultPutchar(int c) {
00087       // tputs takes int(*)(char) on solaris, so wrap putchar
00088       return putchar(c);
00089    }
00090 
00091 
00092    int fNumColors; // number of available colors
00093    bool fAnsiColors; // whether fSetFg, Bg use ANSI
00094    char* fSetFg; // set foreground color
00095    char* fSetBold; // set bold color
00096    char* fSetDefault; // set normal color
00097    char* fStartUnderline; // start underline;
00098    char* fStopUnderline; // stop underline;
00099    PutcFunc_t fPutc;
00100    int fCurrentColorIdx;   // index if the currently active color
00101    bool fCurrentlyBold;  // whether bold is active
00102    bool fCurrentlyUnderlined;  // whether underlining is active
00103 };
00104 
00105 #endif // INCLUDE_TTERMMANIP_H

Generated on Tue Jul 5 14:11:39 2011 for ROOT_528-00b_version by  doxygen 1.5.1