Skip to content

Commit

Permalink
Fix broken TUI styling (#1023)
Browse files Browse the repository at this point in the history
lipgloss v0.11.0 made it so that all the `Style` methods no longer
mutate the style, which I was relying on.
  • Loading branch information
michaelkedar authored Jun 5, 2024
1 parent 21cdb29 commit 4e5c43a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions cmd/osv-scanner/fix/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,23 @@ func (m *model) setTermSize(w, h int) {
// resize the views to the calculated dimensions
m.mainViewWidth = viewWidth
m.mainViewHeight = viewHeight
m.mainViewStyle.Width(paddedWidth).Height(paddedHeight)
m.mainViewStyle = m.mainViewStyle.Width(paddedWidth).Height(paddedHeight)

m.infoViewWidth = viewWidth
m.infoViewHeight = viewHeight
m.infoViewStyle.Width(paddedWidth).Height(paddedHeight)
m.infoViewStyle = m.infoViewStyle.Width(paddedWidth).Height(paddedHeight)

m.st.Resize(m.mainViewWidth, m.mainViewHeight)
m.st.ResizeInfo(m.infoViewWidth, m.infoViewHeight)
}

func (m *model) getBorderStyles() (lipgloss.Style, lipgloss.Style) {
if m.st.IsInfoFocused() {
m.infoViewStyle.UnsetBorderForeground()
m.mainViewStyle.BorderForeground(tui.ColorDisabled)
m.infoViewStyle = m.infoViewStyle.UnsetBorderForeground()
m.mainViewStyle = m.mainViewStyle.BorderForeground(tui.ColorDisabled)
} else {
m.infoViewStyle.BorderForeground(tui.ColorDisabled)
m.mainViewStyle.UnsetBorderForeground()
m.infoViewStyle = m.infoViewStyle.BorderForeground(tui.ColorDisabled)
m.mainViewStyle = m.mainViewStyle.UnsetBorderForeground()
}

return m.mainViewStyle, m.infoViewStyle
Expand Down
4 changes: 2 additions & 2 deletions internal/tui/in-place-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func NewInPlaceInfo(res remediation.InPlaceResult) *inPlaceInfo {
}

st := table.DefaultStyles()
st.Header.Bold(false).BorderStyle(lipgloss.NormalBorder()).BorderBottom(true)
st.Selected.Foreground(ColorPrimary)
st.Header = st.Header.Bold(false).BorderStyle(lipgloss.NormalBorder()).BorderBottom(true)
st.Selected = st.Selected.Foreground(ColorPrimary)

info.Model = table.New(
table.WithColumns(cols),
Expand Down
4 changes: 2 additions & 2 deletions internal/tui/vuln-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (v *vulnList) preambleHeight() int {
func (v *vulnList) Resize(w, h int) {
v.SetWidth(w)
v.SetHeight(h - v.preambleHeight())
v.Styles.TitleBar.Width(w)
v.Styles.TitleBar = v.Styles.TitleBar.Width(w)
if v.currVulnInfo != nil {
v.currVulnInfo.Resize(w, h)
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func (d vulnListItemDelegate) Render(w io.Writer, m list.Model, index int, listI
idStyle := lipgloss.NewStyle().Width(d.idWidth).Align(lipgloss.Left)
if index == m.Index() {
cursor = SelectedTextStyle.Render(">")
idStyle.Inherit(SelectedTextStyle)
idStyle = idStyle.Inherit(SelectedTextStyle)
}
id := idStyle.Render(vuln.Vulnerability.ID)
severity := RenderSeverityShort(vuln.Vulnerability.Severity)
Expand Down

0 comments on commit 4e5c43a

Please sign in to comment.