aboutsummaryrefslogtreecommitdiffstats
path: root/CommandScreen.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
committerDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
commit65357c8c46154de4e4eca14075bfe5523bb5fc14 (patch)
tree8f430ee5a0d5de377c4e7c94e47842a27c70d7e8 /CommandScreen.c
parentf80394a20254938142011855f2954b3f63fe5909 (diff)
downloaddebian_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 'CommandScreen.c')
-rw-r--r--CommandScreen.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/CommandScreen.c b/CommandScreen.c
new file mode 100644
index 0000000..d342829
--- /dev/null
+++ b/CommandScreen.c
@@ -0,0 +1,68 @@
+#include "config.h" // IWYU pragma: keep
+
+#include "CommandScreen.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "Macros.h"
+#include "Panel.h"
+#include "ProvideCurses.h"
+#include "XUtils.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 = xMalloc(COLS + 1);
+ int line_offset = 0, last_spc = -1, len;
+ for (; *p != '\0'; p++, line_offset++) {
+ 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);
+ }
+
+ free(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 - 3, " ");
+}
+
+void CommandScreen_delete(Object* this) {
+ free(InfoScreen_done((InfoScreen*)this));
+}

© 2014-2024 Faster IT GmbH | imprint | privacy policy