mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:04:59 +00:00
diff: Port to Core::Stream
Also switched to calling Core::System::isatty(), and doing so once instead of per hunk.
This commit is contained in:
parent
ed6d353cdd
commit
37d4e01fc4
1 changed files with 6 additions and 6 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue