Changeset 16968 for trunk/FACT++


Ignore:
Timestamp:
07/20/13 14:38:16 (11 years ago)
Author:
tbretz
Message:
Added a possibility to strip color codes.
File:
1 edited

Legend:

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

    r16884 r16968  
    1919        ("end,e",     var<string>(), "End time to be displayed (e.g. 21:00:13)")
    2020        ("verbose,v", var<int16_t>()->implicit_value(true)->default_value(8), "Verbosity level (0:only fatal errors, 8:everything)")
    21         ("color,c",   po_bool(false), "Process a file which already contains color codes")
     21        ("color,c",   po_switch(), "Process a file which already contains color codes")
     22        ("strip,s",   po_switch(), "Strip color codes completely")
    2223        ;
    2324
     
    6566
    6667
    67 void showlog(string fname, const Time &tbeg, const Time &tend, int16_t severity, bool color)
     68void showlog(string fname, const Time &tbeg, const Time &tend, int16_t severity, bool color, bool strip)
    6869{
    6970    // Alternatives
     
    7172    // \x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]
    7273    // \x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]
    73     const boost::regex reg("\x1B\[[0-9;]*[a-zA-Z]");
     74    const boost::regex reg("\x1B\[([0-9]{1,3}(;[0-9]{1,3})?[a-zA-Z]");
    7475
    7576    const uint32_t night = atoi(fname.c_str());
     
    9394    while (getline(fin, buffer, '\n'))
    9495    {
    95         if (color)
     96        if (color || strip)
    9697            buffer = boost::regex_replace(buffer, reg, "");
    9798
     
    130131        }
    131132
    132         if (buffer.size()>1)
     133        if (buffer.size()>1 && !strip)
    133134        {
    134135            int16_t lvl = -1;
     
    161162        }
    162163
    163         log << buffer << endl;
     164        (strip?cout:log) << buffer << endl;
    164165    }
    165166}
     
    194195
    195196    if (files.size()==0)
    196         showlog("", tbeg, tend, conf.Get<int16_t>("verbose"), conf.Get<bool>("color"));
     197        showlog("", tbeg, tend, conf.Get<int16_t>("verbose"), conf.Get<bool>("color"), conf.Get<bool>("strip"));
    197198
    198199    for (auto it=files.begin(); it!=files.end(); it++)
    199         showlog(*it, tbeg, tend, conf.Get<int16_t>("verbose"), conf.Get<bool>("color"));
     200        showlog(*it, tbeg, tend, conf.Get<int16_t>("verbose"), conf.Get<bool>("color"), conf.Get<bool>("strip"));
    200201
    201202    return 0;
Note: See TracChangeset for help on using the changeset viewer.