mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-18 02:40:33 +02:00
Revert all commits since v0.223 to enable me to release a patch on top of v0.223
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
// Forked from https://github.com/charmbracelet/bubbles/blob/master/table/table.go to add horizontal scrolling
|
||||
// Also includes https://github.com/charmbracelet/bubbles/pull/397/files to support cell styling
|
||||
|
||||
package table
|
||||
|
||||
@@ -32,13 +31,6 @@ type Model struct {
|
||||
hcursor int
|
||||
}
|
||||
|
||||
// CellPosition holds row and column indexes.
|
||||
type CellPosition struct {
|
||||
RowID int
|
||||
Column int
|
||||
IsRowSelected bool
|
||||
}
|
||||
|
||||
// Row represents one line in the table.
|
||||
type Row []string
|
||||
|
||||
@@ -116,32 +108,6 @@ type Styles struct {
|
||||
Header lipgloss.Style
|
||||
Cell lipgloss.Style
|
||||
Selected lipgloss.Style
|
||||
|
||||
// RenderCell is a low-level primitive for stylizing cells.
|
||||
// It is responsible for rendering the selection style. Styles.Cell is ignored.
|
||||
//
|
||||
// Example implementation:
|
||||
// s.RenderCell = func(model table.Model, value string, position table.CellPosition) string {
|
||||
// cellStyle := s.Cell.Copy()
|
||||
//
|
||||
// switch {
|
||||
// case position.IsRowSelected:
|
||||
// return cellStyle.Background(lipgloss.Color("57")).Render(value)
|
||||
// case position.Column == 1:
|
||||
// return cellStyle.Foreground(lipgloss.Color("21")).Render(value)
|
||||
// default:
|
||||
// return cellStyle.Render(value)
|
||||
// }
|
||||
// }
|
||||
RenderCell func(model Model, value string, position CellPosition) string
|
||||
}
|
||||
|
||||
func (s Styles) renderCell(model Model, value string, position CellPosition) string {
|
||||
if s.RenderCell != nil {
|
||||
return s.RenderCell(model, value, position)
|
||||
}
|
||||
|
||||
return s.Cell.Render(value)
|
||||
}
|
||||
|
||||
// DefaultStyles returns a set of default style definitions for this table.
|
||||
@@ -479,30 +445,21 @@ func (m Model) headersView() string {
|
||||
}
|
||||
|
||||
func (m *Model) renderRow(rowID int) string {
|
||||
isRowSelected := rowID == m.cursor
|
||||
var s = make([]string, 0, len(m.cols))
|
||||
for i, value := range m.rows[rowID] {
|
||||
style := lipgloss.NewStyle().Width(m.cols[i].Width).MaxWidth(m.cols[i].Width).Inline(true)
|
||||
|
||||
position := CellPosition{
|
||||
RowID: rowID,
|
||||
Column: i,
|
||||
IsRowSelected: isRowSelected,
|
||||
}
|
||||
|
||||
var renderedCell string
|
||||
if i == m.ColIndex(m.hcol) && m.hcursor > 0 {
|
||||
renderedCell = style.Render(runewidth.Truncate(runewidth.TruncateLeft(value, m.hcursor, "…"), m.cols[i].Width, "…"))
|
||||
renderedCell = m.styles.Cell.Render(style.Render(runewidth.Truncate(runewidth.TruncateLeft(value, m.hcursor, "…"), m.cols[i].Width, "…")))
|
||||
} else {
|
||||
renderedCell = style.Render(runewidth.Truncate(value, m.cols[i].Width, "…"))
|
||||
renderedCell = m.styles.Cell.Render(style.Render(runewidth.Truncate(value, m.cols[i].Width, "…")))
|
||||
}
|
||||
renderedCell = m.styles.renderCell(*m, renderedCell, position)
|
||||
s = append(s, renderedCell)
|
||||
}
|
||||
|
||||
row := lipgloss.JoinHorizontal(lipgloss.Left, s...)
|
||||
|
||||
if isRowSelected {
|
||||
if rowID == m.cursor {
|
||||
return m.styles.Selected.Render(row)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user