github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/cmdutil/output.go (about) 1 // Copyright 2018 GRAIL, Inc. All rights reserved. 2 // Use of this source code is governed by the Apache-2.0 3 // license that can be found in the LICENSE file. 4 5 package cmdutil 6 7 import ( 8 "fmt" 9 "io" 10 11 "v.io/x/lib/textutil" 12 ) 13 14 // WriteWrappedMessage writes the message to the specified io.Writer taking 15 // care to line wrap it appropriately for the terminal width. 16 func WriteWrappedMessage(w io.Writer, m string) { 17 _, cols, err := textutil.TerminalSize() 18 if err != nil { 19 fmt.Fprintf(w, "%s", m) 20 return 21 } 22 wrapped := textutil.NewUTF8WrapWriter(w, cols) 23 fmt.Fprintf(wrapped, "%s", m) 24 wrapped.Flush() 25 }