-
Notifications
You must be signed in to change notification settings - Fork 122
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
Allow row painting by index #345
Conversation
Will fix tests before re-opening |
Please retry analysis of this Pull-Request directly on SonarQube Cloud |
Pull Request Test Coverage Report for Build 12203343058Details
💛 - Coveralls |
Quality Gate passedIssues Measures |
func (t *Table) SortedIndices() []int { | ||
return t.sortedRowIndices | ||
} | ||
|
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.
This should not be done as the value will not be available until something gets rendered. And another render might wipe it out as well.
// text.Colors{} to use on the entire row | ||
type RowPainter func(row Row) text.Colors | ||
|
||
// IndexedRowPainter is a custom function that takes a Row index as input and returns the | ||
// text.Colors{} to use on the entire row | ||
type IndexedRowPainter func(idx int) text.Colors | ||
|
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.
I want to work on a generic RowPainter which does both this and more instead of introducing multiple variants like this. Give me a day please.
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.
Sure. I implemented as a separate variant so as to not introduce a breaking change. If you don't have time, I can implement a generic version.
@charliedrewitt I've changed tw.SetRowPainter(func(row Row, attr RowAttributes) text.Colors {
if attr.NumberSorted == 1 {
return text.Colors{text.Bold, text.BgHiCyan, text.FgBlack}
} else if salary, ok := row[3].(int); ok {
if salary > 3000 {
return text.Colors{text.BgYellow, text.FgBlack}
} else if salary < 2000 {
return text.Colors{text.BgRed, text.FgBlack}
}
}
return text.Colors{}
}) Can you try the code in branch |
@jedib0t the version in Any reason why you chose to use 1-indexed slices? |
I don't, but the "Number" terminology works better with 1-index. If I'd named it |
Hey @charliedrewitt cut a tag for your use: https://github.com/jedib0t/go-pretty/releases/tag/v6.6.4 |
Proposed Changes
Background
I am using this project to build a cli, one of the operations involves selecting a value from the table using arrow keys. Allowing painting of the rows by index makes this far easier, especially when sorting is involved.