BashColor.cpp 2.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
/***************************************************************************
 *   Copyright (c) IPNL, IN2P3, CNRS                                       *
 *   Contibutor(s) :                                                       *
 *      Jeremie Dudouet  dudouet(AT)ipnl.in2p3.fr [2014]                   *
 *      Olivier Stezowski stezow(AT)ipnl.in2p3.fr [2014]                   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "BashColor.h"

BashColor::BashColor()
{   
    fColor = "";
    fType = "0;3";
}

BashColor::~BashColor()
{

}

void BashColor::SetType(bType type)
{
    switch (type) {
    case kRegular:
        fType = "0;3";
        break;
    case kBold:
        fType = "1;3";
        break;
    case kUnderline:
        fType = "4;3";
        break;
    case kBoldUnderline:
        fType = "1;4;3";
        break;
    case kBackGround:
        fType = "0;4";
        break;
    case kHighIntensity:
        fType = "0;9";
        break;
    case kBoldHighIntensity:
        fType = "1;9";
        break;
    case kHighIntensityBackground:
        fType = "0;10";
        break;
    }
    ProcessColor();
}

void BashColor::SetColor(BColor col)
{
    std::ostringstream oss;
    oss<<col;
    fColor = oss.str();

    ProcessColor();
}

void BashColor::ProcessColor()
{
    std::string s = "\e[" + fType + fColor + "m";
    std::cout<<s;
}

void BashColor::ResetColor()
{
    fColor = "";
    fType = "0";

    ProcessColor();

    fColor = "";
    fType = "0;3";
}


void BashColor::SetErrorOut()
{
    SetColor(kRed);
    SetType(kBoldHighIntensity);
}

void BashColor::SetWarningOut()
{
    SetColor(kYellow);
    SetType(kBoldUnderline);
}

void BashColor::SetInfoOut()
{
    SetColor(kBlue);
    SetType(kBoldHighIntensity);
}