delta icon indicating copy to clipboard operation
delta copied to clipboard

avoid the display issue with git add -p without losing CR

Open yoichi opened this issue 3 years ago • 8 comments

Solve https://github.com/dandavison/delta/pull/664 without losing CRs in delta's output. This will also show other control characters in the output of git add-p.

It partially fixes https://github.com/dandavison/delta/issues/754 There remains a problem on preserving CRs in delta's input.

yoichi avatar Mar 03 '22 10:03 yoichi

I found that git diff --color=always does not guarantee the escape sequence between CR and LF on each line. So this It wasn't enough for #754.

I think we should deal with it by extending bytelines or not using bytelines.

is needed...

yoichi avatar Mar 03 '22 11:03 yoichi

Ho @yoichi, I think patching bytelines, or not using bytelines, are good ideas. The bytelines author was very helpful when I contacted them about an issue.

Not using it does make sense though, since it's not a mainstream library. I think the reason I started using it was to support non-utf8 encoded input. I'll find the relevant issues.

dandavison avatar Mar 03 '22 11:03 dandavison

See https://github.com/dandavison/delta/issues/188 for encoding discussion. I think I never finished the work discussed.

dandavison avatar Mar 03 '22 11:03 dandavison

bytelines allows us to output lossy decoding. Before bytelines I was doing this, which meant an error message would appear in the middle of user's output: https://github.com/dandavison/delta/commit/9d1aafee2465b3b89de09ae72e1b8b8fbda4a981

We should look how other Rust projects deal with non utf8 input; do they not use stdin.lock().lines()?

dandavison avatar Mar 03 '22 11:03 dandavison

There seems need to a new issue (or #754 probably) to discuss how to preserve CR.

norisio avatar Mar 04 '22 02:03 norisio

I have to say my instinct is that this doesn't feel like the right solution. But I don't think I have the problem clear in my mind so I'm sorry to say something vague like that. I don't really want to make delta's instructions for git add -p more complicated (that's my fault because the name --color-only was never a very good name!)

What is this there about this problem that is specific to git add -p?

dandavison avatar Mar 04 '22 03:03 dandavison

The problem specfic to git add -p is that if we preserve CRs (and other control characters) and want to show them, we must translate them to something printable (e.g. caret notation), since bare control characters will be handled by the terminal.

After I've read the following comment from @dandavison on #754

I do think it's worth bearing in mind that delta's output is for humans to look at, not for machines to parse

then I came up with an idea: we can choose delta's bahavior that it always translate control characters in its output to printables, without introducing new option, and not limited to git add -p.

yoichi avatar Mar 05 '22 14:03 yoichi

In 4ac5035, I've removed the option caret-encode added in this PR.

Note

  • The replacement process can be placed earlier, but it makes the input caret notation and control characters indistinguishable.
  • This change allows us to use reverse video to distinguish between them.

yoichi avatar Mar 05 '22 21:03 yoichi