2020-09-19 11:55:23 +00:00
|
|
|
#include "config.h" // IWYU pragma: keep
|
2017-08-03 09:43:28 +00:00
|
|
|
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "CommandScreen.h"
|
2017-08-03 09:43:28 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2020-09-19 11:55:23 +00:00
|
|
|
|
|
|
|
#include "Macros.h"
|
|
|
|
#include "Panel.h"
|
|
|
|
#include "ProvideCurses.h"
|
|
|
|
#include "XUtils.h"
|
2017-08-03 09:43:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void CommandScreen_scan(InfoScreen* this) {
|
|
|
|
Panel* panel = this->display;
|
|
|
|
int idx = MAXIMUM(Panel_getSelectedIndex(panel), 0);
|
|
|
|
Panel_prune(panel);
|
|
|
|
|
2020-10-17 10:54:45 +00:00
|
|
|
const char* p = Process_getCommand(this->process);
|
2020-12-19 22:05:07 +00:00
|
|
|
char line[COLS + 1];
|
2017-08-03 09:43:28 +00:00
|
|
|
int line_offset = 0, last_spc = -1, len;
|
|
|
|
for (; *p != '\0'; p++, line_offset++) {
|
2020-12-19 22:05:07 +00:00
|
|
|
assert(line_offset >= 0 && (size_t)line_offset < sizeof(line));
|
2020-09-25 21:22:24 +00:00
|
|
|
line[line_offset] = *p;
|
2020-11-01 00:09:51 +00:00
|
|
|
if (*p == ' ') {
|
|
|
|
last_spc = line_offset;
|
|
|
|
}
|
2017-08-03 09:43:28 +00:00
|
|
|
|
|
|
|
if (line_offset == COLS) {
|
|
|
|
len = (last_spc == -1) ? line_offset : last_spc;
|
2020-09-25 21:22:24 +00:00
|
|
|
line[len] = '\0';
|
|
|
|
InfoScreen_addLine(this, line);
|
|
|
|
|
2017-08-03 09:43:28 +00:00
|
|
|
line_offset -= len;
|
|
|
|
last_spc = -1;
|
2020-09-25 21:22:24 +00:00
|
|
|
memcpy(line, p - line_offset, line_offset + 1);
|
2017-08-03 09:43:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 21:22:24 +00:00
|
|
|
if (line_offset > 0) {
|
|
|
|
line[line_offset] = '\0';
|
|
|
|
InfoScreen_addLine(this, line);
|
|
|
|
}
|
2017-08-03 09:43:28 +00:00
|
|
|
|
|
|
|
Panel_setSelected(panel, idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CommandScreen_draw(InfoScreen* this) {
|
2020-10-17 10:54:45 +00:00
|
|
|
InfoScreen_drawTitled(this, "Command of process %d - %s", this->process->pid, Process_getCommand(this->process));
|
2017-08-03 09:43:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-05 11:19:50 +00:00
|
|
|
const InfoScreenClass CommandScreen_class = {
|
2017-08-03 09:43:28 +00:00
|
|
|
.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));
|
|
|
|
}
|