All contributions

olekukonko/tablewriter

tablewriter

A Go library for drawing text tables in the terminal. It measures the width of text in each column itself, tabs included.

Language
Go
GitHub stars
4,824
Merged changes
1

What we changed

Changing the tab width with SetTabWidth now purges the width cache, so text with tabs gets its correct width again.

What this work shows

  • Cache invalidation
  • Mutex synchronisation in Go
  • Terminal text width
What was broken

A new tab width changed nothing

The width cache key did not include the tab width. After SetTabWidth, Width returned stale results for text containing tabs.

How we fixed it

SetTabWidth purges the cache

SetTabWidth now purges the cache under the mutex, just as SetForceNarrow does. A new test sets the tab width to 2, 4 and 6 and compares Width with WidthNoCache each time.

#338

Merged change 1

  1. #338 twwidth: purge width cache in SetTabWidth Merged 11 October 2026

What it taught us

We find cache bugs where the key leaves out a setting the result depends on, and fix them the way the rest of the code already does. The test compares the cached result with the uncached one, so it catches any mismatch.

More about this technology: Golang

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.