Comments (11)
Copy from #10 (comment)
Hey @zavislak I don't know why you use bad = append(bad, []byte(string(c))[0])
You can see this demo instead. https://play.golang.org/p/fHX2TW2-ORG
from reflow.
Do you have more detail examples?
from reflow.
This should illustrate the problem better: https://play.golang.org/p/RLOMbGDu3RV
If you convert a single byte of the a UTF-8 sequence to a string, go will mangle it. This is in effect what happens when the new ansi.Writer outputs the sequences one byte at a time, when downstream code tries to reinterpret these single bytes as strings (as padding.go does).
I found this by building glow at head. Let me know if glow properly shows UTF-8 sequences for you.
from reflow.
I believe you can build glow at head and see the broken UTF-8 sequences, which led me to try track this down to happening between the indent and padding pipes in glamor. If glow properly handles utf-8 for you at head, please let me know.
We can discuss here. One thing you should notice is all changes are not released yet.
from reflow.
in that case, another way to see this is to modify glamour's helloworld example to include a UTF-8 multi-character sequence.
from reflow.
If you convert a single byte of the a UTF-8 sequence to a string, go will mangle it.
I don't think this gonna happen. ansi.Writer
is just a wrapper which doesn't care about the original non-ansi bytes.
from reflow.
You can view the test case.
Btw it is best if there is code that can reproduce the 'bug'.
from reflow.
The problem is not ansi.Writer in isolation, but that this change now causes single bytes to be written instead of full UTF-8 runes. Downstream consumers like padding.go's Write method cast these single byte writes into strings, misinterpreting them.
You can just modify https://github.com/charmbracelet/glamour/blob/master/examples/helloworld/main.go to include a UTF-8 character sequence, which will reproduce the problem.
from reflow.
Once upgrade to master version, I saw the broken string. Will do some investigations.
Thanks for reporting!
from reflow.
Cheers! Was going to just say go get github.com/muesli/reflow@aa57fa9 first.
from reflow.
@zavislak Fixed by iterating in string. Wait @muesli to handle the PR.
Or you can get the latest commit from my repo.
Any feedbacks are welcome!
from reflow.
Related Issues (20)
- Truncate support
- Truncate does not work for blocks of text
- Add unconditional (non-word) wrapping
- Consistency with widths: int vs uint
- BytesWithTail and StringsWithTail should put tail between escape sequences HOT 1
- New release that contains truncate functionality HOT 1
- Issue with wrapping CP437 ANSI file
- Extra newlines when combining unconditional and standard word wrapping HOT 5
- v0.3.0 broke dedent package
- Hyperlinks consume space though the link isn't printed HOT 1
- Don't wrap at non breaking space.
- Working with tabs? HOT 1
- Coloring issue when used in association with lipgloss.JoinHorizontal HOT 1
- Middle string truncation
- wordwrap.String - like API which returns []string?
- wordwrap: Support for URL encoding of the space character (%20)?
- OSC sequences are mis-counted in `PrintableRuneWidth`
- Hyphens can cause wordwrap to exceed the limit
- Question: should wordwrap support a "hard wrap if needed" option?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reflow.