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

Fix flaky tab writing behavior using text/tabwriter #25

Merged
merged 5 commits into from
Dec 16, 2024

Conversation

bschaatsbergen
Copy link
Contributor

@bschaatsbergen bschaatsbergen commented Dec 16, 2024

Alternative implementation to #19

Background

This prototype addresses the flaky tab writing issues caused by relying on a regular os.File writer along with our existing tab-based formatting. The output is now handled by a tabwriter.Writer from the text/tabwriter package, which integrates with the existing view/stream mechanism as it implements the io.Writer interface too. The tabwriter package acts as a write filter, translating tabbed input columns into proper aligned text for consistent and reliable formatting.

Debugging

In 1727fac, I added support for debugging the tab writer. When the debug flag is set, it prints a vertical bar ('|') between columns after formatting, and any discarded columns appear as zero-width columns ("||").

A      |example.com.   |37m46s      |93.184.215.14
NS     |example.com.   |21h17m02s   |a.iana-servers.net.
NS     |example.com.   |21h17m02s   |b.iana-servers.net.
SOA    |example.com.   |01h00m00s   |ns.icann.org. noc.dns.icann.org.
MX     |example.com.   |21h47m50s   |0 .
TXT    |example.com.   |21h25m07s   |v=spf1 -all
TXT    |example.com.   |21h25m07s   |wgyf8z8cgvm2qmxpnbnldrcltvk4xqfn
AAAA   |example.com.   |18m57s      |2606:2800:21f:cb07:6820:80da:af6b:8b2c

To be considered

FWIW, it might be worth considering moving the tab writer implementation down into the rendering logic, as this would make sure that consumers (e.g., tests) inherit all the behavior of the tab writer. On the other hand, the rendering logic is designed to support any writer, so this change might compromise that flexibility.

This fixes problems with tab writing caused by using a regular os.File writer. By standardizing the tab writer’s usage and ensuring consistent initialization, we improve the reliability and consistency of output formatting a lot.
In the past, we’ve faced too many issues with flaky tab formatting. If the `debug` flag is specified, we should enable debugging for the tabwriter as well, leveraging its built-in support for this.
@bschaatsbergen bschaatsbergen marked this pull request as ready for review December 16, 2024 20:42
@bschaatsbergen bschaatsbergen merged commit a6aa63e into main Dec 16, 2024
1 of 2 checks passed
@bschaatsbergen bschaatsbergen deleted the f/tabwriter branch December 16, 2024 20:43
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.

1 participant