Skip to content

Commit

Permalink
Add -b flag to copy to clipboard
Browse files Browse the repository at this point in the history
Philippe: update `README.adoc` and change original `-x` to `-b`.

Refs: #19
Signed-off-by: Philippe Proulx <[email protected]>
  • Loading branch information
coolreader18 authored and eepp committed Nov 11, 2023
1 parent 3e37b71 commit 568d8c0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ jome 🖨 the UTF-8 emoji or the Unicode codepoints (see the
<<opt-p,`-p`{nbsp}option>>) for each codepoint, to the standard output.
Additionally, jome can:

* Copy the UTF-8 emoji or the Unicode codepoints to the clipboard. See
the <<opt-b,`-b`{nbsp}option>>.

* Execute a custom command which receives the UTF-8 emoji or the Unicode
codepoints, with an optional prefix for each codepoint, as its
last argument(s). See the <<opt-s,`-c`{nbsp}option>>.
last argument(s). See the <<opt-c,`-c`{nbsp}option>>.

* Send the UTF-8 emoji or the Unicode codepoints, with an optional
prefix for each codepoint, in response to a client which requested
Expand Down Expand Up @@ -248,6 +251,10 @@ $ jome -c 'xdotool type'
$ jome -f cp -p U -c 'xdotool key --delay 20'
----

[[opt-b]]`-b`::
When you accept an emoji, copy the UTF-8 emoji or the Unicode
codepoints (depending on the <<opt-f,`-f`{nbsp}option>>) to the 📋.

[[opt-q]]`-q`::
Do not quit when you <<accept-emoji,accept>> an emoji.
+
Expand All @@ -256,6 +263,8 @@ By default, when you accept an emoji (with the ⌨️ or with the 🖱), jome:
--
. 🖨 the accepted emoji or its codepoints to the standard output.
. Hides its 🪟.
. **Optional**: Copies the accepted emoji/codepoints to the
clipboard (see the <<opt-b,`-b`{nbsp}option>>).
. **Optional**: Executes a command (see the <<opt-c,`-c`{nbsp}option>>)
after 20{nbsp}ms.
. **If not running in server mode**, quits (see the
Expand Down
9 changes: 9 additions & 0 deletions jome/jome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include <QApplication>
#include <QClipboard>
#include <QCommandLineParser>
#include <QString>
#include <QProcess>
Expand Down Expand Up @@ -34,6 +35,7 @@ struct Params
bool noNewline;
bool noHide;
bool darkBg;
bool copyToClipboard;
boost::optional<std::string> serverName;
boost::optional<std::string> cmd;
std::string cpPrefix;
Expand All @@ -53,6 +55,7 @@ Params parseArgs(QApplication& app)
const QCommandLineOption formatOpt {"f", "Output format (`utf-8` or `cp`)", "FORMAT", "utf-8"};
const QCommandLineOption serverNameOpt {"s", "Server name", "NAME"};
const QCommandLineOption cmdOpt {"c", "External command", "CMD"};
const QCommandLineOption copyToClipboardOpt {"b", "Copy the accepted emoji to the clipboard"};
const QCommandLineOption cpPrefixOpt {"p", "Codepoint prefix", "CPPREFIX"};
const QCommandLineOption noNlOpt {"n", "Do not output newline"};
const QCommandLineOption noHideOpt {"q", "Do not quit when accepting"};
Expand All @@ -62,6 +65,7 @@ Params parseArgs(QApplication& app)
parser.addOption(formatOpt);
parser.addOption(serverNameOpt);
parser.addOption(cmdOpt);
parser.addOption(copyToClipboardOpt);
parser.addOption(cpPrefixOpt);
parser.addOption(noNlOpt);
parser.addOption(noHideOpt);
Expand All @@ -74,6 +78,7 @@ Params parseArgs(QApplication& app)
params.noNewline = parser.isSet(noNlOpt);
params.noHide = parser.isSet(noHideOpt);
params.darkBg = parser.isSet(darkBgOpt);
params.copyToClipboard = parser.isSet(copyToClipboardOpt);

const auto fmt = parser.value(formatOpt);

Expand Down Expand Up @@ -235,6 +240,10 @@ int main(int argc, char **argv)
std::cout << emojiStr;
std::cout.flush();

if (params.copyToClipboard) {
QGuiApplication::clipboard()->setText(QString::fromStdString(emojiStr));
}

if (params.cmd) {
// execute command in 20 ms
QTimer::singleShot(20, &app, [&params, &server, &app, emojiStr]() {
Expand Down

0 comments on commit 568d8c0

Please sign in to comment.