I spend a lot of time automating things, both at the day job and in my personal life, and most of the time I’m writing for the command line. Even after decades of programming, there’s something about the elegance around the unix philosophy and piping that make me extremely happy.

This snippet will allow you to make your text output look much better on the screen.


# main.go
package main

import (

func main() {
	// Observe how the b's and the d's, despite appearing in the
	// second cell of each line, belong to different columns.
	w := tabwriter.NewWriter(os.Stdout, 5, 0, 5, ' ', tabwriter.Debug)
	fmt.Fprintln(w, "id\tname\tcomplete")

	fmt.Fprintln(w, "WC-123\tcosmic signature\tfalse")
	fmt.Fprintln(w, "TX-12\tcombat site\ttrue")
	fmt.Fprintln(w, "AL-0132\tcosmic signature\tfalse")


# output
% go run main.go
id          |name                 |complete
WC-123      |cosmic signature     |false
TX-12       |combat site          |true
AL-0132     |cosmic signature     |false

photo: Evelyn Clement on Unsplash