36constexpr double MinHalfFrameRatio = 12.5;
45 "Common Commands for all:\n"
46 " q | Q | Esc -- quit\n"
47 " Backspace -- go back\n"
48 " h | H -- go to show help info\n"
50 "Common Commands for Topology and Channel Message:\n"
51 " PgDn | ^d -- show next page\n"
52 " PgUp | ^u -- show previous page\n"
54 " Up Arrow -- move up one line\n"
55 " Down Arrow -- move down one line\n"
56 " Right Arrow -- enter the selected Channel or Repeated Datum\n"
57 " Left Arrow -- go back to the upper level\n"
59 " Enter -- the same with Right Arrow key\n"
60 " a | A -- the same with Left Arrow key\n"
61 " d | D -- the same with Right Arrow key\n"
62 " w | W -- the same with Up Arrow key\n"
63 " s | S -- the same with Down Arrow key\n"
65 "Commands for Topology message:\n"
66 " f | F -- show frame ratio for all channel messages\n"
67 " t | T -- show channel message type\n"
69 " Space -- Enable|Disable channel Message\n"
71 "Commands for Channel:\n"
72 " i | I -- show Reader and Writers of Channel\n"
73 " b | B -- show Debug String of Channel Message\n"
75 "Commands for Channel Repeated Datum:\n"
76 " n | N -- next repeated data item\n"
77 " m | M -- previous repeated data item\n"
78 " , -- enable|disable to show all repeated items\n";
81 : current_color_pair_(INVALID),
83 current_state_(State::RenderMessage),
84 highlight_direction_(0),
85 current_render_obj_(nullptr) {}
88 current_render_obj_ =
nullptr;
92inline bool Screen::IsInit(
void)
const {
return (stdscr !=
nullptr); }
96 if (stdscr ==
nullptr) {
99 nodelay(stdscr,
true);
100 keypad(stdscr,
true);
110 init_pair(
RED_BLACK, COLOR_RED, COLOR_BLACK);
129 current_color_pair_ = color;
130 attron(COLOR_PAIR(color));
147 attroff(COLOR_PAIR(current_color_pair_));
154 attron(COLOR_PAIR(color));
156 attroff(COLOR_PAIR(color));
164 move(y + offsetY, x + offsetX);
168void Screen::HighlightLine(
int line_no) {
169 if (IsInit() && line_no <
Height()) {
171 for (
int x = 0; x <
Width(); ++x) {
172 chtype ch = mvinch(line_no + highlight_direction_, x);
175 mvaddch(line_no + highlight_direction_, x, ch);
181 for (
int x = 0; x <
Width(); ++x) {
182 chtype ch = mvinch(line_no, x);
183 mvaddch(line_no, x, ch & A_CHARTEXT);
189int Screen::SwitchState(
int ch) {
190 switch (current_state_) {
191 case State::RenderInterCmdInfo:
192 if (KEY_BACKSPACE == ch) {
193 current_state_ = State::RenderMessage;
198 case State::RenderMessage:
199 if (
'h' == ch ||
'H' == ch) {
200 current_state_ = State::RenderInterCmdInfo;
211 if (stdscr ==
nullptr || current_render_obj_ ==
nullptr) {
215 highlight_direction_ = 0;
217 void (
Screen::*showFuncs[])(
int) = {&Screen::ShowRenderMessage,
218 &Screen::ShowInteractiveCmd};
223 if (ch ==
'q' || ch ==
'Q' || ch == 27) {
228 ch = SwitchState(ch);
230 (this->*showFuncs[
static_cast<int>(current_state_)])(ch);
233 if (fr < MinHalfFrameRatio) {
234 fr = MinHalfFrameRatio;
236 int period =
static_cast<int>(1000.0 / fr);
238 std::this_thread::sleep_for(std::chrono::milliseconds(period));
249void Screen::ShowRenderMessage(
int ch) {
251 int line_num = current_render_obj_->
Render(
this, ch);
252 const int max_height = std::min(
Height(), line_num);
254 int* y = current_render_obj_->
line_no();
265 highlight_direction_ = -1;
266 if (*y >= max_height) {
278 highlight_direction_ = 1;
290 current_render_obj_ = p;
306 current_render_obj_ = child;
315void Screen::ShowInteractiveCmd(
int) {
319 AddStr((
Width() - 19) / 2, y++,
"Interactive Command");
322 while (*ptr !=
'\0') {
323 const char* sub = std::strchr(ptr,
'\n');
324 std::string subStr(ptr, sub);
325 AddStr(0, y++, subStr.c_str());
virtual int Render(const Screen *s, int key)=0
RenderableMessage * parent(void) const
virtual double frame_ratio(void)
virtual RenderableMessage * Child(int) const =0
void reset_line_page(void)
void MoveOffsetXY(int offsetX, int offsetY) const
void AddStr(int x, int y, ColorPair color, const char *str) const
static const char InteractiveCmdStr[]
void SetCurrentColor(ColorPair color) const
void ClearCurrentColor(void) const
static Screen * Instance(void)