Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(term): ansi: implement wrap and wordwrap #51

Merged
merged 2 commits into from
Mar 21, 2024
Merged

Conversation

aymanbagabas
Copy link
Member

This is based on @muesli's awesome
reflow library. It uses the ANSI parser state machine to find escape codes and runes. Since it uses the ANSI parser state machine, it supports OSC, DCS, and other sequences.

Related: muesli/reflow#71

Benchmarks running against reflow:

› go test -bench=. -benchmem -run=^$ ./ansi/...
goos: darwin
goarch: amd64
pkg: github.com/charmbracelet/x/exp/term/ansi
cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
BenchmarkWrap-16                19056892                66.83 ns/op          111 B/op          1 allocs/op
BenchmarkReflowWrap-16           9982068               122.7 ns/op           164 B/op          4 allocs/op
BenchmarkWordwrap-16             7652895               161.3 ns/op           287 B/op          4 allocs/op
BenchmarkReflowWordwrap-16       4818664               254.0 ns/op           287 B/op          4 allocs/op
PASS

@aymanbagabas aymanbagabas force-pushed the term/ansi_wrap branch 3 times, most recently from 133d340 to f4d575c Compare March 14, 2024 16:47
This is based on @muesli's awesome
[reflow](https://github.com/muesli/reflow) library. It uses the ANSI
parser state machine to find escape codes and runes. Since it uses the
ANSI parser state machine, it supports OSC, DCS, and other sequences.
exp/term/ansi/wrap.go Outdated Show resolved Hide resolved
exp/term/ansi/wrap.go Outdated Show resolved Hide resolved
exp/term/ansi/wrap.go Outdated Show resolved Hide resolved
exp/term/ansi/wrap.go Outdated Show resolved Hide resolved
exp/term/ansi/wrap.go Outdated Show resolved Hide resolved
@mikelorant
Copy link

Added some comments, I am fairly intermediate in my Go skills, so take them as observations. I may very well be wrong in my suggestions.

@aymanbagabas
Copy link
Member Author

Added some comments, I am fairly intermediate in my Go skills, so take them as observations. I may very well be wrong in my suggestions.

Thank you @mikelorant for reviewing this one!

@aymanbagabas aymanbagabas merged commit 7faadd0 into main Mar 21, 2024
8 checks passed
@aymanbagabas aymanbagabas deleted the term/ansi_wrap branch March 21, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants