Added an option to disable the mouse.

This commit is contained in:
MartinJM
2019-07-12 21:41:09 +02:00
parent 402e46bb82
commit b0e24cd5a5
4 changed files with 42 additions and 27 deletions

37
htop.c
View File

@ -34,11 +34,12 @@ 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"
@ -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,
};
@ -85,6 +88,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
{"user", required_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'},
{0,0,0,0}
@ -92,7 +96,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
int opt, opti=0;
/* Parse arguments */
while ((opt = getopt_long(argc, argv, "hvCs:td:u:p:", long_opts, &opti))) {
while ((opt = getopt_long(argc, argv, "hvmCs:td:u:p:", long_opts, &opti))) {
if (opt == EOF) break;
switch (opt) {
case 'h':
@ -130,6 +134,9 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
case 'C':
flags.useColors = false;
break;
case 'm':
flags.enableMouse = false;
break;
case 't':
flags.treeView = true;
break;
@ -186,12 +193,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;
@ -201,18 +208,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;
@ -228,7 +237,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);
@ -236,13 +245,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);
@ -250,10 +259,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);
}