Source: ColorSetup.hpp

# Source: ColorSetup.hpp |
Annotated List
Files
Globals
Hierarchy
Index

    #ifndef ColorSetup_hpp
    #define ColorSetup_hpp

    #include
    #include "UnixFile.hpp"

    using namespace std;

    /** This class manages color setups for colourized printing
        (primarily of filenames) onto terminals.
        It provides functionality to generate such output.

        An object represents a specific setup.
    */
      // A straight-forward solution to generate coloured output based on the
      // LS_COLORS environment variable.
    class ColorSetup {
      public:
                      /** The built-in setup. */
        static const  ColorSetup BUILT_IN;

        /** Color code for brighter (or bold) text (Only for ISO 6429 compliant
        terminals)*/
        static const  string BRIGHTER;

      protected:
                      string code_str;  // complete LS_COLORS variable
                                        // now some specific codes
        static const  char   ESC= (char) 0x1b;

                      string left_code, right_code, end_code;

                      string color_text,  // normal text, no filename;
                             color_file,
                             color_dir,
                             color_exec,
                             color_symlink,
                             color_blockdev,
                             color_chardev,
                             color_socket,
                             color_pipe;

                      string color_default;   // color used internally if some other color value is empty

                      /** really do colorization? */
      public:         bool do_colorization;

      public:
                      /** initializing from LS_COLORS environment variable,
                      if present, or from built-in setup.*/
                      ColorSetup();

                      /** initialize with given setup */
                      ColorSetup( const string& setup, bool = true);

                      void enableColorization( bool enabled) { do_colorization= enabled; }

                      string format( string s, const string & color_str, bool colored)  const;
                      string format( const string& s, const string & color_str)  const {
                                return format( s, color_str, this->do_colorization);
                      }
                      string formatFilename( const UnixFile& f)  const;
    };

    #endif

Generated by: mw on nemea on Thu Dec 4 21:20:44 2003, using kdoc 2.0a54.