From 724aae60d14c1721518c768a48e1e46e3391bb4e Mon Sep 17 00:00:00 2001
From: Daniel Flanagan
Date: Fri, 6 Apr 2018 21:52:50 -0500
Subject: [PATCH 1/3] Add tree view flag to man page
---
htop.1.in | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/htop.1.in b/htop.1.in
index 981645202..774bc0999 100644
--- a/htop.1.in
+++ b/htop.1.in
@@ -3,7 +3,7 @@
htop \- interactive process viewer
.SH "SYNOPSIS"
.LP
-.B htop [\fI\-dChusv\fR]
+.B htop [\fI\-dChustv\fR]
.SH "DESCRIPTION"
.LP
Htop is a free (GPL) ncurses-based process viewer for Linux.
@@ -41,6 +41,9 @@ Show only the processes of a given user
.TP
\fB\-v \-\-version
Output version information and exit
+.TP
+\fB\-t \-\-tree
+Show processes in tree view
.PP
.br
.SH "INTERACTIVE COMMANDS"
From 12805f61d89f2869352ed83b98986cab730bd6fb Mon Sep 17 00:00:00 2001
From: Daniel Flanagan
Date: Thu, 31 Oct 2019 11:20:55 -0500
Subject: [PATCH 2/3] Add simple vim mode
This commit adds a "vim_mode" setting (false/`0` by default) that causes
keys to be remapped in the following way by the `ScreenManager`:
+ h -> LEFT
+ j -> DOWN
+ k -> UP
+ l -> RIGHT
+ LEFT -> h (toggle help)
+ DOWN -> j (noop)
+ UP -> k (open kill menu)
+ RIGHT -> l (lsof current process)
+ K (Shift+K) -> k (open kill menu)
+ J (Shift+J) -> K (toggle show/hide kernel threads)
+ L (Shift+L) -> l (lsof current process)
I couldn't figure out where the manpage documentation is in the repo,
though I admittedly did not look particularly hard.
I believe this change would be a welcome option for heavy vim users like myself
who would like a familiar way to get around in htop.
---
ScreenManager.c | 17 +++++++++++++++++
Settings.c | 20 ++++++++++++--------
Settings.h | 3 ++-
3 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/ScreenManager.c b/ScreenManager.c
index 06e901938..81aa2960c 100644
--- a/ScreenManager.c
+++ b/ScreenManager.c
@@ -190,6 +190,23 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
set_escdelay(25);
ch = getch();
+ if (this->settings->vimMode) {
+ switch (ch) {
+ case 'h': ch = KEY_LEFT; break;
+ case 'j': ch = KEY_DOWN; break;
+ case 'k': ch = KEY_UP; break;
+ case 'l': ch = KEY_RIGHT; break;
+ case KEY_LEFT: ch = 'h'; break;
+ case KEY_DOWN: ch = 'j'; break;
+ case KEY_UP: ch = 'k'; break;
+ case KEY_RIGHT: ch = 'l'; break;
+ case 'K': ch = 'k'; break;
+ case 'J': ch = 'K'; break;
+ case 'L': ch = 'l'; break;
+ }
+ }
+
+
HandlerResult result = IGNORED;
if (ch == KEY_MOUSE) {
ch = ERR;
diff --git a/Settings.c b/Settings.c
index db2fa0668..c07b2cf7e 100644
--- a/Settings.c
+++ b/Settings.c
@@ -31,7 +31,7 @@ typedef struct {
typedef struct Settings_ {
char* filename;
-
+
MeterColumnSettings columns[2];
ProcessField* fields;
@@ -58,6 +58,7 @@ typedef struct Settings_ {
bool updateProcessNames;
bool accountGuestInCPUMeter;
bool headerMargin;
+ bool vimMode;
bool changed;
} Settings;
@@ -114,7 +115,7 @@ static void Settings_defaultMeters(Settings* this) {
this->columns[i].modes = xCalloc(sizes[i], sizeof(int));
this->columns[i].len = sizes[i];
}
-
+
int r = 0;
if (this->cpuCount > 8) {
this->columns[0].names[0] = xStrdup("LeftCPUs2");
@@ -134,7 +135,7 @@ static void Settings_defaultMeters(Settings* this) {
this->columns[0].modes[1] = BAR_METERMODE;
this->columns[0].names[2] = xStrdup("Swap");
this->columns[0].modes[2] = BAR_METERMODE;
-
+
this->columns[1].names[r] = xStrdup("Tasks");
this->columns[1].modes[r++] = TEXT_METERMODE;
this->columns[1].names[r] = xStrdup("LoadAverage");
@@ -165,13 +166,13 @@ static void readFields(ProcessField* fields, int* flags, const char* line) {
static bool Settings_read(Settings* this, const char* fileName) {
FILE* fd;
-
+
CRT_dropPrivileges();
fd = fopen(fileName, "r");
CRT_restorePrivileges();
if (!fd)
return false;
-
+
bool didReadMeters = false;
bool didReadFields = false;
for (;;) {
@@ -244,6 +245,8 @@ static bool Settings_read(Settings* this, const char* fileName) {
} else if (String_eq(option[0], "right_meter_modes")) {
Settings_readMeterModes(this, option[1], 1);
didReadMeters = true;
+ } else if (String_eq(option[0], "vim_mode")) {
+ this->vimMode = atoi(option[1]);
}
String_freeArray(option);
}
@@ -320,12 +323,13 @@ bool Settings_write(Settings* this) {
fprintf(fd, "left_meter_modes="); writeMeterModes(this, fd, 0);
fprintf(fd, "right_meters="); writeMeters(this, fd, 1);
fprintf(fd, "right_meter_modes="); writeMeterModes(this, fd, 1);
+ fprintf(fd, "vim_mode=%d\n", (int) this->vimMode);
fclose(fd);
return true;
}
Settings* Settings_new(int cpuCount) {
-
+
Settings* this = xCalloc(1, sizeof(Settings));
this->sortKey = PERCENT_CPU;
@@ -344,7 +348,7 @@ Settings* Settings_new(int cpuCount) {
this->cpuCount = cpuCount;
this->showProgramPath = true;
this->highlightThreads = true;
-
+
this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField));
// TODO: turn 'fields' into a Vector,
// (and ProcessFields into proper objects).
@@ -375,7 +379,7 @@ Settings* Settings_new(int cpuCount) {
htopDir = String_cat(home, "/.config/htop");
}
legacyDotfile = String_cat(home, "/.htoprc");
-
+
CRT_dropPrivileges();
(void) mkdir(configDir, 0700);
(void) mkdir(htopDir, 0700);
diff --git a/Settings.h b/Settings.h
index d9dc0683c..6e3fb512c 100644
--- a/Settings.h
+++ b/Settings.h
@@ -22,7 +22,7 @@ typedef struct {
typedef struct Settings_ {
char* filename;
-
+
MeterColumnSettings columns[2];
ProcessField* fields;
@@ -49,6 +49,7 @@ typedef struct Settings_ {
bool updateProcessNames;
bool accountGuestInCPUMeter;
bool headerMargin;
+ bool vimMode;
bool changed;
} Settings;
From 9ed47a213bee9fe272e1cf16f4d45730e6b37331 Mon Sep 17 00:00:00 2001
From: Daniel Flanagan
Date: Thu, 31 Oct 2019 11:29:28 -0500
Subject: [PATCH 3/3] Fix whitespace
---
Settings.c | 16 ++++++++--------
Settings.h | 2 +-
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/Settings.c b/Settings.c
index c07b2cf7e..bf78f0f89 100644
--- a/Settings.c
+++ b/Settings.c
@@ -31,7 +31,7 @@ typedef struct {
typedef struct Settings_ {
char* filename;
-
+
MeterColumnSettings columns[2];
ProcessField* fields;
@@ -115,7 +115,7 @@ static void Settings_defaultMeters(Settings* this) {
this->columns[i].modes = xCalloc(sizes[i], sizeof(int));
this->columns[i].len = sizes[i];
}
-
+
int r = 0;
if (this->cpuCount > 8) {
this->columns[0].names[0] = xStrdup("LeftCPUs2");
@@ -135,7 +135,7 @@ static void Settings_defaultMeters(Settings* this) {
this->columns[0].modes[1] = BAR_METERMODE;
this->columns[0].names[2] = xStrdup("Swap");
this->columns[0].modes[2] = BAR_METERMODE;
-
+
this->columns[1].names[r] = xStrdup("Tasks");
this->columns[1].modes[r++] = TEXT_METERMODE;
this->columns[1].names[r] = xStrdup("LoadAverage");
@@ -166,13 +166,13 @@ static void readFields(ProcessField* fields, int* flags, const char* line) {
static bool Settings_read(Settings* this, const char* fileName) {
FILE* fd;
-
+
CRT_dropPrivileges();
fd = fopen(fileName, "r");
CRT_restorePrivileges();
if (!fd)
return false;
-
+
bool didReadMeters = false;
bool didReadFields = false;
for (;;) {
@@ -329,7 +329,7 @@ bool Settings_write(Settings* this) {
}
Settings* Settings_new(int cpuCount) {
-
+
Settings* this = xCalloc(1, sizeof(Settings));
this->sortKey = PERCENT_CPU;
@@ -348,7 +348,7 @@ Settings* Settings_new(int cpuCount) {
this->cpuCount = cpuCount;
this->showProgramPath = true;
this->highlightThreads = true;
-
+
this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField));
// TODO: turn 'fields' into a Vector,
// (and ProcessFields into proper objects).
@@ -379,7 +379,7 @@ Settings* Settings_new(int cpuCount) {
htopDir = String_cat(home, "/.config/htop");
}
legacyDotfile = String_cat(home, "/.htoprc");
-
+
CRT_dropPrivileges();
(void) mkdir(configDir, 0700);
(void) mkdir(htopDir, 0700);
diff --git a/Settings.h b/Settings.h
index 6e3fb512c..ec119d1c7 100644
--- a/Settings.h
+++ b/Settings.h
@@ -22,7 +22,7 @@ typedef struct {
typedef struct Settings_ {
char* filename;
-
+
MeterColumnSettings columns[2];
ProcessField* fields;