mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
copy: Port to Core::Stream
This commit is contained in:
parent
6763e1bd60
commit
39a4f1560b
1 changed files with 7 additions and 12 deletions
|
@ -9,8 +9,7 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/Stream.h>
|
||||||
#include <LibCore/System.h>
|
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/Clipboard.h>
|
#include <LibGUI/Clipboard.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
|
@ -22,7 +21,7 @@ struct Options {
|
||||||
bool clear;
|
bool clear;
|
||||||
};
|
};
|
||||||
|
|
||||||
static Options parse_options(Main::Arguments arguments)
|
static ErrorOr<Options> parse_options(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
auto type = "text/plain"sv;
|
auto type = "text/plain"sv;
|
||||||
Vector<String> text;
|
Vector<String> text;
|
||||||
|
@ -43,15 +42,11 @@ static Options parse_options(Main::Arguments arguments)
|
||||||
// We're not copying anything.
|
// We're not copying anything.
|
||||||
} else if (text.is_empty()) {
|
} else if (text.is_empty()) {
|
||||||
// Copy our stdin.
|
// Copy our stdin.
|
||||||
auto c_stdin = Core::File::construct();
|
auto c_stdin = TRY(Core::Stream::File::standard_input());
|
||||||
bool success = c_stdin->open(
|
auto buffer = TRY(c_stdin->read_all());
|
||||||
STDIN_FILENO,
|
|
||||||
Core::OpenMode::ReadOnly,
|
|
||||||
Core::File::ShouldCloseFileDescriptor::No);
|
|
||||||
VERIFY(success);
|
|
||||||
auto buffer = c_stdin->read_all();
|
|
||||||
dbgln("Read size {}", buffer.size());
|
dbgln("Read size {}", buffer.size());
|
||||||
options.data = String((char*)buffer.data(), buffer.size());
|
dbgln("Read data: `{}`", StringView(buffer.bytes()));
|
||||||
|
options.data = buffer.bytes();
|
||||||
} else {
|
} else {
|
||||||
// Copy the rest of our command-line args.
|
// Copy the rest of our command-line args.
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
@ -66,7 +61,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
auto app = TRY(GUI::Application::try_create(arguments));
|
auto app = TRY(GUI::Application::try_create(arguments));
|
||||||
|
|
||||||
Options options = parse_options(arguments);
|
Options options = TRY(parse_options(arguments));
|
||||||
|
|
||||||
auto& clipboard = GUI::Clipboard::the();
|
auto& clipboard = GUI::Clipboard::the();
|
||||||
if (options.clear)
|
if (options.clear)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue