[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Which Diff tool could I use for visually comparing two text files where Word Wrap is possible?



On Mon, 3 Apr 2023 Susmita/Rajib wrote:
[trimmed headers]
[   ...   ]
You have reported that redirecting icdiff output to a file, in your
words, "drops all colors".

And so I have three questions:
[trimmed davidson's questions]
$ icdiff file1 file2 > pretty_diff
$ less -R pretty_diff
[   ...   ]

Yes, thank you. From your indications it became apparent to me the
idiocy that I was engaged in.

No mistakes means no learning. Learning how to make mistakes, to dare
the facts to expose one's false beliefs, is a great art.

Children tend to be adept at this. But grown-ups can do it too with
practice.

I failed to look into what was really meant by your two lines of
codes. I was redirecting the output to a file with a .txt
extension. So when the default application for my Debian
installation, mousepad, opened the file it dropped all colours.
with a lot of extended chars.

The output contains, in addition to the characters that comprise your
document's text, embedded character sequences which you can display
literally with (for example),

 $ cat -v pretty_diff.txt # the digraph '^[' is the ESC character

and these instruct a terminal which implements them to do various
things.

As I understand it, the semantics of these sequences were defined for
terminals. They implement many functions --not just color-- useful for
any teletype-descendant like a unix terminal emulator. Expecting other
applications to implement them too will probably lead to
disappointment. But do prove me wrong if you like.

[trimmed]
This leads me to the next automatic questions:

Would it be possible to increase the column length for the either of
the two files being compared,

I take this to mean that you would like to increase the length of
lines displayed...

so that I could let the terminal window frame occupy the entire
screen space?

...in order to maximise the use of screen real estate.

That is, you'd like to be shown as many characters on one screen as
possible, without a lot of wastefully empty margins.

(I expect I have overstated your intent here. Do correct me.)

It looks to me like icdiff tries to remain faithful to the source
comparands, to the files you request it to compare.

More concretely: Let's say the source files have newlines at a
position no greater than column 55 (say). This means a side-by-side
comparison will require about 113 columns.

Since you have a giant display that can accomodate far more than that,
icdiff displays sizeable righthand margins on each half of a maximised
terminal window.

So you would like icdiff to "flow" the text when it displays each
source on its half of the terminal. You would like icdiff to replace
newlines with spaces, and then wrap them (ie, inserting new newlines)
as appropriate to fill up the right margins on each half.

icdiff will not do that. icdiff is faithful to its sources. I have
determined this by trying it out a little myself, and by examining the
command line options documented in its manual page ("man icdiff").

You could give it different sources:

 $ icdiff <( tr '\n' ' ' <file1 ) <( tr '\n' ' ' <file2 )

You can define a function to do the same thing, to save some typing at
future invocations,

 $ icdiff-flowed () { <( tr '\n' ' ' <file1 ) <( tr '\n' ' ' <file2 ) ; }

and then use it like so

 $ icdiff-flowed file1 file2 | less -R

I imagine this is not quite what you want. But this seems like a good
place to pause, to give you an opportunity to correct me, or to
elaborate on the requirements.

If that is not possible

I expect it is, but I may not yet fully understand what you are
looking for.

then which application should I use in GUI to have all colours
faithfully represented?

You will have far more experience with the range of GUI applications
that might serve your needs than I ever will. Control by keyboard is a
hard requirement of mine. GUIs, naturally enough, rarely meet it.

This might help me overcome the column restrictions.

Do correct or extend my understanding of what you seek.

--
Hackers are free people. They are like artists. If they are in a good
mood, they get up in the morning and begin painting their pictures.
-- Vladimir Putin


Reply to: