diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-09-14 11:36:06 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-11-19 17:00:10 +0000 |
commit | 37d4e01fc4299e85a0fa74169d9f5b17300392b3 (patch) | |
tree | 9705ab1492c19110e008f4895f8ec36b2848b8d2 /Userland/Utilities/diff.cpp | |
parent | ed6d353cdd32f5245b798c52a063ef63c482ec08 (diff) | |
download | serenity-37d4e01fc4299e85a0fa74169d9f5b17300392b3.zip |
diff: Port to Core::Stream
Also switched to calling Core::System::isatty(), and doing so once
instead of per hunk.
Diffstat (limited to 'Userland/Utilities/diff.cpp')
-rw-r--r-- | Userland/Utilities/diff.cpp | 12 |
1 files 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 <LibCore/ArgsParser.h> -#include <LibCore/File.h> +#include <LibCore/Stream.h> #include <LibCore/System.h> #include <LibDiff/Generator.h> #include <LibMain/Main.h> @@ -23,10 +23,12 @@ ErrorOr<int> 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<int> 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) |