clipboard support

This commit is contained in:
Alfie King 2024-06-20 15:03:39 +01:00
parent 53245d19fe
commit 07c2db22f0
6 changed files with 22 additions and 34 deletions

4
.gitignore vendored
View File

@ -30,6 +30,4 @@
# Executables # Executables
*.exe *.exe
*.out *.out
*.app *.app
builds/

28
.vscode/tasks.json vendored
View File

@ -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"
}

6
CMakeLists.txt Normal file
View File

@ -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)

View File

@ -12,10 +12,11 @@ md5sums=('SKIP')
build() { build() {
cd "$srcdir/term-owo-cpp" cd "$srcdir/term-owo-cpp"
g++ -o owo owo.cpp make . -B build
cd build && make
} }
package() { package() {
cd "$srcdir/term-owo-cpp" cd "$srcdir/term-owo-cpp/build"
install -Dm755 owo "$pkgdir/usr/bin/owo" install -Dm755 owo "$pkgdir/usr/bin/owo"
} }

1
clip Submodule

@ -0,0 +1 @@
Subproject commit 4e9eeea9293c6f35a1ebac0fd66db7463890f143

12
owo.cpp
View File

@ -2,6 +2,7 @@
#include <regex> #include <regex>
#include <string> #include <string>
#include <fstream> #include <fstream>
#include "clip/clip.h"
using namespace std; using namespace std;
string replacements[6][2] = { string replacements[6][2] = {
@ -29,12 +30,16 @@ int help() {
cout << "Options:" << endl; cout << "Options:" << endl;
cout << " -p Read from stdin" << endl; cout << " -p Read from stdin" << endl;
cout << " -h Show this help message" << 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; return 0;
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
string input, inputfile, outputfile; string input, inputfile, outputfile;
bool _stdin = false; bool _stdin = false, clipboard = false;
if (argc < 2) { if (argc < 2) {
cout << owo("No text provided") << endl << endl; cout << owo("No text provided") << endl << endl;
@ -55,6 +60,8 @@ int main(int argc, char *argv[]) {
return help(); return help();
} else if (i == argc-1) { } else if (i == argc-1) {
input = string(argv[i]); input = string(argv[i]);
} else if (string(argv[i]) == "-c") {
clipboard = true;
} else { } else {
cout << owo("Invalid argument: " + string(argv[i])) << endl << endl; cout << owo("Invalid argument: " + string(argv[i])) << endl << endl;
help(); help();
@ -109,6 +116,9 @@ int main(int argc, char *argv[]) {
} else if (input != "") { } else if (input != "") {
if (outputfile != "") { if (outputfile != "") {
*output << owo(input) << endl; *output << owo(input) << endl;
} else if (clipboard) {
clip::set_text(owo(input));
cout << owo("Copied to clipboard") << endl;
} else { } else {
cout << owo(input) << endl; cout << owo(input) << endl;
} }