diff options
author | Daniel Lange <DLange@git.local> | 2020-12-07 10:26:01 +0100 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2020-12-07 10:26:01 +0100 |
commit | 65357c8c46154de4e4eca14075bfe5523bb5fc14 (patch) | |
tree | 8f430ee5a0d5de377c4e7c94e47842a27c70d7e8 /InfoScreen.c | |
parent | f80394a20254938142011855f2954b3f63fe5909 (diff) | |
download | debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.gz debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.bz2 debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.zip |
New upstream version 3.0.3upstream/3.0.3
Diffstat (limited to 'InfoScreen.c')
-rw-r--r-- | InfoScreen.c | 65 |
1 files changed, 41 insertions, 24 deletions
diff --git a/InfoScreen.c b/InfoScreen.c index 8a6a3be..ceb29f7 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -1,17 +1,18 @@ +#include "config.h" // IWYU pragma: keep + #include "InfoScreen.h" -#include "config.h" -#include "Object.h" +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + #include "CRT.h" #include "IncSet.h" #include "ListItem.h" -#include "Platform.h" -#include "StringUtils.h" - -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <stdarg.h> +#include "Object.h" +#include "ProvideCurses.h" +#include "XUtils.h" static const char* const InfoScreenFunctions[] = {"Search ", "Filter ", "Refresh", "Done ", NULL}; @@ -20,7 +21,7 @@ static const char* const InfoScreenKeys[] = {"F3", "F4", "F5", "Esc"}; static int InfoScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27}; -InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, const char* panelHeader) { +InfoScreen* InfoScreen_init(InfoScreen* this, const Process* process, FunctionBar* bar, int height, const char* panelHeader) { this->process = process; if (!bar) { bar = FunctionBar_new(InfoScreenFunctions, InfoScreenKeys, InfoScreenEvents); @@ -42,45 +43,56 @@ InfoScreen* InfoScreen_done(InfoScreen* this) { void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...) { va_list ap; va_start(ap, fmt); + + char* title = xMalloc(COLS + 1); + int len = vsnprintf(title, COLS + 1, fmt, ap); + if (len > COLS) { + memset(&title[COLS - 3], '.', 3); + } + attrset(CRT_colors[METER_TEXT]); mvhline(0, 0, ' ', COLS); - (void) wmove(stdscr, 0, 0); - vw_printw(stdscr, fmt, ap); + mvwprintw(stdscr, 0, 0, title); attrset(CRT_colors[DEFAULT_COLOR]); this->display->needsRedraw = true; - Panel_draw(this->display, true); + Panel_draw(this->display, true, true); IncSet_drawBar(this->inc); + free(title); va_end(ap); } void InfoScreen_addLine(InfoScreen* this, const char* line) { Vector_add(this->lines, (Object*) ListItem_new(line, 0)); const char* incFilter = IncSet_filter(this->inc); - if (!incFilter || String_contains_i(line, incFilter)) - Panel_add(this->display, (Object*)Vector_get(this->lines, Vector_size(this->lines)-1)); + if (!incFilter || String_contains_i(line, incFilter)) { + Panel_add(this->display, Vector_get(this->lines, Vector_size(this->lines) - 1)); + } } void InfoScreen_appendLine(InfoScreen* this, const char* line) { - ListItem* last = (ListItem*)Vector_get(this->lines, Vector_size(this->lines)-1); + ListItem* last = (ListItem*)Vector_get(this->lines, Vector_size(this->lines) - 1); ListItem_append(last, line); const char* incFilter = IncSet_filter(this->inc); - if (incFilter && Panel_get(this->display, Panel_size(this->display)-1) != (Object*)last && String_contains_i(line, incFilter)) + if (incFilter && Panel_get(this->display, Panel_size(this->display) - 1) != (Object*)last && String_contains_i(line, incFilter)) { Panel_add(this->display, (Object*)last); + } } void InfoScreen_run(InfoScreen* this) { Panel* panel = this->display; - if (As_InfoScreen(this)->scan) InfoScreen_scan(this); + if (As_InfoScreen(this)->scan) + InfoScreen_scan(this); + InfoScreen_draw(this); bool looping = true; while (looping) { - Panel_draw(panel, true); + Panel_draw(panel, true, true); if (this->inc->active) { - (void) move(LINES-1, CRT_cursorX); + (void) move(LINES - 1, CRT_cursorX); } set_escdelay(25); int ch = getch(); @@ -102,7 +114,7 @@ void InfoScreen_run(InfoScreen* this) { } else if (mevent.y == LINES - 1) { ch = IncSet_synthesizeEvent(this->inc, mevent.x); } - } + } } if (this->inc->active) { @@ -123,20 +135,25 @@ void InfoScreen_run(InfoScreen* this) { break; case KEY_F(5): clear(); - if (As_InfoScreen(this)->scan) InfoScreen_scan(this); + if (As_InfoScreen(this)->scan) + InfoScreen_scan(this); + InfoScreen_draw(this); break; case '\014': // Ctrl+L clear(); InfoScreen_draw(this); break; - case 'q': case 27: + case 'q': case KEY_F(10): looping = false; break; case KEY_RESIZE: - Panel_resize(panel, COLS, LINES-2); + Panel_resize(panel, COLS, LINES - 2); + if (As_InfoScreen(this)->scan) + InfoScreen_scan(this); + InfoScreen_draw(this); break; default: |