-
Notifications
You must be signed in to change notification settings - Fork 1
Truncate long columns instead of line wrapping #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9c8acb6
avoid line wrapping tables
sjmiller609 4bb36d5
Avoid truncating shorter columns
sjmiller609 01b7e20
Add status and last checked to kernel proxies get
sjmiller609 3e77152
Clean up table function
sjmiller609 d911c65
Alias apps
sjmiller609 ee81c6b
Fix padding
sjmiller609 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,113 +1,11 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "strings" | ||
| "unicode/utf8" | ||
|
|
||
| "github.com/onkernel/cli/pkg/table" | ||
| "github.com/pterm/pterm" | ||
| ) | ||
|
|
||
| // printTableNoPad renders a table similar to pterm.DefaultTable, but it avoids | ||
| // adding trailing padding spaces after the last column and does not add blank | ||
| // padded lines to match multi-line cells in other columns. The last column may | ||
| // contain multi-line content which will be printed as-is on following lines. | ||
| func printTableNoPad(data pterm.TableData, hasHeader bool) { | ||
| if len(data) == 0 { | ||
| return | ||
| } | ||
|
|
||
| // Determine number of columns from the first row | ||
| numCols := len(data[0]) | ||
| if numCols == 0 { | ||
| return | ||
| } | ||
|
|
||
| // Pre-compute max width per column for all but the last column | ||
| maxColWidths := make([]int, numCols) | ||
| for _, row := range data { | ||
| for colIdx := 0; colIdx < numCols && colIdx < len(row); colIdx++ { | ||
| if colIdx == numCols-1 { | ||
| continue | ||
| } | ||
| for _, line := range strings.Split(row[colIdx], "\n") { | ||
| if w := utf8.RuneCountInString(line); w > maxColWidths[colIdx] { | ||
| maxColWidths[colIdx] = w | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| var b strings.Builder | ||
| sep := pterm.DefaultTable.Separator | ||
| sepStyled := pterm.ThemeDefault.TableSeparatorStyle.Sprint(sep) | ||
|
|
||
| renderRow := func(row []string, styleHeader bool) { | ||
| // Build first-line-only for non-last columns; last column is full string | ||
| firstLineParts := make([]string, 0, numCols) | ||
| for colIdx := 0; colIdx < numCols; colIdx++ { | ||
| var cell string | ||
| if colIdx < len(row) { | ||
| cell = row[colIdx] | ||
| } | ||
|
|
||
| if colIdx < numCols-1 { | ||
| // Only the first line for non-last columns | ||
| lines := strings.Split(cell, "\n") | ||
| first := "" | ||
| if len(lines) > 0 { | ||
| first = lines[0] | ||
| } | ||
| padCount := maxColWidths[colIdx] - utf8.RuneCountInString(first) | ||
| if padCount < 0 { | ||
| padCount = 0 | ||
| } | ||
| firstLineParts = append(firstLineParts, first+strings.Repeat(" ", padCount)) | ||
| } else { | ||
| // Last column: render the first line now; remaining lines after | ||
| lines := strings.Split(cell, "\n") | ||
| if len(lines) > 0 { | ||
| firstLineParts = append(firstLineParts, lines[0]) | ||
| } else { | ||
| firstLineParts = append(firstLineParts, "") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| line := strings.Join(firstLineParts[:numCols-1], sepStyled) | ||
| if numCols > 1 { | ||
| if line != "" { | ||
| line += sepStyled | ||
| } | ||
| line += firstLineParts[numCols-1] | ||
| } | ||
|
|
||
| if styleHeader { | ||
| b.WriteString(pterm.ThemeDefault.TableHeaderStyle.Sprint(line)) | ||
| } else { | ||
| b.WriteString(line) | ||
| } | ||
| b.WriteString("\n") | ||
|
|
||
| // Print remaining lines from the last column without alignment padding | ||
| if numCols > 0 { | ||
| var lastCell string | ||
| if len(row) >= numCols { | ||
| lastCell = row[numCols-1] | ||
| } | ||
| lines := strings.Split(lastCell, "\n") | ||
| if len(lines) > 1 { | ||
| rest := strings.Join(lines[1:], "\n") | ||
| if rest != "" { | ||
| b.WriteString(rest) | ||
| b.WriteString("\n") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for idx, row := range data { | ||
| renderRow(row, hasHeader && idx == 0) | ||
| } | ||
|
|
||
| pterm.Print(b.String()) | ||
| // PrintTableNoPad is a wrapper around pkg/table.PrintTableNoPad for backwards compatibility | ||
| func PrintTableNoPad(data pterm.TableData, hasHeader bool) { | ||
| table.PrintTableNoPad(data, hasHeader) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.