From 37d4e01fc4299e85a0fa74169d9f5b17300392b3 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 14 Sep 2022 11:36:06 +0100 Subject: [PATCH] diff: Port to Core::Stream Also switched to calling Core::System::isatty(), and doing so once instead of per hunk. --- Userland/Utilities/diff.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Userland/Utilities/diff.cpp b/Userland/Utilities/diff.cpp index 7b1c4ebea6..6160a8eca5 100644 --- a/Userland/Utilities/diff.cpp +++ b/Userland/Utilities/diff.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include @@ -23,10 +23,12 @@ ErrorOr serenity_main(Main::Arguments arguments) parser.add_positional_argument(filename2, "Second file to compare", "file2", Core::ArgsParser::Required::Yes); parser.parse(arguments); - auto file1 = TRY(Core::File::open(filename1, Core::OpenMode::ReadOnly)); - auto file2 = TRY(Core::File::open(filename2, Core::OpenMode::ReadOnly)); + auto file1 = TRY(Core::Stream::File::open(filename1, Core::Stream::OpenMode::Read)); + auto file2 = TRY(Core::Stream::File::open(filename2, Core::Stream::OpenMode::Read)); - auto hunks = Diff::from_text(file1->read_all(), file2->read_all()); + bool color_output = TRY(Core::System::isatty(STDOUT_FILENO)); + + auto hunks = Diff::from_text(TRY(file1->read_all()), TRY(file2->read_all())); for (auto const& hunk : hunks) { auto original_start = hunk.original_start_line; auto target_start = hunk.target_start_line; @@ -52,8 +54,6 @@ ErrorOr serenity_main(Main::Arguments arguments) if (num_added > 1) sb.appendff(",{}", target_start + num_added - 1); - bool color_output = isatty(STDOUT_FILENO); - outln("Hunk: {}", sb.build()); for (auto const& line : hunk.removed_lines) { if (color_output)