mirror of https://github.com/aristocratos/btop.git
Merge ca1bfb69b9
into ac17f34580
This commit is contained in:
commit
9be3ae2ca9
|
@ -436,6 +436,9 @@ namespace Input {
|
|||
return;
|
||||
else if (old_selected != new_selected and (old_selected == 0 or new_selected == 0))
|
||||
redraw = true;
|
||||
} else if (is_in(key, "copyout-shellcmd", "v")) {
|
||||
atomic_wait(Runner::active);
|
||||
copy_to_clipboard(get_cmd_line(Config::getI("selected_pid")));
|
||||
}
|
||||
else keep_going = true;
|
||||
|
||||
|
|
|
@ -141,6 +141,7 @@ namespace Menu {
|
|||
{"c", "Toggle per-core cpu usage of processes."},
|
||||
{"r", "Reverse sorting order in processes box."},
|
||||
{"e", "Toggle processes tree view."},
|
||||
{"v", "Copy the select process' command line to clipboard."},
|
||||
{"Selected +, -", "Expand/collapse the selected process in tree view."},
|
||||
{"Selected t", "Terminate selected process with SIGTERM - 15."},
|
||||
{"Selected k", "Kill selected process with SIGKILL - 9."},
|
||||
|
|
|
@ -82,7 +82,7 @@ namespace Shared {
|
|||
//* Initialize platform specific needed variables and check for errors
|
||||
void init();
|
||||
|
||||
extern long coreCount, page_size, clk_tck;
|
||||
extern long coreCount, page_size, clk_tck, arg_max;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -598,3 +598,18 @@ namespace Logger {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_cmd_line(size_t pid) {
|
||||
auto procs = Proc::collect(true);
|
||||
auto p_info = rng::find(procs, pid, &Proc::proc_info::pid);
|
||||
return p_info->cmd; // Copy
|
||||
}
|
||||
|
||||
int copy_to_clipboard(const std::string& msg) {
|
||||
// TODO(..): Implement FreeBSD and Linux
|
||||
#ifdef __APPLE__
|
||||
return pcopy(msg.c_str());
|
||||
#elif // __APPLE__
|
||||
return 0;
|
||||
#endif // __APPLE__
|
||||
}
|
||||
|
|
|
@ -359,3 +359,6 @@ namespace Logger {
|
|||
inline void debug(const string msg) { log_write(4, msg); }
|
||||
}
|
||||
|
||||
std::string get_cmd_line(size_t pid);
|
||||
int copy_to_clipboard(const std::string& msg);
|
||||
extern bool pcopy(const char *buf);
|
||||
|
|
|
@ -1220,7 +1220,7 @@ namespace Proc {
|
|||
std::string_view proc_args(proc_chars.get(), argmax);
|
||||
if (size_t null_pos = proc_args.find('\0', sizeof(argc)); null_pos != string::npos) {
|
||||
if (size_t start_pos = proc_args.find_first_not_of('\0', null_pos); start_pos != string::npos) {
|
||||
while (argc-- > 0 and null_pos != string::npos and cmp_less(new_proc.cmd.size(), 1000)) {
|
||||
while (argc-- > 0 and null_pos != string::npos and cmp_less(new_proc.cmd.size(), argmax)) {
|
||||
null_pos = proc_args.find('\0', start_pos);
|
||||
new_proc.cmd += (string)proc_args.substr(start_pos, null_pos - start_pos) + ' ';
|
||||
start_pos = null_pos + 1;
|
||||
|
@ -1231,8 +1231,8 @@ namespace Proc {
|
|||
}
|
||||
}
|
||||
if (new_proc.cmd.empty()) new_proc.cmd = f_name;
|
||||
if (new_proc.cmd.size() > 1000) {
|
||||
new_proc.cmd.resize(1000);
|
||||
if (new_proc.cmd.size() > static_cast<size_t>(Shared::arg_max)) {
|
||||
new_proc.cmd.resize(Shared::arg_max);
|
||||
new_proc.cmd.shrink_to_fit();
|
||||
}
|
||||
new_proc.ppid = kproc.kp_eproc.e_ppid;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#include <AppKit/AppKit.h>
|
||||
|
||||
bool pcopy(const char *buf) {
|
||||
NSString *text = @(buf);
|
||||
[[NSPasteboard generalPasteboard] clearContents];
|
||||
[[NSPasteboard generalPasteboard] setString:text
|
||||
forType:NSPasteboardTypeString];
|
||||
return true;
|
||||
}
|
|
@ -34,7 +34,7 @@ static UInt32 _strtoul(char *str, int size, int base) {
|
|||
|
||||
static void _ultostr(char *str, UInt32 val) {
|
||||
str[0] = '\0';
|
||||
sprintf(str, "%c%c%c%c",
|
||||
snprintf(str, sizeof(UInt32Char_t), "%c%c%c%c",
|
||||
(unsigned int)val >> 24,
|
||||
(unsigned int)val >> 16,
|
||||
(unsigned int)val >> 8,
|
||||
|
|
Loading…
Reference in New Issue