forked from Mirrors/sngrep
Reworked Call Raw scroll
This commit is contained in:
parent
2c7c381cda
commit
cb51d66196
|
@ -92,10 +92,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
// Initialize interface
|
||||
// This is a blocking call. Interface have user action loops.
|
||||
ret = init_interface(config);
|
||||
if (ret == 127) {
|
||||
fprintf(stderr, "%s requires at least %d columns in terminal :(\n", argv[0], UI_MIN_COLS);
|
||||
}
|
||||
init_interface(config);
|
||||
|
||||
// Leaving!
|
||||
return ret;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <string.h>
|
||||
#include "ui_manager.h"
|
||||
#include "ui_call_flow.h"
|
||||
#include "ui_call_raw.h"
|
||||
|
||||
/**
|
||||
* @brief Call flow status information
|
||||
|
@ -189,6 +190,7 @@ int call_flow_handle_key(PANEL *panel, int key)
|
|||
int i, rnpag_steps = 4;
|
||||
call_flow_info_t *info = (call_flow_info_t*) panel_userptr(panel);
|
||||
sip_msg_t *next = NULL, *prev = NULL;
|
||||
ui_t *next_panel;
|
||||
|
||||
// Sanity check, this should not happen
|
||||
if (!info) return -1;
|
||||
|
@ -235,6 +237,12 @@ int call_flow_handle_key(PANEL *panel, int key)
|
|||
break;
|
||||
case 10:
|
||||
break;
|
||||
case 'r':
|
||||
case 'R':
|
||||
// KEY_R, display current call in raw mode
|
||||
next_panel = ui_create(RAW_PANEL);
|
||||
call_raw_set_call(info->call);
|
||||
wait_for_input(next_panel);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,9 @@
|
|||
PANEL *call_raw_create()
|
||||
{
|
||||
PANEL *panel;
|
||||
WINDOW *win;
|
||||
call_raw_info_t *info;
|
||||
int height, width;
|
||||
|
||||
// Create a new panel to fill all the screen
|
||||
panel = new_panel(newwin(LINES, COLS, 0, 0));
|
||||
|
@ -37,6 +39,14 @@ PANEL *call_raw_create()
|
|||
// Store it into panel userptr
|
||||
set_panel_userptr(panel, (void*) info);
|
||||
|
||||
// Let's draw the fixed elements of the screen
|
||||
win = panel_window(panel);
|
||||
getmaxyx(win, height, width);
|
||||
|
||||
// Calculate available printable area
|
||||
info->linescnt = height;
|
||||
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
|
@ -44,20 +54,33 @@ int call_raw_draw(PANEL *panel)
|
|||
{
|
||||
struct sip_msg *msg = NULL;
|
||||
int pline = 0, raw_line;
|
||||
const char *all_lines[1024];
|
||||
int all_linescnt = 0;
|
||||
|
||||
// Get panel information
|
||||
call_raw_info_t *info = (call_raw_info_t*) panel_userptr(panel);
|
||||
// Get window of main panel
|
||||
WINDOW *win = panel_window(panel);
|
||||
wclear(win);
|
||||
|
||||
mvwprintw(win, pline++, 0, "%d", info->scrollpos);
|
||||
|
||||
/*
|
||||
FIXME This part could be coded decently.
|
||||
A better aproach is creating a pad window and copy the visible area
|
||||
into the panel window, taking into account the scroll position.
|
||||
This is dirty but easier to manage by now
|
||||
*/
|
||||
memset(all_lines, 0, 1024);
|
||||
while ((msg = get_next_msg(info->call, msg))) {
|
||||
for (raw_line = 0; raw_line < msg->plines; raw_line++) {
|
||||
mvwprintw(win, pline, 0, "%s", msg->payload[raw_line]);
|
||||
pline++;
|
||||
all_lines[all_linescnt++] = msg->payload[raw_line];
|
||||
}
|
||||
pline++;
|
||||
all_linescnt+=2;
|
||||
}
|
||||
info->all_lines = all_linescnt;
|
||||
|
||||
for (raw_line = info->scrollpos; raw_line - info->scrollpos < info->linescnt; raw_line++){
|
||||
if (all_lines[raw_line])
|
||||
mvwprintw(win, pline, 0, "%s", all_lines[raw_line]);
|
||||
pline++;
|
||||
}
|
||||
return 0;
|
||||
|
@ -65,7 +88,7 @@ int call_raw_draw(PANEL *panel)
|
|||
|
||||
int call_raw_handle_key(PANEL *panel, int key)
|
||||
{
|
||||
int i, rnpag_steps = 5;
|
||||
int i, rnpag_steps = 10;
|
||||
call_raw_info_t *info = (call_raw_info_t*) panel_userptr(panel);
|
||||
|
||||
// Sanity check, this should not happen
|
||||
|
@ -76,9 +99,13 @@ int call_raw_handle_key(PANEL *panel, int key)
|
|||
switch (key) {
|
||||
case KEY_DOWN:
|
||||
info->scrollpos++;
|
||||
if (info->scrollpos + info->linescnt >= info->all_lines)
|
||||
info->scrollpos--;
|
||||
break;
|
||||
case KEY_UP:
|
||||
info->scrollpos--;
|
||||
if (info->scrollpos <= 0)
|
||||
info->scrollpos = 0;
|
||||
break;
|
||||
case KEY_NPAGE:
|
||||
// Next page => N key down strokes
|
||||
|
|
|
@ -35,6 +35,8 @@ typedef struct call_raw_info call_raw_info_t;
|
|||
struct call_raw_info {
|
||||
sip_call_t *call;
|
||||
int scrollpos;
|
||||
int linescnt;
|
||||
int all_lines;
|
||||
};
|
||||
|
||||
extern PANEL *call_raw_create();
|
||||
|
|
|
@ -25,13 +25,6 @@
|
|||
#include <panel.h>
|
||||
#include "sip.h"
|
||||
|
||||
/**
|
||||
* The actual UI is not very flexible. It requires a lot of space to
|
||||
* be correctyle drawn.. It would be nice to be more adaptative and hide
|
||||
* some columns in main panel depending on the available columns
|
||||
*/
|
||||
#define UI_MIN_COLS 175
|
||||
|
||||
//! Shorter declaration of ui structure
|
||||
typedef struct ui ui_t;
|
||||
|
||||
|
@ -48,15 +41,18 @@ struct ui
|
|||
PANEL *panel;
|
||||
//! Constructor for this panel
|
||||
PANEL *(*create)();
|
||||
//! Reques the panel to redraw its data
|
||||
//! Destroy current panel
|
||||
void (*destroy)(PANEL *);
|
||||
//! Request the panel to redraw its data
|
||||
int (*draw)(PANEL*);
|
||||
//! Check if the panel request redraw with given msg
|
||||
int (*redraw_required)(PANEL *, sip_msg_t *);
|
||||
//! Handle a custom keybind on this panel
|
||||
int (*handle_key)(PANEL*, int key);
|
||||
//! Show help window for this panel (if any)
|
||||
int (*help)(PANEL *);
|
||||
//! Destroy current panel
|
||||
void (*destroy)(PANEL *);
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
* Enum for available color pairs
|
||||
|
@ -106,6 +102,63 @@ struct ui_config
|
|||
*/
|
||||
int init_interface(const struct ui_config);
|
||||
|
||||
/**
|
||||
* @brief Create a panel structure
|
||||
*/
|
||||
ui_t *ui_create(int type);
|
||||
|
||||
/**
|
||||
* @brief Destroy a panel structure
|
||||
*/
|
||||
void ui_destroy(ui_t *ui);
|
||||
|
||||
/**
|
||||
* @brief Get panel pointer from an ui element
|
||||
*
|
||||
* Basic getter to get the Ncurses PANEL pointer
|
||||
* from ui structure. Use this instead of accessing
|
||||
* directly to the pointer.
|
||||
*
|
||||
* @param ui UI structure
|
||||
* @return ncurses panel pointer of given UI
|
||||
*/
|
||||
PANEL *ui_get_panel(ui_t *ui);
|
||||
|
||||
|
||||
void ui_draw_panel(ui_t *ui);
|
||||
|
||||
/**
|
||||
* @brief Show help screen from current UI (if any)
|
||||
*
|
||||
* This function will display the help screen for given
|
||||
* ui if exits.
|
||||
* All help screens exits after any character input
|
||||
*
|
||||
* @param ui UI structure
|
||||
*/
|
||||
void ui_help(ui_t *ui);
|
||||
|
||||
/**
|
||||
* @brief Handle key inputs on given UI
|
||||
*
|
||||
* This function will pass the input key sequence
|
||||
* to the given UI. This will only happen if the key
|
||||
* sequence don't match any of the general keybindings
|
||||
*
|
||||
* @param ui UI structure
|
||||
* @param key keycode sequence of the pressed keys and mods
|
||||
*/
|
||||
void ui_handle_key(ui_t *ui, int key);
|
||||
|
||||
/**
|
||||
* @brief Find a ui from its pannel pointer
|
||||
*/
|
||||
ui_t *ui_find_by_panel(PANEL *panel);
|
||||
|
||||
/**
|
||||
* @brief Find a ui form its panel id
|
||||
*/
|
||||
ui_t *ui_find_by_type(int type);
|
||||
/**
|
||||
* @brief Toggle color mode on and off
|
||||
* @param on Pass 0 to turn all black&white
|
||||
|
@ -122,7 +175,6 @@ void toggle_color(int on);
|
|||
void wait_for_input(ui_t *ui);
|
||||
|
||||
|
||||
void ui_draw_panel(ui_t *ui);
|
||||
|
||||
/**
|
||||
* Draw a box around passed windows with two bars (top and bottom)
|
||||
|
@ -142,28 +194,5 @@ void title_foot_box(WINDOW *win);
|
|||
*/
|
||||
void refresh_call_ui(const char *callid);
|
||||
|
||||
/**
|
||||
* @brief Create a panel structure
|
||||
*/
|
||||
ui_t *ui_create(int type);
|
||||
|
||||
/**
|
||||
* @berif Destroy a panel structure
|
||||
*/
|
||||
void ui_destroy(ui_t *ui);
|
||||
|
||||
PANEL *ui_get_panel(ui_t *ui);
|
||||
void ui_help(ui_t *ui);
|
||||
void ui_handle_key(ui_t *ui, int key);
|
||||
|
||||
/**
|
||||
* @brief Find a ui from its pannel pointer
|
||||
*/
|
||||
ui_t *ui_find_by_panel(PANEL *panel);
|
||||
|
||||
/**
|
||||
* @brief Find a ui form its panel id
|
||||
*/
|
||||
ui_t *ui_find_by_type(int type);
|
||||
|
||||
#endif // __SNGREP_UI_MANAGER_H
|
||||
|
|
Loading…
Reference in New Issue