Skip to content

Commit

Permalink
rosmon_core: Adding verbosity filter feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Cartoonman committed May 25, 2020
1 parent 634f754 commit b927232
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
18 changes: 17 additions & 1 deletion rosmon_core/src/terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <term.h>
#include <curses.h>
#include <iostream>

// really?
#ifdef columns
Expand Down Expand Up @@ -60,14 +61,18 @@ void Terminal::Parser::parseSetAttributes(const std::string& str)
m_bgColor = {};
}
else if(code >= 30 && code <= 37)
m_fgColor = m_term->color(static_cast<SimpleColor>(code - 30));
{
m_fgCode = code - 30;
m_fgColor = m_term->color(static_cast<SimpleColor>(m_fgCode));
}
else if(code >= 40 && code <= 47)
m_bgColor = m_term->color(static_cast<SimpleColor>(code - 40));
else if(code == 1)
m_bold = true;
}
}


bool Terminal::Parser::parse(char c)
{
if(!m_term)
Expand Down Expand Up @@ -108,6 +113,17 @@ bool Terminal::Parser::parse(char c)
return false;
}

void Terminal::Parser::resetForegroundCode()
{
m_fgCode = -1;
}

int Terminal::Parser::getForegroundCode()
{
return m_fgCode;
}


void Terminal::Parser::parse(const std::string& str)
{
if(!m_term)
Expand Down
6 changes: 5 additions & 1 deletion rosmon_core/src/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class Terminal
//! parse string
void parse(const std::string& str);

int getForegroundCode();
void resetForegroundCode();

//! Apply the current internal state (colors) on the terminal
void apply();

Expand All @@ -123,7 +126,7 @@ class Terminal
std::vector<std::string> wrap(const std::string& str, unsigned int columns);
private:
void parseSetAttributes(const std::string& str);

int parseSetAttributesColorOnly(const std::string& str);
enum State
{
STATE_ESCAPE,
Expand All @@ -138,6 +141,7 @@ class Terminal

Color m_fgColor;
Color m_bgColor;
int m_fgCode;
bool m_bold = false;
};

Expand Down
58 changes: 56 additions & 2 deletions rosmon_core/src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ UI::UI(monitor::Monitor* monitor, const FDWatcher::Ptr& fdWatcher)
, m_fdWatcher(fdWatcher)
, m_columns(80)
, m_selectedNode(-1)
, m_verbosityLevel(2)
{
std::atexit(cleanup);
m_monitor->logMessageSignal.connect(boost::bind(&UI::log, this, _1));
Expand Down Expand Up @@ -209,13 +210,20 @@ void UI::drawStatusLine()
else
{
printKey("A-Z", "Node actions");
printKey("F6-F8", "Verbosity");
printKey("F9", "Mute all");
printKey("F10", "Unmute all");
printKey("/", "Node search");

// Print verbosity level
print(" ");
m_term.setSimpleForeground(Terminal::Black);
m_term.setSimpleBackground(Terminal::White);
print(" Verbosity: {} ", m_verbosityLevel);
m_style_bar.use();
if(anyMuted())
{
print(" ");
print(" ");
m_term.setSimpleForeground(Terminal::Black);
m_term.setSimpleBackground(Terminal::Yellow);
print("! Caution: Nodes muted !");
Expand Down Expand Up @@ -404,11 +412,32 @@ void UI::log(const LogEvent& event)
// Is this a node message?
if(it != m_nodeColorMap.end())
{
m_term.setLineWrap(false);
// Reset fg code for verbosity level checking
it->second.parser.resetForegroundCode();

auto actualLabelWidth = std::max<unsigned int>(m_nodeLabelWidth, event.source.size());
auto lines = it->second.parser.wrap(clean, m_columns - actualLabelWidth - 2);

// Check verbosity filter
auto color = it->second.parser.getForegroundCode();
switch (color)
{
case -1: // INFO
if (m_verbosityLevel < 2)
return;
break;
case 1: // ERR/FATAL
break;
case 2: // DEBUG
if (m_verbosityLevel < 3)
return;
break;
case 3: // WARN
break;
}

m_term.setLineWrap(false);

for(unsigned int line = 0; line < lines.size(); ++line)
{
// Draw label
Expand Down Expand Up @@ -649,6 +678,26 @@ void UI::handleKey(int c)
return;
}

// Check for toggling of verbosity modes

if(c == Terminal::SK_F6)
{
setVerbosityLevel(1);
return;
}

if(c == Terminal::SK_F7)
{
setVerbosityLevel(2);
return;
}

if(c == Terminal::SK_F8)
{
setVerbosityLevel(3);
return;
}

// Search
if(c == '/')
{
Expand Down Expand Up @@ -723,4 +772,9 @@ void UI::scheduleUpdate()
m_refresh_required = true;
}

void UI::setVerbosityLevel(int level)
{
m_verbosityLevel = level;
}

}
3 changes: 3 additions & 0 deletions rosmon_core/src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ class UI
void unmuteAll();

void scheduleUpdate();

void setVerbosityLevel(int level);

monitor::Monitor* m_monitor;
FDWatcher::Ptr m_fdWatcher;
bool m_refresh_required = true;

Terminal m_term;

int m_verbosityLevel;
int m_columns;
ros::WallTimer m_sizeTimer;
ros::WallTimer m_terminalCheckTimer;
Expand Down

0 comments on commit b927232

Please sign in to comment.