Bug/153 text table long lines (#154)

* text table: fixed long lines padding

* text table: fixed long lines padding
This commit is contained in:
Neil O'Toole 2023-03-19 01:51:05 -06:00 committed by GitHub
parent 35f11b32c1
commit db189e55a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 5 deletions

View File

@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v0.25.1] - 2023-03-19
### Fixed
- [#153]: Improved formatting of text table with long lines.
## [v0.25.0] - 2023-03-19
### Added
@ -188,6 +195,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[v0.15.3]: https://github.com/neilotoole/sq/compare/v0.15.2...v0.15.3
[v0.15.2]: https://github.com/neilotoole/sq/releases/tag/v0.15.2
[#153]: https://github.com/neilotoole/sq/issues/153
[#151]: https://github.com/neilotoole/sq/issues/151
[#144]: https://github.com/neilotoole/sq/issues/144
[#142]: https://github.com/neilotoole/sq/issues/142

View File

@ -9,10 +9,12 @@
package internal
import (
"bytes"
"fmt"
"io"
"regexp"
"strings"
"unicode"
)
// MaxRowWidth defines maximum row width
@ -326,9 +328,12 @@ func (t *Table) printHeading() {
return
}
buf := &bytes.Buffer{}
// Check if border is set
// Replace with space if not set
fmt.Fprint(t.out, ConditionString(t.borders.Left, t.pColumn, Empty))
fmt.Fprint(buf, ConditionString(t.borders.Left, t.pColumn, Empty))
fmt.Fprint(t.out, strings.TrimRightFunc(buf.String(), unicode.IsSpace))
// Identify last column
end := len(t.cs) - 1
@ -345,7 +350,14 @@ func (t *Table) printHeading() {
}
pad := ConditionString(i == end && !t.borders.Left, Space, t.pColumn)
head := t.headerTrans(fmt.Sprintf("%s %s ", padFunc(h, Space, v), pad))
var head string
if i == end {
// Trim the padding from the final column
// head = strings.TrimRightFunc(head, unicode.IsPunct)
head = t.headerTrans(h)
} else {
head = t.headerTrans(fmt.Sprintf("%s %s ", padFunc(h, Space, v), pad))
}
fmt.Fprint(t.out, head)
}
@ -487,8 +499,11 @@ func (t *Table) printRow(columns [][]string, colKey int) {
cellContent := text
if y != total-1 {
cellContent = PadRight(text, Space, t.cs[y])
fmt.Fprintf(t.out, tran("%s "), cellContent)
} else {
fmt.Fprintf(t.out, tran(strings.TrimRightFunc(cellContent, unicode.IsSpace)))
}
fmt.Fprintf(t.out, tran("%s "), cellContent)
default:
if decimal.MatchString(strings.TrimSpace(text)) || percent.MatchString(strings.TrimSpace(text)) {
fmt.Fprintf(t.out, "%s", PadLeft(text, Space, t.cs[y]))
@ -496,11 +511,10 @@ func (t *Table) printRow(columns [][]string, colKey int) {
fmt.Fprintf(t.out, "%s", PadRight(text, Space, t.cs[y]))
}
}
fmt.Fprint(t.out, Space)
}
// Check if border is set
// Replace with space if not set
fmt.Fprint(t.out, ConditionString(t.borders.Left, t.pColumn, Space))
// fmt.Fprint(t.out, ConditionString(t.borders.Left, t.pColumn, Space))
fmt.Fprintln(t.out)
}