Skip to content

Commit

Permalink
chore: rollback changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nekrassov01 committed Feb 23, 2024
1 parent 9af87f6 commit cd18729
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
Binary file modified _assets/text_compressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 15 additions & 25 deletions mintab.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,40 +219,31 @@ func (t *Table) printHeader() {

// printData renders the table data with dynamic conditional borders.
func (t *Table) printData() {
var prev []string
for ri, row := range t.data {
lines := 1
splitedCells := make([][]string, len(row))
hasBorder := false
for fi, field := range row {
splitedCell := strings.Split(field, "\n")
splitedCells[fi] = splitedCell
if len(splitedCell) > lines {
lines = len(splitedCell)
}
if ri == 0 {
continue
}
if t.format == FormatCompressedText {
if field != "" && (len(prev) <= fi || prev[fi] == "") || (row[0] != "") {
hasBorder = true
}
}
if ri > 0 {
if t.format == FormatText {
hasBorder = true
t.printDataBorder(row)
}
if t.format == FormatCompressedText && row[0] != "" {
t.printBorder()
}
}
if hasBorder {
t.printDataBorder(row)
lines := 1
splitFields := make([][]string, len(row))
for fi, field := range row {
splitFields[fi] = strings.Split(field, "\n")
if len(splitFields[fi]) > lines {
lines = len(splitFields[fi])
}
}
for line := 0; line < lines; line++ {
t.builder.Reset()
t.builder.WriteString("|")
for sfi, splitedCell := range splitedCells {
for sfi, splitField := range splitFields {
margin := t.getMargin()
t.builder.WriteString(margin)
if line < len(splitedCell) {
t.builder.WriteString(pad(splitedCell[line], t.columnWidths[sfi]))
if line < len(splitField) {
t.builder.WriteString(pad(splitField[line], t.columnWidths[sfi]))
} else {
t.builder.WriteString(pad("", t.columnWidths[sfi]))
}
Expand All @@ -261,7 +252,6 @@ func (t *Table) printData() {
}
fmt.Fprintln(t.writer, t.builder.String())
}
prev = row
}
}

Expand Down
2 changes: 0 additions & 2 deletions mintab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ func TestTable_Out(t *testing.T) {
+------------+--------------+-------+-----------------+---------------+------------+----------+--------+---------------+---------------+
| i-1 | server-1 | vpc-1 | sg-1 | Ingress | tcp | 22 | 22 | SecurityGroup | sg-10 |
| | | | | Egress | -1 | 0 | 0 | Ipv4 | 0.0.0.0/0 |
+ + + +-----------------+---------------+------------+----------+--------+---------------+---------------+
| | | | sg-2 | Ingress | tcp | 443 | 443 | Ipv4 | 0.0.0.0/0 |
| | | | | Egress | -1 | 0 | 0 | Ipv4 | 0.0.0.0/0 |
+------------+--------------+-------+-----------------+---------------+------------+----------+--------+---------------+---------------+
Expand Down Expand Up @@ -695,7 +694,6 @@ func TestTable_printData(t *testing.T) {
},
want: `| i-1 | server-1 | vpc-1 | sg-1 | Ingress | tcp | 22 | 22 | SecurityGroup | sg-10 |
| | | | | Egress | -1 | 0 | 0 | Ipv4 | 0.0.0.0/0 |
+ + + +-----------------+---------------+------------+----------+--------+---------------+---------------+
| | | | sg-2 | Ingress | tcp | 443 | 443 | Ipv4 | 0.0.0.0/0 |
| | | | | Egress | -1 | 0 | 0 | Ipv4 | 0.0.0.0/0 |
+------------+--------------+-------+-----------------+---------------+------------+----------+--------+---------------+---------------+
Expand Down

0 comments on commit cd18729

Please sign in to comment.