From 07c2db22f0675ad14b0ffbff7b8e2c37ca760022 Mon Sep 17 00:00:00 2001 From: Alfie King Date: Thu, 20 Jun 2024 15:03:39 +0100 Subject: [PATCH] clipboard support --- .gitignore | 4 +--- .vscode/tasks.json | 28 ---------------------------- CMakeLists.txt | 6 ++++++ PKGBUILD | 5 +++-- clip | 1 + owo.cpp | 12 +++++++++++- 6 files changed, 22 insertions(+), 34 deletions(-) delete mode 100644 .vscode/tasks.json create mode 100644 CMakeLists.txt create mode 160000 clip diff --git a/.gitignore b/.gitignore index 10e81be..62142cd 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,4 @@ # Executables *.exe *.out -*.app - -builds/ \ No newline at end of file +*.app \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 05054c5..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "tasks": [ - { - "type": "cppbuild", - "label": "C/C++: g++ build active file", - "command": "/usr/bin/g++", - "args": [ - "-fdiagnostics-color=always", - "-g", - "${file}", - "-o", - "${fileDirname}/${fileBasenameNoExtension}" - ], - "options": { - "cwd": "${fileDirname}" - }, - "problemMatcher": [ - "$gcc" - ], - "group": { - "kind": "build", - "isDefault": true - }, - "detail": "Task generated by Debugger." - } - ], - "version": "2.0.0" -} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7edcd2e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 2.8) +project(owo) +add_executable(owo owo.cpp) +add_subdirectory(clip) +target_link_libraries(owo clip) + diff --git a/PKGBUILD b/PKGBUILD index 9f4a067..68edec7 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -12,10 +12,11 @@ md5sums=('SKIP') build() { cd "$srcdir/term-owo-cpp" - g++ -o owo owo.cpp + make . -B build + cd build && make } package() { - cd "$srcdir/term-owo-cpp" + cd "$srcdir/term-owo-cpp/build" install -Dm755 owo "$pkgdir/usr/bin/owo" } \ No newline at end of file diff --git a/clip b/clip new file mode 160000 index 0000000..4e9eeea --- /dev/null +++ b/clip @@ -0,0 +1 @@ +Subproject commit 4e9eeea9293c6f35a1ebac0fd66db7463890f143 diff --git a/owo.cpp b/owo.cpp index bcdac8d..e70e0b0 100644 --- a/owo.cpp +++ b/owo.cpp @@ -2,6 +2,7 @@ #include #include #include +#include "clip/clip.h" using namespace std; string replacements[6][2] = { @@ -29,12 +30,16 @@ int help() { cout << "Options:" << endl; cout << " -p Read from stdin" << endl; cout << " -h Show this help message" << endl; + cout << " -f Read from file" << endl; + cout << " -o Write to file" << endl; + cout << " -c Copy to clipboard" << endl; + cout << " text Text to convert" << endl; return 0; } int main(int argc, char *argv[]) { string input, inputfile, outputfile; - bool _stdin = false; + bool _stdin = false, clipboard = false; if (argc < 2) { cout << owo("No text provided") << endl << endl; @@ -55,6 +60,8 @@ int main(int argc, char *argv[]) { return help(); } else if (i == argc-1) { input = string(argv[i]); + } else if (string(argv[i]) == "-c") { + clipboard = true; } else { cout << owo("Invalid argument: " + string(argv[i])) << endl << endl; help(); @@ -109,6 +116,9 @@ int main(int argc, char *argv[]) { } else if (input != "") { if (outputfile != "") { *output << owo(input) << endl; + } else if (clipboard) { + clip::set_text(owo(input)); + cout << owo("Copied to clipboard") << endl; } else { cout << owo(input) << endl; }