Hide process selection on ESC

Do not highlight the current process line after pressing ESC in the main
screen.
Restore after pressing any key.
This commit is contained in:
Christian Göttsche 2020-11-23 16:23:18 +01:00 committed by BenBE
parent ea4f33409a
commit 19b5141685
8 changed files with 13 additions and 7 deletions

View File

@ -341,7 +341,7 @@ static Htop_Reaction actionKill(State* st) {
if (sgn) { if (sgn) {
if (sgn->key != 0) { if (sgn->key != 0) {
Panel_setHeader(st->panel, "Sending..."); Panel_setHeader(st->panel, "Sending...");
Panel_draw(st->panel, true); Panel_draw(st->panel, true, true);
refresh(); refresh();
MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg) { .i = sgn->key }, NULL); MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg) { .i = sgn->key }, NULL);
napms(500); napms(500);

View File

@ -38,6 +38,7 @@ typedef struct State_ {
Panel* panel; Panel* panel;
Header* header; Header* header;
bool pauseProcessUpdate; bool pauseProcessUpdate;
bool hideProcessSelection;
} State; } State;
typedef Htop_Reaction (*Htop_Action)(State* st); typedef Htop_Reaction (*Htop_Action)(State* st);

View File

@ -55,7 +55,7 @@ void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...) {
mvwprintw(stdscr, 0, 0, title); mvwprintw(stdscr, 0, 0, title);
attrset(CRT_colors[DEFAULT_COLOR]); attrset(CRT_colors[DEFAULT_COLOR]);
this->display->needsRedraw = true; this->display->needsRedraw = true;
Panel_draw(this->display, true); Panel_draw(this->display, true, true);
IncSet_drawBar(this->inc); IncSet_drawBar(this->inc);
free(title); free(title);
va_end(ap); va_end(ap);
@ -89,7 +89,7 @@ void InfoScreen_run(InfoScreen* this) {
bool looping = true; bool looping = true;
while (looping) { while (looping) {
Panel_draw(panel, true); Panel_draw(panel, true, true);
if (this->inc->active) { if (this->inc->active) {
(void) move(LINES - 1, CRT_cursorX); (void) move(LINES - 1, CRT_cursorX);

View File

@ -57,6 +57,9 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
Htop_Reaction reaction = HTOP_OK; Htop_Reaction reaction = HTOP_OK;
if (ch != ERR)
this->state->hideProcessSelection = false;
if (EVENT_IS_HEADER_CLICK(ch)) { if (EVENT_IS_HEADER_CLICK(ch)) {
int x = EVENT_HEADER_CLICK_GET_X(ch); int x = EVENT_HEADER_CLICK_GET_X(ch);
const ProcessList* pl = this->state->pl; const ProcessList* pl = this->state->pl;
@ -83,6 +86,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
} }
result = HANDLED; result = HANDLED;
} else if (ch == 27) { } else if (ch == 27) {
this->state->hideProcessSelection = true;
return HANDLED; return HANDLED;
} else if (ch != ERR && ch > 0 && ch < KEY_MAX && this->keys[ch]) { } else if (ch != ERR && ch > 0 && ch < KEY_MAX && this->keys[ch]) {
reaction |= (this->keys[ch])(this->state); reaction |= (this->keys[ch])(this->state);

View File

@ -217,7 +217,7 @@ void Panel_splice(Panel* this, Vector* from) {
this->needsRedraw = true; this->needsRedraw = true;
} }
void Panel_draw(Panel* this, bool focus) { void Panel_draw(Panel* this, bool focus, bool highlightSelected) {
assert (this != NULL); assert (this != NULL);
int size = Vector_size(this->items); int size = Vector_size(this->items);
@ -273,7 +273,7 @@ void Panel_draw(Panel* this, bool focus) {
Object_display(itemObj, &item); Object_display(itemObj, &item);
int itemLen = RichString_sizeVal(item); int itemLen = RichString_sizeVal(item);
int amt = MINIMUM(itemLen - scrollH, this->w); int amt = MINIMUM(itemLen - scrollH, this->w);
if (i == this->selected) { if (highlightSelected && i == this->selected) {
item.highlightAttr = selectionColor; item.highlightAttr = selectionColor;
} }
if (item.highlightAttr) { if (item.highlightAttr) {

View File

@ -109,7 +109,7 @@ int Panel_size(Panel* this);
void Panel_setSelected(Panel* this, int selected); void Panel_setSelected(Panel* this, int selected);
void Panel_draw(Panel* this, bool focus); void Panel_draw(Panel* this, bool focus, bool highlightSelected);
void Panel_splice(Panel* this, Vector* from); void Panel_splice(Panel* this, Vector* from);

View File

@ -123,7 +123,7 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus) {
const int nPanels = this->panelCount; const int nPanels = this->panelCount;
for (int i = 0; i < nPanels; i++) { for (int i = 0; i < nPanels; i++) {
Panel* panel = (Panel*) Vector_get(this->panels, i); Panel* panel = (Panel*) Vector_get(this->panels, i);
Panel_draw(panel, i == focus); Panel_draw(panel, i == focus, !((panel == this->state->panel) && this->state->hideProcessSelection));
mvvline(panel->y, panel->x + panel->w, ' ', panel->h + 1); mvvline(panel->y, panel->x + panel->w, ' ', panel->h + 1);
} }
} }

1
htop.c
View File

@ -320,6 +320,7 @@ int main(int argc, char** argv) {
.panel = (Panel*) panel, .panel = (Panel*) panel,
.header = header, .header = header,
.pauseProcessUpdate = false, .pauseProcessUpdate = false,
.hideProcessSelection = false,
}; };
MainPanel_setState(panel, &state); MainPanel_setState(panel, &state);