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