2020-01-18 11:38:21 +03:00
|
|
|
/*
|
2020-01-24 16:45:29 +03:00
|
|
|
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-09-17 21:45:38 +03:00
|
|
|
#include <AK/String.h>
|
2020-02-06 17:04:03 +03:00
|
|
|
#include <LibCore/ArgsParser.h>
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/Application.h>
|
|
|
|
#include <LibGUI/Clipboard.h>
|
2019-09-22 21:50:39 +03:00
|
|
|
#include <stdlib.h>
|
2019-09-17 21:45:38 +03:00
|
|
|
|
2020-01-27 20:25:36 +03:00
|
|
|
int main(int argc, char* argv[])
|
2019-09-17 21:45:38 +03:00
|
|
|
{
|
2020-01-27 20:25:36 +03:00
|
|
|
bool print_type = false;
|
|
|
|
bool no_newline = false;
|
2019-09-17 21:45:38 +03:00
|
|
|
|
2020-02-02 14:34:39 +03:00
|
|
|
Core::ArgsParser args_parser;
|
2020-12-05 18:22:58 +03:00
|
|
|
args_parser.set_general_help("Paste from the clipboard to stdout.");
|
2020-01-27 20:25:36 +03:00
|
|
|
args_parser.add_option(print_type, "Display the copied type", "print-type", 0);
|
|
|
|
args_parser.add_option(no_newline, "Do not append a newline", "no-newline", 'n');
|
|
|
|
args_parser.parse(argc, argv);
|
2019-09-17 21:45:38 +03:00
|
|
|
|
2020-07-04 15:05:19 +03:00
|
|
|
auto app = GUI::Application::construct(argc, argv);
|
2019-09-17 21:45:38 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
auto& clipboard = GUI::Clipboard::the();
|
2019-09-17 21:45:38 +03:00
|
|
|
auto data_and_type = clipboard.data_and_type();
|
|
|
|
|
2020-09-05 17:16:01 +03:00
|
|
|
if (data_and_type.mime_type.is_null()) {
|
2020-12-27 02:59:18 +03:00
|
|
|
warnln("Nothing copied");
|
2020-05-15 22:35:03 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-01-27 20:25:36 +03:00
|
|
|
if (!print_type) {
|
2020-12-27 02:59:18 +03:00
|
|
|
out("{}", StringView(data_and_type.data));
|
2020-12-05 18:22:58 +03:00
|
|
|
// Append a newline to text contents, unless the caller says otherwise.
|
2020-09-05 17:16:01 +03:00
|
|
|
if (data_and_type.mime_type.starts_with("text/") && !no_newline)
|
2020-12-27 02:59:18 +03:00
|
|
|
outln();
|
2019-09-17 21:45:38 +03:00
|
|
|
} else {
|
2020-12-27 02:59:18 +03:00
|
|
|
outln("{}", data_and_type.mime_type);
|
2019-09-17 21:45:38 +03:00
|
|
|
}
|
2019-09-23 10:36:25 +03:00
|
|
|
|
|
|
|
return 0;
|
2019-09-17 21:45:38 +03:00
|
|
|
}
|