1 /* 2 * (C) 2006 Oleg V. Palij <o.palij@gmail.com> 3 * Released under the GNU GPL, see the COPYING file in the source distribution for its full text. 4 */ 5 6 #ifndef __NCUI_H 7 #define __NCUI_H 8 9 #include <string> 10 #include <vector> 11 #include <csignal> 12 13 #include "config.h" 14 15 #include "options.hpp" 16 #include "sqstat.hpp" 17 18 namespace sqtop { 19 20 struct formattedline_t { 21 // text representation of sconn or url 22 std::string str; 23 // position (height) 24 unsigned int y; 25 // how much lines takes str 26 unsigned int coef; 27 // original structure (for toggle_action/0) 28 SQUID_Connection sconn; 29 // url id (for toggle_action/0) 30 std::string id; 31 // is it empty line 32 bool new_line; 33 // line was selected 34 bool highlighted; 35 }; 36 37 class ncui { 38 public: 39 //ncui(); 40 ~ncui(); 41 ncui(Options* pgOpts); 42 43 void CursesInit(void); 44 void CursesFinish(void); 45 46 void Print(void); 47 void Loop(void); 48 void Tick(void); 49 50 void SetError(std::string); 51 void ClearError(); 52 53 void SetSpeeds(long av_speed, long curr_speed); 54 void SetActiveConnCount(int); 55 void SetStat(std::vector<SQUID_Connection>); 56 57 private: 58 int CompactLongLine(std::string &line); 59 60 std::string EdLine(int linenum, std::string prompt, std::string initial); 61 int min(const int a, const int b); 62 63 void ShowHelpHint(std::string text); 64 int helphint_time; 65 66 std::string helpmsg(void); 67 68 std::string b2s(bool); 69 70 std::string error; 71 72 unsigned int selected_index; 73 void ToggleAction(); 74 75 formattedline_t MakeResult(std::string str, int y, int coef, SQUID_Connection sconn, std::string id); 76 formattedline_t MakeNewLine(int y); 77 78 unsigned int page_size; 79 80 std::vector<std::string> collapsed; 81 std::vector<std::string> detailed; 82 83 std::string search_string; 84 85 std::string debug; 86 void AddWatch(std::string prefix, std::string value); 87 88 long av_speed; 89 long curr_speed; 90 int act_conn; 91 std::vector<SQUID_Connection> sqconns; 92 93 std::string helphintmsg; 94 time_t helptimer; 95 sig_atomic_t foad; 96 Options* pGlobalOpts; 97 98 pthread_mutex_t tick_mutex; 99 pthread_mutexattr_t mattr; 100 101 formattedline_t selected_t; 102 103 std::vector<formattedline_t> FormatConnections(std::vector<SQUID_Connection> conns, int offset); 104 static bool Filter(SQUID_Connection scon, Options* pOpts); 105 std::vector<SQUID_Connection> FilterConns(std::vector<SQUID_Connection> in); 106 int increment; 107 unsigned int y_coef; 108 unsigned int start; 109 110 Options* pOpts; 111 }; 112 113 } 114 #endif /* __NCUI_H */ 115 116 // vim: ai ts=3 sts=3 et sw=3 expandtab 117