Skip to content

Commit

Permalink
refactor: use a custom command, set in config as copy_command, to c…
Browse files Browse the repository at this point in the history
…opy to clipboard instead, to support all windowing systems
  • Loading branch information
stevenxxiu committed May 21, 2023
1 parent 3c51761 commit b89549a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

16 changes: 2 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,6 @@ ifeq ($(THREADS),1)
override THREADS := auto
endif

#? Pull in the clipboard library
CLIPDIR := lib/clip
override ADDFLAGS += -L$(CLIPDIR) -lclip
ifeq ($(PLATFORM_LC),linux)
override ADDFLAGS += -lxcb
endif

#? The Directories, Source, Includes, Objects and Binary
SRCDIR := src
INCDIR := include
Expand All @@ -141,7 +134,7 @@ OPTFLAGS := -O2 -ftree-vectorize -flto=$(THREADS)
LDCXXFLAGS := -pthread -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS $(GOODFLAGS) $(ADDFLAGS)
override CXXFLAGS += $(REQFLAGS) $(LDCXXFLAGS) $(OPTFLAGS) $(WARNFLAGS)
override LDFLAGS += $(LDCXXFLAGS) $(OPTFLAGS) $(WARNFLAGS)
INC := -I$(INCDIR) -I$(CLIPDIR) -I$(SRCDIR)
INC := -I$(INCDIR) -I$(SRCDIR)
SU_USER := root

ifdef DEBUG
Expand Down Expand Up @@ -175,11 +168,6 @@ P := %%
#? Default Make
all: $(PRE) directories btop

clip:
@cd $(CLIPDIR)
@env CXXFLAGS="" LDFLAGS="" cmake -DCLIP_X11_WITH_PNG=OFF .
@env CXXFLAGS="" LDFLAGS="" make

info:
@printf " $(BANNER)\n"
@printf "\033[1;92mPLATFORM \033[1;93m?| \033[0m$(PLATFORM)\n"
Expand Down Expand Up @@ -273,7 +261,7 @@ uninstall:

#? Link
.ONESHELL:
btop: $(OBJECTS) | directories clip
btop: $(OBJECTS) | directories
@sleep 0.2 2>/dev/null || true
@TSTAMP=$$(date +%s 2>/dev/null || echo "0")
@$(QUIET) || printf "\n\033[1;92mLinking and optimizing binary\033[37m...\033[0m\n"
Expand Down
1 change: 0 additions & 1 deletion lib/clip
Submodule clip deleted from 343323
3 changes: 3 additions & 0 deletions src/btop_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ namespace Config {
{"vim_keys", "#* Set to True to enable \"h,j,k,l,g,G\" keys for directional control in lists.\n"
"#* Conflicting keys for h:\"help\" and k:\"kill\" is accessible while holding shift."},

{"copy_command", "#* Command to copy to the system clipboard. Clipboard contents are piped into stdin."},

{"rounded_corners", "#* Rounded corners on boxes, is ignored if TTY mode is ON."},

{"graph_symbol", "#* Default symbols to use for graph creation, \"braille\", \"block\" or \"tty\".\n"
Expand Down Expand Up @@ -198,6 +200,7 @@ namespace Config {
{"shown_boxes", "cpu mem net proc"},
{"graph_symbol", "braille"},
{"presets", "cpu:1:default,proc:0:default cpu:0:default,mem:0:default,net:0:default cpu:0:block,net:0:tty"},
{"copy_command", ""},
{"graph_symbol_cpu", "default"},
{"graph_symbol_mem", "default"},
{"graph_symbol_net", "default"},
Expand Down
16 changes: 13 additions & 3 deletions src/btop_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ tab-size = 4
#include <thread>
#include <mutex>

#include <clip.h>

#include <btop_input.hpp>
#include <btop_tools.hpp>
#include <btop_config.hpp>
Expand Down Expand Up @@ -441,7 +439,19 @@ namespace Input {
}
else if (key == "x") {
atomic_wait(Runner::active);
clip::set_text(Config::getS("selected_cmd"));

auto copy_command = Config::getS("copy_command");
if (copy_command.empty()) {
vector<string> cont_vec;
cont_vec.emplace_back("`copy_command` is empty");
Menu::msgBox messageBox = Menu::msgBox{45, 0, cont_vec, "error"};
Global::overlay = messageBox();
} else {
FILE *p_copy_stdin = popen(copy_command.c_str(), "w");
auto selected_cmd = Config::getS("selected_cmd");
fwrite(selected_cmd.c_str(), selected_cmd.length(), selected_cmd.length(), p_copy_stdin);
pclose(p_copy_stdin);
}
}
else keep_going = true;

Expand Down

0 comments on commit b89549a

Please sign in to comment.