Documentation ¶
Overview ¶
Example (BoxOutput) ¶
package main import ( "fmt" "strings" ) // boxOutput formats its arguments as fmt.Printf, and encloses them in a box of // arrows pointing at their content, in order to better highlight it. See // ExampleBoxOutput func boxOutput(errorMsgTemplate string, errorMsgValues ...interface{}) string { errorMsgTemplate = fmt.Sprintf(errorMsgTemplate, errorMsgValues...) lines := strings.Split(errorMsgTemplate, "\n") maxlen := 0 for _, line := range lines { if len(line) > maxlen { maxlen = len(line) } } internalLength := maxlen + 4 output := "↘" + strings.Repeat("↓", internalLength) + "↙\n" output += "→ " + strings.Repeat(" ", maxlen) + " ←\n" readme := strings.Repeat("README ", maxlen/7) output += "→ " + readme + strings.Repeat(" ", maxlen-len(readme)) + " ←\n" output += "→ " + strings.Repeat(" ", maxlen) + " ←\n" for _, line := range lines { output += "→ " + line + strings.Repeat(" ", maxlen-len(line)) + " ←\n" } output += "→ " + strings.Repeat(" ", maxlen) + " ←\n" output += "→ " + readme + strings.Repeat(" ", maxlen-len(readme)) + " ←\n" output += "→ " + strings.Repeat(" ", maxlen) + " ←\n" return "\n" + output + "↗" + strings.Repeat("↑", internalLength) + "↖" + "\n\n" } func main() { fmt.Println() fmt.Print(boxOutput("%s is %d", "foo", 17)) }
Output: ↘↓↓↓↓↓↓↓↓↓↓↓↓↓↙ → ← → README ← → ← → foo is 17 ← → ← → README ← → ← ↗↑↑↑↑↑↑↑↑↑↑↑↑↑↖
Click to show internal directories.
Click to hide internal directories.