diff options
author | Tor Lillqvist <tml@collabora.com> | 2021-01-14 16:39:37 +0200 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2021-01-14 15:49:49 +0100 |
commit | 1dacb8cb94162310345b7f63f7ceda35a7152d0a (patch) | |
tree | b089c8210092edd09ae62597d6e1e63fee5caefd /vcl/workben | |
parent | 30b599ed276ca48e4077931d81f83f529acc9593 (diff) |
Add an option to dump pasteboard data for a type to stdout
Change-Id: Iafa24799c5c18abef93f032a2f637c39f4a9cf5e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109296
Tested-by: Tor Lillqvist <tml@collabora.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'vcl/workben')
-rw-r--r-- | vcl/workben/pasteboard.mm | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/vcl/workben/pasteboard.mm b/vcl/workben/pasteboard.mm index b38b19387602..3d523afeb383 100644 --- a/vcl/workben/pasteboard.mm +++ b/vcl/workben/pasteboard.mm @@ -12,13 +12,59 @@ // Build with: clang++ -Wall -o pasteboard vcl/workben/pasteboard.mm -framework AppKit +#import <unistd.h> + #import <iostream> #import <AppKit/AppKit.h> +static void usage() +{ + std::cout << + "Usage: pastebord\n" + " --List the types on the pasteboard and in each pasteboard item.\n" + " pasteboard -t type\n" + " --Output the data for the type in question to stdout. Note: output will in many cases be binary.\n"; +} + int main(int argc, char** argv) { + NSString* requestedType; + + int ch; + + while ((ch = getopt(argc, argv, "t:")) != -1) + { + switch (ch) + { + case 't': + requestedType = [NSString stringWithUTF8String:optarg]; + break; + case '?': + usage(); + break; + } + } + + argc -= optind; + argv += optind; + + if (argc > 0) + { + usage(); + return 1; + } + NSPasteboard* pb = [NSPasteboard generalPasteboard]; + if ([requestedType length] > 0) + { + NSData *data = [pb dataForType:requestedType]; + + std::cout.write((const char *)[data bytes], [data length]); + + return 0; + } + { NSArray<NSPasteboardType>* types = [pb types]; std::cout << "Types directly on pasteboard:\n"; |