Go to the documentation of this file.
10 #include <fmt/format.h>
38 , m_fdWatcher(fdWatcher)
90 fdWatcher->registerFD(STDIN_FILENO, boost::bind(&
UI::readInput,
this));
103 for(
int i = 0; i < n; ++i)
105 float hue = i * 360 / n;
117 std::min(255, std::max(0,
static_cast<int>(r)))
118 | (std::min(255, std::max(0,
static_cast<int>(g))) << 8)
119 | (std::min(255, std::max(0,
static_cast<int>(
b))) << 16);
131 constexpr
unsigned int column()
const
134 template<
typename ... Args>
135 void operator()(Args&& ... args)
137 std::string str = fmt::format(std::forward<Args>(args)...);
139 fputs(str.c_str(), stdout);
148 std::string fullName;
150 fullName = node.
name();
155 if(!fullName.empty() && fullName[0] ==
'/')
156 fullName = fullName.substr(1);
158 return fullName.substr(0, maxWidth);
163 const int NODE_WIDTH = 13;
165 unsigned int lines = 0;
186 auto printKey = [&](
const std::string& key,
const std::string& label) {
190 print(
" {} ", label);
205 switch(selectedNode->state())
211 default:
state =
"<UNKNOWN>";
break;
214 print(
"Node '{}' {}. Actions: ", selectedNode->fullName(),
state);
215 printKey(
"s",
"start");
216 printKey(
"k",
"stop");
217 printKey(
"d",
"debug");
219 if(selectedNode->isMuted())
220 printKey(
"u",
"unmute");
222 printKey(
"m",
"mute");
226 printKey(
"A-Z",
"Node actions");
227 printKey(
"F6",
"Start all");
228 printKey(
"F7",
"Stop all");
229 printKey(
"F8",
"Toggle WARN+ only");
230 printKey(
"F9",
"Mute all");
231 printKey(
"F10",
"Unmute all");
232 printKey(
"/",
"Node search");
239 print(
"! WARN+ output only !");
248 print(
"! Caution: Nodes muted !");
271 constexpr
auto SEARCH_NODE_WIDTH = NODE_WIDTH+3;
273 std::size_t nodeWidth = SEARCH_NODE_WIDTH;
275 nodeWidth = std::max(nodeWidth,
nodeDisplayName(*nodes[nodeIdx]).length());
279 nodeWidth = SEARCH_NODE_WIDTH;
281 const int BLOCK_WIDTH = nodeWidth;
292 fmt::print(
"{:^{}}", label, nodeWidth);
303 else if(col + 1 + BLOCK_WIDTH >
m_columns)
331 fmt::print(
"{:c}", key);
341 switch(node->state())
359 switch(node->state())
378 fmt::print(
"[{:^{}}]", label, NODE_WIDTH);
380 fmt::print(
" {:^{}} ", label, NODE_WIDTH);
384 const int BLOCK_WIDTH = NODE_WIDTH + 3;
392 else if(col + 1 + BLOCK_WIDTH >
m_columns)
431 std::string
clean =
event.coloredString();
442 auto lines = parser.wrap(
clean,
m_columns - actualLabelWidth - 2);
444 for(
unsigned int line = 0; line < lines.size(); ++line)
464 for(
unsigned int i = 0; i < actualLabelWidth-1; ++i)
472 fputs(lines[line].c_str(), stdout);
485 unsigned int len =
clean.length();
486 while(len != 0 && (
clean[len-1] ==
'\n' ||
clean[len-1] ==
'\r'))
505 fwrite(
clean.c_str(), 1, len, stdout);
552 w = std::max(w, node->fullName().size());
640 if(row < numRows - 1)
651 else if(std::isgraph(c))
659 for(
unsigned int i = 0; i < nodes.size(); ++i)
661 const auto& node = nodes[i];
663 if(idx != std::string::npos)
717 if(c >=
'a' && c <=
'z')
719 else if(c >=
'A' && c <=
'Z')
720 nodeIndex = 26 + c -
'A';
721 else if(c >=
'0' && c <=
'9')
722 nodeIndex = 26 + 26 + c -
'0';
724 if(nodeIndex < 0 || (
size_t)nodeIndex >=
m_monitor->
nodes().size())
742 node->launchDebugger();
745 node->setMuted(
true);
748 node->setMuted(
false);
Terminal::Style m_style_bar
static unsigned int g_statusLines
ros::WallTimer m_terminalCheckTimer
void moveCursorToStartOfLine()
Move cursor to start of the line.
void log(const LogEvent &event)
Terminal::Style m_style_nodeCrashed
unsigned int m_searchSelectedIndex
Color color(SimpleColor code)
void setCursorVisible()
restore cursor
UI(monitor::Monitor *monitor, const FDWatcher::Ptr &fdWatcher)
ros::WallTimer m_sizeTimer
Terminal::Style m_style_barLine
Terminal::Style m_style_nodeRunningFaded
void setCursorInvisible()
hide cursor
void HUSLtoRGB(float *r, float *g, float *b, float h, float s, float l)
void setBackgroundColor(uint32_t color)
Set 24-bit background color.
std::map< std::string, ChannelInfo > m_nodeColorMap
static std::string g_windowTitle
ROSCPP_DECL std::string clean(const std::string &name)
Terminal::Style m_style_nodeIdleFaded
Terminal::Style m_style_nodeRunning
launch::LaunchConfig::ConstPtr config() const
std::vector< unsigned int > m_searchNodes
std::shared_ptr< NodeMonitor > Ptr
FDWatcher::Ptr m_fdWatcher
void setLineWrap(bool on)
void clearToEndOfLine()
Clear characters from cursor to end of line.
Terminal::Style m_style_nodeWaitingFaded
Terminal::Style m_style_nodeIdle
unsigned int m_nodeLabelWidth
void setSimplePair(SimpleColor fg, SimpleColor bg)
const std::vector< NodeMonitor::Ptr > & nodes() const
Terminal::Style m_style_nodeWaiting
Terminal::Style m_style_nodeKey
std::string name() const
Node name.
Terminal::Style m_style_nodeKeyMuted
std::string nodeDisplayName(monitor::NodeMonitor &node, std::size_t maxWidth=std::string::npos)
void setSimpleBackground(SimpleColor color)
void setStandardColors()
Reset fg + bg to standard terminal colors.
Terminal::Color m_color_bar
void setWindowTitle(const std::string &title)
@ STATE_IDLE
Idle (e.g. exited with code 0)
void moveCursorUp(int numLines)
Move cursor up by numLines.
bool has256Colors() const
void clearWindowTitle(const std::string &backup)
std::string namespaceString() const
Node namespace.
boost::signals2::signal< void(LogEvent)> logMessageSignal
Terminal::Style m_style_nodeCrashedFaded
monitor::Monitor * m_monitor
unsigned int m_searchDisplayColumns
Encapsulates terminal control.
Terminal::Style m_style_barHighlight
ROSCONSOLE_DECL void print(FilterBase *filter, void *logger, Level level, const char *file, int line, const char *function, const char *fmt,...) ROSCONSOLE_PRINTF_ATTRIBUTE(7
@ STATE_WAITING
Waiting for automatic restart after crash.
Terminal::Style m_style_barKey
void setSimpleForeground(SimpleColor color)
@ STATE_CRASHED
Crashed (i.e. exited with code != 0)
std::string m_searchString
bool getSize(int *columns, int *rows)
Get current window size.
Monitors a single node process.
rosmon_core
Author(s): Max Schwarz
autogenerated on Wed Feb 21 2024 04:01:14