forked from Mirrors/sngrep
UI: more ui refactoring
This commit is contained in:
parent
8223091431
commit
f115522e8d
|
@ -0,0 +1,60 @@
|
|||
/**************************************************************************
|
||||
**
|
||||
** sngrep - SIP Messages flow viewer
|
||||
**
|
||||
** Copyright (C) 2013-2016 Ivan Alonso (Kaian)
|
||||
** Copyright (C) 2013-2016 Irontec SL. All rights reserved.
|
||||
**
|
||||
** 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
****************************************************************************/
|
||||
/**
|
||||
* @file theme.h
|
||||
* @author Ivan Alonso [aka Kaian] <kaian@irontec.com>
|
||||
*
|
||||
* @brief Theme and Color definitions
|
||||
*
|
||||
*/
|
||||
#ifndef __SNGREP_THEME_H
|
||||
#define __SNGREP_THEME_H
|
||||
|
||||
/**
|
||||
* @brief Enum for available color pairs
|
||||
*/
|
||||
enum sngrep_colors_pairs {
|
||||
CP_DEFAULT = 0,
|
||||
CP_CYAN_ON_DEF,
|
||||
CP_YELLOW_ON_DEF,
|
||||
CP_MAGENTA_ON_DEF,
|
||||
CP_GREEN_ON_DEF,
|
||||
CP_RED_ON_DEF,
|
||||
CP_BLUE_ON_DEF,
|
||||
CP_WHITE_ON_DEF,
|
||||
CP_DEF_ON_CYAN,
|
||||
CP_DEF_ON_BLUE,
|
||||
CP_WHITE_ON_BLUE,
|
||||
CP_BLACK_ON_CYAN,
|
||||
CP_WHITE_ON_CYAN,
|
||||
CP_YELLOW_ON_CYAN,
|
||||
CP_BLUE_ON_CYAN,
|
||||
CP_BLUE_ON_WHITE,
|
||||
CP_CYAN_ON_BLACK,
|
||||
CP_CYAN_ON_WHITE,
|
||||
};
|
||||
|
||||
// Used to configure color pairs only with fg color
|
||||
#define COLOR_DEFAULT -1
|
||||
|
||||
|
||||
#endif /* __SNGREP_THEME_H */
|
|
@ -158,7 +158,7 @@ call_flow_draw(ui_t *ui)
|
|||
strcat(title, " (Color by CSeq)");
|
||||
|
||||
// Draw panel title
|
||||
draw_title(ui->panel, title);
|
||||
ui_set_title(ui, title);
|
||||
|
||||
// Show some keybinding
|
||||
call_flow_draw_footer(ui);
|
||||
|
@ -232,7 +232,7 @@ call_flow_draw_footer(ui_t *ui)
|
|||
key_action_key_str(ACTION_INCREASE_RAW), "Increase Raw"
|
||||
};
|
||||
|
||||
draw_keybindings(ui->panel, keybindings, 22);
|
||||
ui_draw_bindings(ui, keybindings, 22);
|
||||
|
||||
// If any dialog has RTP streams and they are not visible
|
||||
if (!setting_enabled(SETTING_CF_MEDIA)) {
|
||||
|
|
|
@ -178,10 +178,10 @@ call_list_draw_header(ui_t *ui)
|
|||
call_list_info_t *info = call_list_info(ui);
|
||||
|
||||
// Draw panel title
|
||||
draw_title(ui->panel, "sngrep - SIP messages flow viewer");
|
||||
ui_set_title(ui, "sngrep - SIP messages flow viewer");
|
||||
|
||||
// Draw a Panel header lines
|
||||
clear_line(ui->win, 1);
|
||||
ui_clear_line(ui, 1);
|
||||
if ((infile = capture_input_file()))
|
||||
mvwprintw(ui->win, 1, ui->width - strlen(infile) - 11, "Filename: %s", infile);
|
||||
mvwprintw(ui->win, 2, 2, "Display Filter: ");
|
||||
|
@ -241,7 +241,7 @@ call_list_draw_footer(ui_t *ui)
|
|||
key_action_key_str(ACTION_SHOW_COLUMNS), "Columns"
|
||||
};
|
||||
|
||||
draw_keybindings(ui->panel, keybindings, 22);
|
||||
ui_draw_bindings(ui, keybindings, 22);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -304,7 +304,7 @@ call_list_draw_list(ui_t *ui)
|
|||
wattron(list_win, A_REVERSE);
|
||||
}
|
||||
// Set current line background
|
||||
clear_line(list_win, cline);
|
||||
mvwprintw(list_win, cline, 0, "%*s", listw, "");
|
||||
// Set current line selection box
|
||||
mvwprintw(list_win, cline, 2, call_group_exists(info->group, call) ? "[*]" : "[ ]");
|
||||
|
||||
|
@ -351,7 +351,6 @@ call_list_draw_list(ui_t *ui)
|
|||
// Draw scrollbar to the right
|
||||
draw_vscrollbar(list_win, info->first_line, info->dispcallcnt, 1);
|
||||
wnoutrefresh(info->list_win);
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -314,61 +314,6 @@ title_foot_box(PANEL *panel)
|
|||
|
||||
}
|
||||
|
||||
void
|
||||
draw_keybindings(PANEL *panel, const char *keybindings[], int count)
|
||||
{
|
||||
int height, width, key, xpos = 0;
|
||||
|
||||
// Get window available space
|
||||
WINDOW *win = panel_window(panel);
|
||||
getmaxyx(win, height, width);
|
||||
|
||||
// Reverse colors on monochrome terminals
|
||||
if (!has_colors())
|
||||
wattron(win, A_REVERSE);
|
||||
|
||||
// Write a line all the footer width
|
||||
wattron(win, COLOR_PAIR(CP_DEF_ON_CYAN));
|
||||
clear_line(win, height - 1);
|
||||
|
||||
// Draw keys and their actions
|
||||
for (key = 0; key < count; key += 2) {
|
||||
wattron(win, A_BOLD | COLOR_PAIR(CP_WHITE_ON_CYAN));
|
||||
mvwprintw(win, height - 1, xpos, "%-*s", strlen(keybindings[key]) + 1, keybindings[key]);
|
||||
xpos += strlen(keybindings[key]) + 1;
|
||||
wattroff(win, A_BOLD | COLOR_PAIR(CP_WHITE_ON_CYAN));
|
||||
wattron(win, COLOR_PAIR(CP_BLACK_ON_CYAN));
|
||||
mvwprintw(win, height - 1, xpos, "%-*s", strlen(keybindings[key + 1]) + 1,
|
||||
keybindings[key + 1]);
|
||||
wattroff(win, COLOR_PAIR(CP_BLACK_ON_CYAN));
|
||||
xpos += strlen(keybindings[key + 1]) + 3;
|
||||
}
|
||||
|
||||
// Disable reverse mode in all cases
|
||||
wattroff(win, A_REVERSE);
|
||||
}
|
||||
|
||||
void
|
||||
draw_title(PANEL *panel, const char *title)
|
||||
{
|
||||
int height, width;
|
||||
|
||||
// Get window available space
|
||||
WINDOW *win = panel_window(panel);
|
||||
getmaxyx(win, height, width);
|
||||
|
||||
// Reverse colors on monochrome terminals
|
||||
if (!has_colors())
|
||||
wattron(win, A_REVERSE);
|
||||
|
||||
// Center the title on the window
|
||||
wattron(win, A_BOLD | COLOR_PAIR(CP_DEF_ON_CYAN));
|
||||
clear_line(win, 0);
|
||||
mvwprintw(win, 0, (width - strlen(title)) / 2, "%s", title);
|
||||
wattroff(win, A_BOLD | A_REVERSE | COLOR_PAIR(CP_DEF_ON_CYAN));
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
draw_vscrollbar(WINDOW *win, int value, int max, int left)
|
||||
{
|
||||
|
@ -400,15 +345,6 @@ draw_vscrollbar(WINDOW *win, int value, int max, int left)
|
|||
|
||||
}
|
||||
|
||||
void
|
||||
clear_line(WINDOW *win, int line)
|
||||
{
|
||||
// We could do this with wcleartoel but we want to
|
||||
// preserve previous window attributes. That way we
|
||||
// can set the background of the line.
|
||||
mvwprintw(win, line, 0, "%*s", getmaxx(win), "");
|
||||
}
|
||||
|
||||
int
|
||||
draw_message(WINDOW *win, sip_msg_t *msg)
|
||||
{
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#ifndef __SNGREP_UI_MANAGER_H
|
||||
#define __SNGREP_UI_MANAGER_H
|
||||
#include "config.h"
|
||||
#include "theme.h"
|
||||
#include "ui_panel.h"
|
||||
#include "sip.h"
|
||||
#include "group.h"
|
||||
|
@ -48,32 +49,6 @@
|
|||
#define DIALOG_MAX_WIDTH 100
|
||||
#define DIALOG_MIN_WIDTH 40
|
||||
|
||||
/**
|
||||
* @brief Enum for available color pairs
|
||||
*/
|
||||
enum sngrep_colors_pairs {
|
||||
CP_DEFAULT = 0,
|
||||
CP_CYAN_ON_DEF,
|
||||
CP_YELLOW_ON_DEF,
|
||||
CP_MAGENTA_ON_DEF,
|
||||
CP_GREEN_ON_DEF,
|
||||
CP_RED_ON_DEF,
|
||||
CP_BLUE_ON_DEF,
|
||||
CP_WHITE_ON_DEF,
|
||||
CP_DEF_ON_CYAN,
|
||||
CP_DEF_ON_BLUE,
|
||||
CP_WHITE_ON_BLUE,
|
||||
CP_BLACK_ON_CYAN,
|
||||
CP_WHITE_ON_CYAN,
|
||||
CP_YELLOW_ON_CYAN,
|
||||
CP_BLUE_ON_CYAN,
|
||||
CP_BLUE_ON_WHITE,
|
||||
CP_CYAN_ON_BLACK,
|
||||
CP_CYAN_ON_WHITE,
|
||||
};
|
||||
|
||||
// Used to configure color pairs only with fg color
|
||||
#define COLOR_DEFAULT -1
|
||||
|
||||
/**
|
||||
* Define existing panels
|
||||
|
@ -166,28 +141,6 @@ default_handle_key(ui_t *ui, int key);
|
|||
void
|
||||
title_foot_box(PANEL *panel);
|
||||
|
||||
/**
|
||||
* @brief Draw title at the top of the panel
|
||||
*
|
||||
* This function will draw a line with the title on the first
|
||||
* row of the panel's window
|
||||
*
|
||||
* @param panel PANEL pointer to draw title on
|
||||
* @param title String containing the title
|
||||
*/
|
||||
void
|
||||
draw_title(PANEL *panel, const char *title);
|
||||
|
||||
/**
|
||||
* @brief Draw keybinding info at the bottom of the panel
|
||||
*
|
||||
* This function will draw a line with the available keybindings
|
||||
* in the last line of the given panel
|
||||
*
|
||||
*/
|
||||
void
|
||||
draw_keybindings(PANEL *panel, const char *keybindings[], int count);
|
||||
|
||||
/**
|
||||
* @brief Draw a vertical scroll
|
||||
*
|
||||
|
@ -197,15 +150,6 @@ draw_keybindings(PANEL *panel, const char *keybindings[], int count);
|
|||
void
|
||||
draw_vscrollbar(WINDOW *win, int value, int max, int left);
|
||||
|
||||
/**
|
||||
* @brief Clear a given window line
|
||||
*
|
||||
* This function can be used to clear a given line on the
|
||||
* screen.
|
||||
*/
|
||||
void
|
||||
clear_line(WINDOW *win, int line);
|
||||
|
||||
/**
|
||||
* @brief Draw a message payload in a window
|
||||
*
|
||||
|
|
|
@ -91,7 +91,7 @@ msg_diff_create(ui_t *ui)
|
|||
mvwvline(ui->win, 0, hwidth, ACS_VLINE, ui->height);
|
||||
|
||||
// Draw title
|
||||
draw_title(ui->panel, "sngrep - SIP messages flow viewer");
|
||||
ui_set_title(ui, "sngrep - SIP messages flow viewer");
|
||||
|
||||
// Draw keybindings
|
||||
msg_diff_draw_footer(ui);
|
||||
|
@ -148,7 +148,7 @@ msg_diff_draw_footer(ui_t *ui)
|
|||
key_action_key_str(ACTION_SHOW_HELP), "Help"
|
||||
};
|
||||
|
||||
draw_keybindings(ui->panel, keybindings, 4);
|
||||
ui_draw_bindings(ui, keybindings, 4);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "ui_panel.h"
|
||||
#include <string.h>
|
||||
#include "theme.h"
|
||||
|
||||
ui_t *
|
||||
ui_create(ui_t *ui)
|
||||
|
@ -149,3 +151,59 @@ ui_panel_destroy(ui_t *ui)
|
|||
// Deallocate panel pointer
|
||||
del_panel(ui->panel);
|
||||
}
|
||||
|
||||
void
|
||||
ui_set_title(ui_t *ui, const char *title)
|
||||
{
|
||||
// FIXME Reverse colors on monochrome terminals
|
||||
if (!has_colors()) {
|
||||
wattron(ui->win, A_REVERSE);
|
||||
}
|
||||
|
||||
// Center the title on the window
|
||||
wattron(ui->win, A_BOLD | COLOR_PAIR(CP_DEF_ON_CYAN));
|
||||
ui_clear_line(ui, 0);
|
||||
mvwprintw(ui->win, 0, (ui->width - strlen(title)) / 2, "%s", title);
|
||||
wattroff(ui->win, A_BOLD | A_REVERSE | COLOR_PAIR(CP_DEF_ON_CYAN));
|
||||
}
|
||||
|
||||
void
|
||||
ui_clear_line(ui_t *ui, int line)
|
||||
{
|
||||
// We could do this with wcleartoel but we want to
|
||||
// preserve previous window attributes. That way we
|
||||
// can set the background of the line.
|
||||
mvwprintw(ui->win, line, 0, "%*s", ui->width, "");
|
||||
}
|
||||
|
||||
void
|
||||
ui_draw_bindings(ui_t *ui, const char *keybindings[], int count)
|
||||
{
|
||||
int key, xpos = 0;
|
||||
|
||||
// Reverse colors on monochrome terminals
|
||||
if (!has_colors()) {
|
||||
wattron(ui->win, A_REVERSE);
|
||||
}
|
||||
|
||||
// Write a line all the footer width
|
||||
wattron(ui->win, COLOR_PAIR(CP_DEF_ON_CYAN));
|
||||
ui_clear_line(ui, ui->height - 1);
|
||||
|
||||
// Draw keys and their actions
|
||||
for (key = 0; key < count; key += 2) {
|
||||
wattron(ui->win, A_BOLD | COLOR_PAIR(CP_WHITE_ON_CYAN));
|
||||
mvwprintw(ui->win, ui->height - 1, xpos, "%-*s",
|
||||
strlen(keybindings[key]) + 1, keybindings[key]);
|
||||
xpos += strlen(keybindings[key]) + 1;
|
||||
wattroff(ui->win, A_BOLD | COLOR_PAIR(CP_WHITE_ON_CYAN));
|
||||
wattron(ui->win, COLOR_PAIR(CP_BLACK_ON_CYAN));
|
||||
mvwprintw(ui->win, ui->height - 1, xpos, "%-*s",
|
||||
strlen(keybindings[key + 1]) + 1, keybindings[key + 1]);
|
||||
wattroff(ui->win, COLOR_PAIR(CP_BLACK_ON_CYAN));
|
||||
xpos += strlen(keybindings[key + 1]) + 3;
|
||||
}
|
||||
|
||||
// Disable reverse mode in all cases
|
||||
wattroff(ui->win, A_REVERSE | A_BOLD);
|
||||
}
|
||||
|
|
|
@ -199,5 +199,38 @@ ui_panel_create(ui_t *ui, int height, int width);
|
|||
void
|
||||
ui_panel_destroy(ui_t *ui);
|
||||
|
||||
/**
|
||||
* @brief Draw title at the top of the panel UI
|
||||
*
|
||||
* This function will draw a line with the title on the first
|
||||
* row of the UI panel's window
|
||||
*
|
||||
* @param ui UI structure
|
||||
* @param title String containing the title
|
||||
*/
|
||||
void
|
||||
ui_set_title(ui_t *ui, const char *title);
|
||||
|
||||
/**
|
||||
* @brief Clear a given window line
|
||||
*
|
||||
* This function can be used to clear a given line on the
|
||||
* screen.
|
||||
*
|
||||
* @param ui UI structure
|
||||
* @param line Number of line to be cleared
|
||||
*/
|
||||
void
|
||||
ui_clear_line(ui_t *ui, int line);
|
||||
|
||||
/**
|
||||
* @brief Draw keybinding info at the bottom of the panel
|
||||
*
|
||||
* This function will draw a line with the available keybindings
|
||||
* in the last line of the given panel
|
||||
*
|
||||
*/
|
||||
void
|
||||
ui_draw_bindings(ui_t *ui, const char *keybindings[], int count);
|
||||
|
||||
#endif /* __SNGREP_UI_PANEL_H */
|
||||
|
|
Loading…
Reference in New Issue