From f4bb50294a31c0d46dbcd742c4002f4fbb20d2a8 Mon Sep 17 00:00:00 2001 From: ryenus Date: Thu, 3 Aug 2017 17:43:28 +0800 Subject: show selected command wrapped in a separate window For a process with a very long command, especially with many long command line arguments, inspecting the command and its arguments could become inconvenient. Meanwhile htop supports the concept of "screen", or window, which is extended here to create a dedicated "CommandScreen", making it possible to display the command of the selected process in a separate window meanwhile being wrapped into multiple lines. Another benefit of using a command screen is, the user can navigate through the wrapped lines of the command and perform actions like searching and filtering. --- Action.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'Action.c') diff --git a/Action.c b/Action.c index eac7f1f6..f36e0bd2 100644 --- a/Action.c +++ b/Action.c @@ -13,6 +13,7 @@ in the source distribution for its full text. #include "CategoriesPanel.h" #include "CRT.h" #include "EnvScreen.h" +#include "CommandScreen.h" #include "MainPanel.h" #include "OpenFilesScreen.h" #include "Process.h" @@ -422,8 +423,8 @@ static const struct { const char* key; const char* info; } helpRight[] = { { .key = " e: ", .info = "show process environment" }, { .key = " i: ", .info = "set IO priority" }, { .key = " l: ", .info = "list open files with lsof" }, + { .key = " M: ", .info = "show process command in multiple lines" }, { .key = " s: ", .info = "trace syscalls with strace" }, - { .key = " ", .info = "" }, { .key = " F2 C S: ", .info = "setup" }, { .key = " F1 h: ", .info = "show this help screen" }, { .key = " F10 q: ", .info = "quit" }, @@ -530,6 +531,16 @@ static Htop_Reaction actionShowEnvScreen(State* st) { return HTOP_REFRESH | HTOP_REDRAW_BAR; } +static Htop_Reaction actionShowCommandScreen(State* st) { + Process* p = (Process*) Panel_getSelected(st->panel); + if (!p) return HTOP_OK; + CommandScreen* cmdScr = CommandScreen_new(p); + InfoScreen_run((InfoScreen*)cmdScr); + CommandScreen_delete((Object*)cmdScr); + clear(); + CRT_enableDelay(); + return HTOP_REFRESH | HTOP_REDRAW_BAR; +} void Action_setBindings(Htop_Action* keys) { keys[KEY_RESIZE] = actionResize; @@ -584,4 +595,5 @@ void Action_setBindings(Htop_Action* keys) { keys['U'] = actionUntagAll; keys['c'] = actionTagAllChildren; keys['e'] = actionShowEnvScreen; + keys['M'] = actionShowCommandScreen; } -- cgit v1.2.3