aboutsummaryrefslogtreecommitdiffstats
path: root/htop.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2020-08-27 07:48:10 +0200
committerDaniel Lange <DLange@git.local>2020-08-27 07:48:10 +0200
commitf3147ea2d1598914c2db53e8cfb34c8ff81e2ff4 (patch)
tree3ee82b2af2ab3d38b6e4b07f3994516aac72f742 /htop.c
parentdf568a576f7b44ac5a2b9b7222c7f39d9932f626 (diff)
downloaddebian_htop-f3147ea2d1598914c2db53e8cfb34c8ff81e2ff4.tar.gz
debian_htop-f3147ea2d1598914c2db53e8cfb34c8ff81e2ff4.tar.bz2
debian_htop-f3147ea2d1598914c2db53e8cfb34c8ff81e2ff4.zip
New upstream version 3.0.0upstream/3.0.0
Diffstat (limited to 'htop.c')
-rw-r--r--htop.c55
1 files changed, 38 insertions, 17 deletions
diff --git a/htop.c b/htop.c
index 6db81dd..7cdf4e4 100644
--- a/htop.c
+++ b/htop.c
@@ -34,16 +34,17 @@ static void printVersionFlag() {
stdout);
exit(0);
}
-
+
static void printHelpFlag() {
fputs("htop " VERSION " - " COPYRIGHT "\n"
"Released under the GNU GPL.\n\n"
"-C --no-color Use a monochrome color scheme\n"
+ "-m --no-mouse Disable the mouse\n"
"-d --delay=DELAY Set the delay between updates, in tenths of seconds\n"
"-h --help Print this help screen\n"
"-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n"
"-t --tree Show the tree view by default\n"
- "-u --user=USERNAME Show only processes of a given user\n"
+ "-u --user[=USERNAME] Show only processes for a given user (or $USER)\n"
"-p --pid=PID,[,PID,PID...] Show only the given PIDs\n"
"-v --version Print version info\n"
"\n"
@@ -62,6 +63,7 @@ typedef struct CommandLineSettings_ {
int sortKey;
int delay;
bool useColors;
+ bool enableMouse;
bool treeView;
} CommandLineSettings;
@@ -73,6 +75,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
.sortKey = 0,
.delay = -1,
.useColors = true,
+ .enableMouse = true,
.treeView = false,
};
@@ -82,18 +85,18 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
{"version", no_argument, 0, 'v'},
{"delay", required_argument, 0, 'd'},
{"sort-key", required_argument, 0, 's'},
- {"user", required_argument, 0, 'u'},
+ {"user", optional_argument, 0, 'u'},
{"no-color", no_argument, 0, 'C'},
{"no-colour",no_argument, 0, 'C'},
+ {"no-mouse", no_argument, 0, 'm'},
{"tree", no_argument, 0, 't'},
{"pid", required_argument, 0, 'p'},
- {"io", no_argument, 0, 'i'},
{0,0,0,0}
};
int opt, opti=0;
/* Parse arguments */
- while ((opt = getopt_long(argc, argv, "hvCst::d:u:p:i", long_opts, &opti))) {
+ while ((opt = getopt_long(argc, argv, "hvmCs:td:u::p:", long_opts, &opti))) {
if (opt == EOF) break;
switch (opt) {
case 'h':
@@ -113,6 +116,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
flags.sortKey = ColumnsPanel_fieldNameToIndex(optarg);
if (flags.sortKey == -1) {
fprintf(stderr, "Error: invalid column \"%s\".\n", optarg);
+ exit(1);
}
break;
case 'd':
@@ -121,16 +125,31 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
if (flags.delay > 100) flags.delay = 100;
} else {
fprintf(stderr, "Error: invalid delay value \"%s\".\n", optarg);
+ exit(1);
}
break;
case 'u':
+ if (!optarg && optind < argc && argv[optind] != NULL &&
+ (argv[optind][0] != '\0' && argv[optind][0] != '-')) {
+ optarg = argv[optind++];
+ }
+
+ if (!optarg) {
+ optarg = getenv("USER");
+ flags.userId = geteuid();
+ }
+
if (!Action_setUserOnly(optarg, &(flags.userId))) {
fprintf(stderr, "Error: invalid user \"%s\".\n", optarg);
+ exit(1);
}
break;
case 'C':
flags.useColors = false;
break;
+ case 'm':
+ flags.enableMouse = false;
+ break;
case 't':
flags.treeView = true;
break;
@@ -187,12 +206,12 @@ int main(int argc, char** argv) {
exit(1);
}
#endif
-
+
Process_setupColumnWidths();
-
+
UsersTable* ut = UsersTable_new();
ProcessList* pl = ProcessList_new(ut, flags.pidWhiteList, flags.userId);
-
+
Settings* settings = Settings_new(pl->cpuCount);
pl->settings = settings;
@@ -202,18 +221,20 @@ int main(int argc, char** argv) {
if (flags.delay != -1)
settings->delay = flags.delay;
- if (!flags.useColors)
+ if (!flags.useColors)
settings->colorScheme = COLORSCHEME_MONOCHROME;
+ if (!flags.enableMouse)
+ settings->enableMouse = false;
if (flags.treeView)
settings->treeView = true;
CRT_init(settings->delay, settings->colorScheme);
-
+
MainPanel* panel = MainPanel_new();
ProcessList_setPanel(pl, (Panel*) panel);
MainPanel_updateTreeFunctions(panel, settings->treeView);
-
+
if (flags.sortKey > 0) {
settings->sortKey = flags.sortKey;
settings->treeView = false;
@@ -229,7 +250,7 @@ int main(int argc, char** argv) {
.header = header,
};
MainPanel_setState(panel, &state);
-
+
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, true);
ScreenManager_add(scr, (Panel*) panel, -1);
@@ -237,13 +258,13 @@ int main(int argc, char** argv) {
millisleep(75);
ProcessList_scan(pl);
- ScreenManager_run(scr, NULL, NULL);
-
+ ScreenManager_run(scr, NULL, NULL);
+
attron(CRT_colors[RESET_COLOR]);
mvhline(LINES-1, 0, ' ', COLS);
attroff(CRT_colors[RESET_COLOR]);
refresh();
-
+
CRT_done();
if (settings->changed)
Settings_write(settings);
@@ -251,10 +272,10 @@ int main(int argc, char** argv) {
ProcessList_delete(pl);
ScreenManager_delete(scr);
-
+
UsersTable_delete(ut);
Settings_delete(settings);
-
+
if(flags.pidWhiteList) {
Hashtable_delete(flags.pidWhiteList);
}

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