-
Notifications
You must be signed in to change notification settings - Fork 162
plugin(table): Add option to remove padding from tables #161
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
Open
datalogics-jacksonm
wants to merge
15
commits into
JohannesKaufmann:main
Choose a base branch
from
datalogics-jacksonm:minimum-required-characters-for-tables
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
150ea33
table: add `padColumns` option to tables
datalogics-jacksonm 3591da5
table renderer: add logic to account for `padColumns` option
datalogics-jacksonm e5681ff
cli: add `tablePadColumns` option to cli, default `true`
datalogics-jacksonm 9f8f225
cli: update stdout golden files with new cli option
datalogics-jacksonm 28eb6ae
padColumns: switch to using string option instead of bool
datalogics-jacksonm 9c072f3
cli: Update flag to mention "on" and "off" values in cli output
datalogics-jacksonm 6d21f28
render: switch to specific PadColumnsBehavior type for comparison
datalogics-jacksonm 13571ca
table_test: add tests for new table option
datalogics-jacksonm e2ea5d9
renderer: remove extra spaces if padding option is off
datalogics-jacksonm 5fd8cf8
table_test: update test to work with changed behavior
datalogics-jacksonm 1f84cf9
padColumns: add value `some` to options
datalogics-jacksonm fe23ef0
table_test: add test for the new `some` option
datalogics-jacksonm 9880166
table plugin: adjust naming convention for table padding option
datalogics-jacksonm 2c7d79f
testdata: update stdout golden files with new expected output
datalogics-jacksonm 0cfec2d
table_test: update table tests with new naming conventions
datalogics-jacksonm 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 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 |
---|---|---|
|
@@ -71,6 +71,39 @@ func WithNewlineBehavior(behavior NewlineBehavior) option { | |
} | ||
} | ||
|
||
type CellPaddingBehavior string | ||
|
||
const ( | ||
// CellPaddingAligned adds visual padding to cells to make each column equal width (default). | ||
CellPaddingAligned CellPaddingBehavior = "aligned" | ||
// CellPaddingMinimal keeps a very small amount of padding to balance table readability while also reducing character count. | ||
CellPaddingMinimal CellPaddingBehavior = "minimal" | ||
// CellPaddingNone refrains from adding the padding to the cells. | ||
CellPaddingNone CellPaddingBehavior = "none" | ||
) | ||
|
||
// WithPadColumns configures how to handle padding in table cells. | ||
// When set to "aligned" (default), every cell's text is padded to the width of the largest cell in its column. | ||
// When set to "minimal", every cell gets a space at the beginning and end of the cell for some minimal padding. | ||
// When set to "none", no extra padding is applied to cells. | ||
func WithCellPadding(behavior CellPaddingBehavior) option { | ||
return func(p *tablePlugin) error { | ||
switch behavior { | ||
case "": | ||
// Allow empty string to default to "aligned" | ||
p.cellPaddingBehavior = CellPaddingBehavior(CellPaddingAligned) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The wrapping with |
||
return nil | ||
|
||
case CellPaddingAligned, CellPaddingMinimal, CellPaddingNone: | ||
p.cellPaddingBehavior = behavior | ||
return nil | ||
|
||
default: | ||
return fmt.Errorf("unknown value %q for pad columns behavior", behavior) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update naming |
||
} | ||
} | ||
} | ||
|
||
// WithSkipEmptyRows configures the table plugin to omit empty rows from the output. | ||
// An empty row is defined as a row where all cells contain no content or only whitespace. | ||
// When set to true, empty rows will be omitted from the output. When false (default), | ||
|
@@ -113,6 +146,7 @@ type tablePlugin struct { | |
skipEmptyRows bool | ||
promoteFirstRowToHeader bool | ||
convertPresentationTables bool | ||
cellPaddingBehavior CellPaddingBehavior | ||
} | ||
|
||
func (p *tablePlugin) setError(err error) { | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to WithCellPadding