This commit is contained in:
Hisham Muhammad 2017-07-26 16:16:10 -03:00
commit 3975e9ce5c
17 changed files with 46 additions and 39 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ htop
# skip all backups # skip all backups
*.bak *.bak
*~ *~
.*.sw?
# skip coverage files # skip coverage files
*.gcda *.gcda

View File

@ -381,7 +381,7 @@ static Htop_Reaction actionRedraw() {
return HTOP_REFRESH | HTOP_REDRAW_BAR; return HTOP_REFRESH | HTOP_REDRAW_BAR;
} }
static struct { const char* key; const char* info; } helpLeft[] = { static const struct { const char* key; const char* info; } helpLeft[] = {
{ .key = " Arrows: ", .info = "scroll process list" }, { .key = " Arrows: ", .info = "scroll process list" },
{ .key = " Digits: ", .info = "incremental PID search" }, { .key = " Digits: ", .info = "incremental PID search" },
{ .key = " F3 /: ", .info = "incremental name search" }, { .key = " F3 /: ", .info = "incremental name search" },
@ -399,7 +399,7 @@ static struct { const char* key; const char* info; } helpLeft[] = {
{ .key = NULL, .info = NULL } { .key = NULL, .info = NULL }
}; };
static struct { const char* key; const char* info; } helpRight[] = { static const struct { const char* key; const char* info; } helpRight[] = {
{ .key = " Space: ", .info = "tag process" }, { .key = " Space: ", .info = "tag process" },
{ .key = " c: ", .info = "tag process and its children" }, { .key = " c: ", .info = "tag process and its children" },
{ .key = " U: ", .info = "untag all processes" }, { .key = " U: ", .info = "untag all processes" },

View File

@ -26,7 +26,7 @@ typedef struct AvailableColumnsPanel_ {
}*/ }*/
static const char* AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL}; static const char* const AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL};
static void AvailableColumnsPanel_delete(Object* object) { static void AvailableColumnsPanel_delete(Object* object) {
Panel* super = (Panel*) object; Panel* super = (Panel*) object;

View File

@ -34,7 +34,7 @@ typedef struct CategoriesPanel_ {
}*/ }*/
static const char* CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; static const char* const CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
static void CategoriesPanel_delete(Object* object) { static void CategoriesPanel_delete(Object* object) {
Panel* super = (Panel*) object; Panel* super = (Panel*) object;

View File

@ -34,9 +34,9 @@ typedef struct ColorsPanel_ {
}*/ }*/
static const char* ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; static const char* const ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
static const char* ColorSchemeNames[] = { static const char* const ColorSchemeNames[] = {
"Default", "Default",
"Monochromatic", "Monochromatic",
"Black on White", "Black on White",

View File

@ -29,7 +29,7 @@ typedef struct ColumnsPanel_ {
}*/ }*/
static const char* ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL}; static const char* const ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
static void ColumnsPanel_delete(Object* object) { static void ColumnsPanel_delete(Object* object) {
Panel* super = (Panel*) object; Panel* super = (Panel*) object;

View File

@ -28,7 +28,7 @@ typedef struct DisplayOptionsPanel_ {
}*/ }*/
static const char* DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
static void DisplayOptionsPanel_delete(Object* object) { static void DisplayOptionsPanel_delete(Object* object) {
Panel* super = (Panel*) object; Panel* super = (Panel*) object;

View File

@ -28,21 +28,21 @@ typedef struct FunctionBar_ {
}*/ }*/
static const char* FunctionBar_FKeys[] = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", NULL}; static const char* const FunctionBar_FKeys[] = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", NULL};
static const char* FunctionBar_FLabels[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", NULL}; static const char* const FunctionBar_FLabels[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", NULL};
static int FunctionBar_FEvents[] = {KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5), KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10)}; static int FunctionBar_FEvents[] = {KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5), KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10)};
static const char* FunctionBar_EnterEscKeys[] = {"Enter", "Esc", NULL}; static const char* const FunctionBar_EnterEscKeys[] = {"Enter", "Esc", NULL};
static int FunctionBar_EnterEscEvents[] = {13, 27}; static const int FunctionBar_EnterEscEvents[] = {13, 27};
FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) { FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) {
const char* functions[] = {enter, esc, NULL}; const char* functions[] = {enter, esc, NULL};
return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents); return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents);
} }
FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* events) { FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events) {
FunctionBar* this = xCalloc(1, sizeof(FunctionBar)); FunctionBar* this = xCalloc(1, sizeof(FunctionBar));
this->functions = xCalloc(16, sizeof(char*)); this->functions = xCalloc(16, sizeof(char*));
if (!functions) { if (!functions) {

View File

@ -24,7 +24,7 @@ typedef struct FunctionBar_ {
FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc); FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc);
FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* events); FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events);
void FunctionBar_delete(FunctionBar* this); void FunctionBar_delete(FunctionBar* this);

View File

@ -52,8 +52,8 @@ static void IncMode_reset(IncMode* mode) {
mode->buffer[0] = 0; mode->buffer[0] = 0;
} }
static const char* searchFunctions[] = {"Next ", "Cancel ", " Search: ", NULL}; static const char* const searchFunctions[] = {"Next ", "Cancel ", " Search: ", NULL};
static const char* searchKeys[] = {"F3", "Esc", " "}; static const char* const searchKeys[] = {"F3", "Esc", " "};
static int searchEvents[] = {KEY_F(3), 27, ERR}; static int searchEvents[] = {KEY_F(3), 27, ERR};
static inline void IncMode_initSearch(IncMode* search) { static inline void IncMode_initSearch(IncMode* search) {
@ -62,8 +62,8 @@ static inline void IncMode_initSearch(IncMode* search) {
search->isFilter = false; search->isFilter = false;
} }
static const char* filterFunctions[] = {"Done ", "Clear ", " Filter: ", NULL}; static const char* const filterFunctions[] = {"Done ", "Clear ", " Filter: ", NULL};
static const char* filterKeys[] = {"Enter", "Esc", " "}; static const char* const filterKeys[] = {"Enter", "Esc", " "};
static int filterEvents[] = {13, 27, ERR}; static int filterEvents[] = {13, 27, ERR};
static inline void IncMode_initFilter(IncMode* filter) { static inline void IncMode_initFilter(IncMode* filter) {

View File

@ -50,9 +50,9 @@ struct InfoScreen_ {
}; };
}*/ }*/
static const char* InfoScreenFunctions[] = {"Search ", "Filter ", "Refresh", "Done ", NULL}; static const char* const InfoScreenFunctions[] = {"Search ", "Filter ", "Refresh", "Done ", NULL};
static const char* InfoScreenKeys[] = {"F3", "F4", "F5", "Esc"}; static const char* const InfoScreenKeys[] = {"F3", "F4", "F5", "Esc"};
static int InfoScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27}; static int InfoScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27};

View File

@ -31,7 +31,7 @@ typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
}*/ }*/
static const char* MainFunctions[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL}; static const char* const MainFunctions[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL};
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) { void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) {
FunctionBar* bar = MainPanel_getFunctionBar(this); FunctionBar* bar = MainPanel_getFunctionBar(this);

16
Meter.c
View File

@ -336,7 +336,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
#ifdef HAVE_LIBNCURSESW #ifdef HAVE_LIBNCURSESW
#define PIXPERROW_UTF8 4 #define PIXPERROW_UTF8 4
static const char* GraphMeterMode_dotsUtf8[] = { static const char* const GraphMeterMode_dotsUtf8[] = {
/*00*/" ", /*01*/"", /*02*/"", /*03*/"", /*04*/ "", /*00*/" ", /*01*/"", /*02*/"", /*03*/"", /*04*/ "",
/*10*/"", /*11*/"", /*12*/"", /*13*/"", /*14*/ "", /*10*/"", /*11*/"", /*12*/"", /*13*/"", /*14*/ "",
/*20*/"", /*21*/"", /*22*/"", /*23*/"", /*24*/ "", /*20*/"", /*21*/"", /*22*/"", /*23*/"", /*24*/ "",
@ -347,13 +347,13 @@ static const char* GraphMeterMode_dotsUtf8[] = {
#endif #endif
#define PIXPERROW_ASCII 2 #define PIXPERROW_ASCII 2
static const char* GraphMeterMode_dotsAscii[] = { static const char* const GraphMeterMode_dotsAscii[] = {
/*00*/" ", /*01*/".", /*02*/":", /*00*/" ", /*01*/".", /*02*/":",
/*10*/".", /*11*/".", /*12*/":", /*10*/".", /*11*/".", /*12*/":",
/*20*/":", /*21*/":", /*22*/":" /*20*/":", /*21*/":", /*22*/":"
}; };
static const char** GraphMeterMode_dots; static const char* const* GraphMeterMode_dots;
static int GraphMeterMode_pixPerRow; static int GraphMeterMode_pixPerRow;
static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
@ -406,8 +406,8 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
} }
for (; i < nValues; i+=2, k++) { for (; i < nValues; i+=2, k++) {
int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT; int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT;
int v1 = CLAMP(data->values[i] * pix, 1, pix); int v1 = CLAMP((int) lround(data->values[i] * pix), 1, pix);
int v2 = CLAMP(data->values[i+1] * pix, 1, pix); int v2 = CLAMP((int) lround(data->values[i+1] * pix), 1, pix);
int colorIdx = GRAPH_1; int colorIdx = GRAPH_1;
for (int line = 0; line < GRAPH_HEIGHT; line++) { for (int line = 0; line < GRAPH_HEIGHT; line++) {
@ -424,7 +424,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
/* ---------- LEDMeterMode ---------- */ /* ---------- LEDMeterMode ---------- */
static const char* LEDMeterMode_digitsAscii[] = { static const char* const LEDMeterMode_digitsAscii[] = {
" __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ ", " __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ ",
"| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|", "| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|",
"|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|" "|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|"
@ -432,7 +432,7 @@ static const char* LEDMeterMode_digitsAscii[] = {
#ifdef HAVE_LIBNCURSESW #ifdef HAVE_LIBNCURSESW
static const char* LEDMeterMode_digitsUtf8[] = { static const char* const LEDMeterMode_digitsUtf8[] = {
"┌──┐","","╶──┐","╶──┐","╷ ╷","┌──╴","┌──╴","╶──┐","┌──┐","┌──┐", "┌──┐","","╶──┐","╶──┐","╷ ╷","┌──╴","┌──╴","╶──┐","┌──┐","┌──┐",
"│ │","","┌──┘"," ──┤","└──┤","└──┐","├──┐","","├──┤","└──┤", "│ │","","┌──┘"," ──┤","└──┤","└──┐","├──┐","","├──┤","└──┤",
"└──┘","","└──╴","╶──┘","","╶──┘","└──┘","","└──┘"," ──┘" "└──┘","","└──╴","╶──┘","","╶──┘","└──┘","","└──┘"," ──┘"
@ -440,7 +440,7 @@ static const char* LEDMeterMode_digitsUtf8[] = {
#endif #endif
static const char** LEDMeterMode_digits; static const char* const* LEDMeterMode_digits;
static void LEDMeterMode_drawDigit(int x, int y, int n) { static void LEDMeterMode_drawDigit(int x, int y, int n) {
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)

View File

@ -33,16 +33,16 @@ struct MetersPanel_ {
// Note: In code the meters are known to have bar/text/graph "Modes", but in UI // Note: In code the meters are known to have bar/text/graph "Modes", but in UI
// we call them "Styles". // we call them "Styles".
static const char* MetersFunctions[] = {"Style ", "Move ", " ", "Delete", "Done ", NULL}; static const char* const MetersFunctions[] = {"Style ", "Move ", " ", "Delete", "Done ", NULL};
static const char* MetersKeys[] = {"Space", "Enter", " ", "Del", "F10"}; static const char* const MetersKeys[] = {"Space", "Enter", " ", "Del", "F10"};
static int MetersEvents[] = {' ', 13, ERR, KEY_DC, KEY_F(10)}; static int MetersEvents[] = {' ', 13, ERR, KEY_DC, KEY_F(10)};
// We avoid UTF-8 arrows ← → here as they might display full-width on Chinese // We avoid UTF-8 arrows ← → here as they might display full-width on Chinese
// terminals, breaking our aligning. // terminals, breaking our aligning.
// In <http://unicode.org/reports/tr11/>, arrows (U+2019..U+2199) are // In <http://unicode.org/reports/tr11/>, arrows (U+2019..U+2199) are
// considered "Ambiguous characters". // considered "Ambiguous characters".
static const char* MetersMovingFunctions[] = {"Style ", "Lock ", "Up ", "Down ", "Left ", "Right ", " ", "Delete", "Done ", NULL}; static const char* const MetersMovingFunctions[] = {"Style ", "Lock ", "Up ", "Down ", "Left ", "Right ", " ", "Delete", "Done ", NULL};
static const char* MetersMovingKeys[] = {"Space", "Enter", "Up", "Dn", "<-", "->", " ", "Del", "F10"}; static const char* const MetersMovingKeys[] = {"Space", "Enter", "Up", "Dn", "<-", "->", " ", "Del", "F10"};
static int MetersMovingEvents[] = {' ', 13, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, ERR, KEY_DC, KEY_F(10)}; static int MetersMovingEvents[] = {' ', 13, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, ERR, KEY_DC, KEY_F(10)};
static FunctionBar* Meters_movingBar = NULL; static FunctionBar* Meters_movingBar = NULL;

View File

@ -254,23 +254,29 @@ static bool Settings_read(Settings* this, const char* fileName) {
static void writeFields(FILE* fd, ProcessField* fields, const char* name) { static void writeFields(FILE* fd, ProcessField* fields, const char* name) {
fprintf(fd, "%s=", name); fprintf(fd, "%s=", name);
const char* sep = "";
for (int i = 0; fields[i]; i++) { for (int i = 0; fields[i]; i++) {
// This "-1" is for compatibility with the older enum format. // This "-1" is for compatibility with the older enum format.
fprintf(fd, "%d ", (int) fields[i]-1); fprintf(fd, "%s%d", sep, (int) fields[i]-1);
sep = " ";
} }
fprintf(fd, "\n"); fprintf(fd, "\n");
} }
static void writeMeters(Settings* this, FILE* fd, int column) { static void writeMeters(Settings* this, FILE* fd, int column) {
const char* sep = "";
for (int i = 0; i < this->columns[column].len; i++) { for (int i = 0; i < this->columns[column].len; i++) {
fprintf(fd, "%s ", this->columns[column].names[i]); fprintf(fd, "%s%s", sep, this->columns[column].names[i]);
sep = " ";
} }
fprintf(fd, "\n"); fprintf(fd, "\n");
} }
static void writeMeterModes(Settings* this, FILE* fd, int column) { static void writeMeterModes(Settings* this, FILE* fd, int column) {
const char* sep = "";
for (int i = 0; i < this->columns[column].len; i++) { for (int i = 0; i < this->columns[column].len; i++) {
fprintf(fd, "%d ", this->columns[column].modes[i]); fprintf(fd, "%s%d", sep, this->columns[column].modes[i]);
sep = " ";
} }
fprintf(fd, "\n"); fprintf(fd, "\n");
} }

View File

@ -43,9 +43,9 @@ typedef struct TraceScreen_ {
}*/ }*/
static const char* TraceScreenFunctions[] = {"Search ", "Filter ", "AutoScroll ", "Stop Tracing ", "Done ", NULL}; static const char* const TraceScreenFunctions[] = {"Search ", "Filter ", "AutoScroll ", "Stop Tracing ", "Done ", NULL};
static const char* TraceScreenKeys[] = {"F3", "F4", "F8", "F9", "Esc"}; static const char* const TraceScreenKeys[] = {"F3", "F4", "F8", "F9", "Esc"};
static int TraceScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27}; static int TraceScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27};

View File

@ -19,7 +19,7 @@ Panel* IOPriorityPanel_new(IOPriority currPrio) {
Panel_setHeader(this, "IO Priority:"); Panel_setHeader(this, "IO Priority:");
Panel_add(this, (Object*) ListItem_new("None (based on nice)", IOPriority_None)); Panel_add(this, (Object*) ListItem_new("None (based on nice)", IOPriority_None));
if (currPrio == IOPriority_None) Panel_setSelected(this, 0); if (currPrio == IOPriority_None) Panel_setSelected(this, 0);
struct { int klass; const char* name; } classes[] = { static const struct { int klass; const char* name; } classes[] = {
{ .klass = IOPRIO_CLASS_RT, .name = "Realtime" }, { .klass = IOPRIO_CLASS_RT, .name = "Realtime" },
{ .klass = IOPRIO_CLASS_BE, .name = "Best-effort" }, { .klass = IOPRIO_CLASS_BE, .name = "Best-effort" },
{ .klass = 0, .name = NULL } { .klass = 0, .name = NULL }