diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:00:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:00:29 +0000 |
commit | 52e25213825024b8bb446eb26b03bedc9d5c2103 (patch) | |
tree | da70bf44b2423f6f8e9a070c063fed79d190b489 /CommandScreen.c | |
parent | Initial commit. (diff) | |
download | htop-52e25213825024b8bb446eb26b03bedc9d5c2103.tar.xz htop-52e25213825024b8bb446eb26b03bedc9d5c2103.zip |
Adding upstream version 3.2.2.upstream/3.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'CommandScreen.c')
-rw-r--r-- | CommandScreen.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/CommandScreen.c b/CommandScreen.c new file mode 100644 index 0000000..6a87d13 --- /dev/null +++ b/CommandScreen.c @@ -0,0 +1,68 @@ +#include "config.h" // IWYU pragma: keep + +#include "CommandScreen.h" + +#include <assert.h> +#include <stdlib.h> +#include <string.h> + +#include "Macros.h" +#include "Panel.h" +#include "ProvideCurses.h" + + +static void CommandScreen_scan(InfoScreen* this) { + Panel* panel = this->display; + int idx = MAXIMUM(Panel_getSelectedIndex(panel), 0); + Panel_prune(panel); + + const char* p = Process_getCommand(this->process); + char line[COLS + 1]; + int line_offset = 0, last_spc = -1, len; + for (; *p != '\0'; p++, line_offset++) { + assert(line_offset >= 0 && (size_t)line_offset < sizeof(line)); + line[line_offset] = *p; + if (*p == ' ') { + last_spc = line_offset; + } + + if (line_offset == COLS) { + len = (last_spc == -1) ? line_offset : last_spc; + line[len] = '\0'; + InfoScreen_addLine(this, line); + + line_offset -= len; + last_spc = -1; + memcpy(line, p - line_offset, line_offset + 1); + } + } + + if (line_offset > 0) { + line[line_offset] = '\0'; + InfoScreen_addLine(this, line); + } + + Panel_setSelected(panel, idx); +} + +static void CommandScreen_draw(InfoScreen* this) { + InfoScreen_drawTitled(this, "Command of process %d - %s", this->process->pid, Process_getCommand(this->process)); +} + +const InfoScreenClass CommandScreen_class = { + .super = { + .extends = Class(Object), + .delete = CommandScreen_delete + }, + .scan = CommandScreen_scan, + .draw = CommandScreen_draw +}; + +CommandScreen* CommandScreen_new(Process* process) { + CommandScreen* this = AllocThis(CommandScreen); + return (CommandScreen*) InfoScreen_init(&this->super, process, NULL, LINES - 2, " "); +} + +void CommandScreen_delete(Object* this) { + free(InfoScreen_done((InfoScreen*)this)); +} |