Skip to content

Commit

Permalink
Add key to pause process list updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cgzones committed Oct 12, 2020
1 parent fc301b7 commit b47bc66
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 46 deletions.
29 changes: 19 additions & 10 deletions Action.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess)
Settings* settings = st->settings;

int y = panel->y;
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, false);
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, st, false);
scr->allowFocusChange = false;
ScreenManager_add(scr, list, x - 1);
ScreenManager_add(scr, panel, -1);
Expand Down Expand Up @@ -73,17 +73,17 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess)

// ----------------------------------------

static void Action_runSetup(Settings* settings, Header* header, ProcessList* pl) {
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, true);
CategoriesPanel* panelCategories = CategoriesPanel_new(scr, settings, header, pl);
static void Action_runSetup(State* st) {
ScreenManager* scr = ScreenManager_new(0, st->header->height, 0, -1, HORIZONTAL, st->header, st->settings, st, true);
CategoriesPanel* panelCategories = CategoriesPanel_new(scr, st->settings, st->header, st->pl);
ScreenManager_add(scr, (Panel*) panelCategories, 16);
CategoriesPanel_makeMetersPage(panelCategories);
Panel* panelFocus;
int ch;
ScreenManager_run(scr, &panelFocus, &ch);
ScreenManager_delete(scr);
if (settings->changed) {
Header_writeBackToSettings(header);
if (st->settings->changed) {
Header_writeBackToSettings(st->header);
}
}

Expand Down Expand Up @@ -168,6 +168,8 @@ static Htop_Reaction sortBy(State* st) {
reaction |= Action_setSortKey(st->settings, field->key);
}
Object_delete(sortPanel);
if (st->pauseProcessUpdate)
ProcessList_sort(st->pl);
return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
}

Expand Down Expand Up @@ -346,7 +348,7 @@ Htop_Reaction Action_follow(State* st) {
}

static Htop_Reaction actionSetup(State* st) {
Action_runSetup(st->settings, st->header, st->pl);
Action_runSetup(st);
// TODO: shouldn't need this, colors should be dynamic
int headerHeight = Header_calculateHeight(st->header);
Panel_move(st->panel, 0, headerHeight);
Expand Down Expand Up @@ -392,13 +394,19 @@ static Htop_Reaction actionRedraw(ATTR_UNUSED State *st) {
return HTOP_REFRESH | HTOP_REDRAW_BAR;
}

static Htop_Reaction actionTogglePauseProcessUpdate(State *st) {
st->pauseProcessUpdate = !st->pauseProcessUpdate;
return HTOP_REFRESH | HTOP_REDRAW_BAR;
}

static const struct { const char* key; const char* info; } helpLeft[] = {
{ .key = " Arrows: ", .info = "scroll process list" },
{ .key = " Digits: ", .info = "incremental PID search" },
{ .key = " F3 /: ", .info = "incremental name search" },
{ .key = " F4 \\: ",.info = "incremental name filtering" },
{ .key = " F5 t: ", .info = "tree view" },
{ .key = " p: ", .info = "toggle program path" },
{ .key = " Z: ", .info = "pause/resume process updates" },
{ .key = " u: ", .info = "show processes of a single user" },
{ .key = " H: ", .info = "hide/show user process threads" },
{ .key = " K: ", .info = "hide/show kernel threads" },
Expand Down Expand Up @@ -491,12 +499,12 @@ static Htop_Reaction actionHelp(State* st) {
for (int i = 0; helpLeft[i].key; i++) { mvaddstr(9+i, 0, helpLeft[i].key); }
for (int i = 0; helpRight[i].key; i++) { mvaddstr(9+i, 40, helpRight[i].key); }
attrset(CRT_colors[PROCESS_THREAD]);
mvaddstr(16, 32, "threads");
mvaddstr(17, 26, "threads");
mvaddstr(17, 32, "threads");
mvaddstr(18, 26, "threads");
attrset(CRT_colors[DEFAULT_COLOR]);

attrset(CRT_colors[HELP_BOLD]);
mvaddstr(23,0, "Press any key to return.");
mvaddstr(24,0, "Press any key to return.");
attrset(CRT_colors[DEFAULT_COLOR]);
refresh();
CRT_readKey();
Expand Down Expand Up @@ -596,4 +604,5 @@ void Action_setBindings(Htop_Action* keys) {
keys['c'] = actionTagAllChildren;
keys['e'] = actionShowEnvScreen;
keys['w'] = actionShowCommandScreen;
keys['Z'] = actionTogglePauseProcessUpdate;
}
1 change: 1 addition & 0 deletions Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef struct State_ {
ProcessList* pl;
Panel* panel;
Header* header;
bool pauseProcessUpdate;
} State;

typedef Htop_Reaction (*Htop_Action)(State* st);
Expand Down
2 changes: 1 addition & 1 deletion AffinityPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static void AffinityPanel_update(AffinityPanel* this, bool keepSelected) {
Panel* super = (Panel*) this;

FunctionBar_setLabel(super->currentBar, KEY_F(3), this->topoView ? "Collapse/Expand" : "");
FunctionBar_draw(super->currentBar, NULL);
FunctionBar_draw(super->currentBar);

int oldSelected = Panel_getSelectedIndex(super);
Panel_prune(super);
Expand Down
2 changes: 1 addition & 1 deletion AvailableMetersPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, c
Panel_add(panel, (Object*) Meter_toListItem(meter, false));
Panel_setSelected(panel, Panel_size(panel) - 1);
MetersPanel_setMoving((MetersPanel*)panel, true);
FunctionBar_draw(panel->currentBar, NULL);
FunctionBar_draw(panel->currentBar);
}

static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {
Expand Down
8 changes: 7 additions & 1 deletion CRT.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow),
[PANEL_SELECTION_UNFOCUS] = ColorPair(Black,White),
[FAILED_SEARCH] = ColorPair(Red,Cyan),
[PAUSED] = A_BOLD | ColorPair(Yellow,Cyan),
[UPTIME] = A_BOLD | ColorPair(Cyan,Black),
[BATTERY] = A_BOLD | ColorPair(Cyan,Black),
[LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black),
Expand Down Expand Up @@ -162,6 +163,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PANEL_SELECTION_FOLLOW] = A_REVERSE,
[PANEL_SELECTION_UNFOCUS] = A_BOLD,
[FAILED_SEARCH] = A_REVERSE | A_BOLD,
[PAUSED] = A_BOLD | A_REVERSE,
[UPTIME] = A_BOLD,
[BATTERY] = A_BOLD,
[LARGE_NUMBER] = A_BOLD,
Expand Down Expand Up @@ -237,6 +239,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow),
[PANEL_SELECTION_UNFOCUS] = ColorPair(Blue,White),
[FAILED_SEARCH] = ColorPair(Red,Cyan),
[PAUSED] = A_BOLD | ColorPair(Yellow,Cyan),
[UPTIME] = ColorPair(Yellow,White),
[BATTERY] = ColorPair(Yellow,White),
[LARGE_NUMBER] = ColorPair(Red,White),
Expand Down Expand Up @@ -312,6 +315,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow),
[PANEL_SELECTION_UNFOCUS] = ColorPair(Blue,Black),
[FAILED_SEARCH] = ColorPair(Red,Cyan),
[PAUSED] = A_BOLD | ColorPair(Yellow,Cyan),
[UPTIME] = ColorPair(Yellow,Black),
[BATTERY] = ColorPair(Yellow,Black),
[LARGE_NUMBER] = ColorPair(Red,Black),
Expand Down Expand Up @@ -387,6 +391,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow),
[PANEL_SELECTION_UNFOCUS] = A_BOLD | ColorPair(Yellow,Blue),
[FAILED_SEARCH] = ColorPair(Red,Cyan),
[PAUSED] = A_BOLD | ColorPair(Yellow,Cyan),
[UPTIME] = A_BOLD | ColorPair(Yellow,Blue),
[BATTERY] = A_BOLD | ColorPair(Yellow,Blue),
[LARGE_NUMBER] = A_BOLD | ColorPair(Red,Blue),
Expand Down Expand Up @@ -461,7 +466,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PANEL_SELECTION_FOCUS] = ColorPair(Black,Cyan),
[PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow),
[PANEL_SELECTION_UNFOCUS] = ColorPair(Black,White),
[FAILED_SEARCH] = ColorPair(Red,Cyan),
[FAILED_SEARCH] = ColorPair(Red,Green),
[PAUSED] = A_BOLD | ColorPair(Yellow,Green),
[UPTIME] = ColorPair(Green,Black),
[BATTERY] = ColorPair(Green,Black),
[LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black),
Expand Down
1 change: 1 addition & 0 deletions CRT.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef enum ColorElements_ {
FUNCTION_BAR,
FUNCTION_KEY,
FAILED_SEARCH,
PAUSED,
PANEL_HEADER_FOCUS,
PANEL_HEADER_UNFOCUS,
PANEL_SELECTION_FOCUS,
Expand Down
2 changes: 1 addition & 1 deletion ColorsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) {
clear();
Panel* menu = (Panel*) Vector_get(this->scr->panels, 0);
Header_draw(header);
FunctionBar_draw(super->currentBar, NULL);
FunctionBar_draw(super->currentBar);
RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]);
RichString_setAttr(&(menu->header), CRT_colors[PANEL_HEADER_UNFOCUS]);
ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
Expand Down
35 changes: 29 additions & 6 deletions FunctionBar.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ static int FunctionBar_FEvents[] = {KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_
static const char* const FunctionBar_EnterEscKeys[] = {"Enter", "Esc", NULL};
static const int FunctionBar_EnterEscEvents[] = {13, 27};

static int currentLen = 0;

FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) {
const char* functions[] = {enter, esc, NULL};
return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents);
Expand Down Expand Up @@ -53,7 +55,7 @@ FunctionBar* FunctionBar_new(const char* const* functions, const char* const* ke
this->staticData = true;
this->keys.constKeys = FunctionBar_FKeys;
this->events = FunctionBar_FEvents;
this->size = 10;
this->size = ARRAYSIZE(FunctionBar_FEvents);
}
return this;
}
Expand Down Expand Up @@ -83,11 +85,11 @@ void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) {
}
}

void FunctionBar_draw(const FunctionBar* this, char* buffer) {
FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]);
void FunctionBar_draw(const FunctionBar* this) {
FunctionBar_drawExtra(this, NULL, -1, false);
}

void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) {
void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr, bool setCursor) {
attrset(CRT_colors[FUNCTION_BAR]);
mvhline(LINES-1, 0, ' ', COLS);
int x = 0;
Expand All @@ -99,15 +101,36 @@ void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) {
mvaddstr(LINES-1, x, this->functions[i]);
x += strlen(this->functions[i]);
}

if (buffer) {
attrset(attr);
if (attr == -1)
attrset(CRT_colors[FUNCTION_BAR]);
else
attrset(attr);
mvaddstr(LINES-1, x, buffer);
CRT_cursorX = x + strlen(buffer);
attrset(CRT_colors[RESET_COLOR]);
x += strlen(buffer);
}

if (setCursor) {
CRT_cursorX = x;
curs_set(1);
} else {
curs_set(0);
}

currentLen = x;
}

void FunctionBar_append(const char* buffer, int attr) {
if (attr == -1)
attrset(CRT_colors[FUNCTION_BAR]);
else
attrset(attr);
mvaddstr(LINES-1, currentLen, buffer);
attrset(CRT_colors[RESET_COLOR]);

currentLen += strlen(buffer);
}

int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) {
Expand Down
6 changes: 4 additions & 2 deletions FunctionBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ void FunctionBar_delete(FunctionBar* this);

void FunctionBar_setLabel(FunctionBar* this, int event, const char* text);

void FunctionBar_draw(const FunctionBar* this, char* buffer);
void FunctionBar_draw(const FunctionBar* this);

void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr);
void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr, bool setCursor);

void FunctionBar_append(const char* buffer, int attr);

int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos);

Expand Down
19 changes: 10 additions & 9 deletions IncSet.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelVa
break;
}
}
if (found)
FunctionBar_draw(mode->bar, mode->buffer);
else
FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]);

FunctionBar_drawExtra(mode->bar,
mode->buffer,
found ? -1 : CRT_colors[FAILED_SEARCH],
true);
return found;
}

Expand Down Expand Up @@ -177,7 +178,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
}
this->active = NULL;
Panel_setDefaultBar(panel);
FunctionBar_draw(this->defaultBar, NULL);
FunctionBar_draw(this->defaultBar);
doSearch = false;
}
if (doSearch) {
Expand All @@ -198,15 +199,15 @@ const char* IncSet_getListItemValue(Panel* panel, int i) {

void IncSet_activate(IncSet* this, IncType type, Panel* panel) {
this->active = &(this->modes[type]);
FunctionBar_draw(this->active->bar, this->active->buffer);
FunctionBar_drawExtra(this->active->bar, this->active->buffer, -1, true);
panel->currentBar = this->active->bar;
}

void IncSet_drawBar(IncSet* this) {
void IncSet_drawBar(const IncSet* this) {
if (this->active) {
FunctionBar_draw(this->active->bar, this->active->buffer);
FunctionBar_drawExtra(this->active->bar, this->active->buffer, -1, true);
} else {
FunctionBar_draw(this->defaultBar, NULL);
FunctionBar_draw(this->defaultBar);
}
}

Expand Down
2 changes: 1 addition & 1 deletion IncSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const char* IncSet_getListItemValue(Panel* panel, int i);

void IncSet_activate(IncSet* this, IncType type, Panel* panel);

void IncSet_drawBar(IncSet* this);
void IncSet_drawBar(const IncSet* this);

int IncSet_synthesizeEvent(IncSet* this, int x);

Expand Down
2 changes: 2 additions & 0 deletions MainPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
if (reaction & HTOP_REDRAW_BAR) {
MainPanel_updateTreeFunctions(this, this->state->settings->treeView);
IncSet_drawBar(this->inc);
if (this->state->pauseProcessUpdate)
FunctionBar_append("PAUSED", CRT_colors[PAUSED]);
}
if (reaction & HTOP_UPDATE_PANELHDR) {
ProcessList_printHeader(this->state->pl, Panel_getHeader(super));
Expand Down
2 changes: 1 addition & 1 deletion MetersPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void MetersPanel_setMoving(MetersPanel* this, bool moving) {
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOLLOW]);
super->currentBar = Meters_movingBar;
}
FunctionBar_draw(this->super.currentBar, NULL);
FunctionBar_draw(this->super.currentBar);
}

static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) {
Expand Down
Loading

0 comments on commit b47bc66

Please sign in to comment.