// Copyright 2014 Oleku Konko All rights reserved.// Use of this source code is governed by a MIT// license that can be found in the LICENSE file.// This module is a Table Writer API for the Go Programming Language.// The protocols were written in pure Go and works on windows and unix systemspackage tablewriterimport ()var ansi = regexp.MustCompile("\033\\[(?:[0-9]{1,3}(?:;[0-9]{1,3})*)?[m|K]")func ( string) int {returnrunewidth.StringWidth(ansi.ReplaceAllLiteralString(, ""))}// Simple Condition for string// Returns value based on conditionfunc ( bool, , string) string {if {return }return}func isNumOrSpace( rune) bool {return ('0' <= && <= '9') || == ' '}// Format Table Header// Replace _ , . and spacesfunc ( string) string { := len() := []rune()for , := range {switch {case'_': [] = ' 'case'.':// ignore floating number 0.0if ( != 0 && !isNumOrSpace([-1])) || ( != len()-1 && !isNumOrSpace([+1])) { [] = ' ' } } } = string() = strings.TrimSpace()iflen() == 0 && > 0 {// Keep at least one character. This is important to preserve // empty lines in multi-line headers/footers. = " " }returnstrings.ToUpper()}// Pad String// Attempts to place string in the centerfunc (, string, int) string { := - DisplayWidth()if > 0 { := int(math.Ceil(float64( / 2))) := - returnstrings.Repeat(string(), ) + + strings.Repeat(string(), ) }return}// Pad String Right position// This would place string at the left side of the screenfunc (, string, int) string { := - DisplayWidth()if > 0 {return + strings.Repeat(string(), ) }return}// Pad String Left position// This would place string at the right side of the screenfunc (, string, int) string { := - DisplayWidth()if > 0 {returnstrings.Repeat(string(), ) + }return}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.