Skip to content

Commit

Permalink
fix(ui): preserve header line when no description is available
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Oct 23, 2023
1 parent 0f8dc11 commit 43b4331
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
53 changes: 28 additions & 25 deletions server/ui/pages/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,22 @@ func New(c common.Common, comps ...common.TabComponent) *Repo {
return r
}

// SetSize implements common.Component.
func (r *Repo) SetSize(width, height int) {
r.common.SetSize(width, height)
func (r *Repo) getMargins() (w, h int) {
hh := 1
if r.selectedRepo != nil && r.selectedRepo.Description() != "" {
hh++
}
hm := r.common.Styles.Repo.Body.GetVerticalFrameSize() +
r.common.Styles.Repo.Header.GetHeight() +
hh +
r.common.Styles.Repo.Header.GetVerticalFrameSize() +
r.common.Styles.StatusBar.GetHeight()
return 0, hm
}

// SetSize implements common.Component.
func (r *Repo) SetSize(width, height int) {
r.common.SetSize(width, height)
_, hm := r.getMargins()
r.tabs.SetSize(width, height-hm)
r.statusbar.SetSize(width, height-hm)
for _, p := range r.panes {
Expand Down Expand Up @@ -272,11 +281,8 @@ func (r *Repo) View() string {
Width(r.common.Width).
Height(r.common.Height)
repoBodyStyle := r.common.Styles.Repo.Body.Copy()
hm := repoBodyStyle.GetVerticalFrameSize() +
r.common.Styles.Repo.Header.GetHeight() +
r.common.Styles.Repo.Header.GetVerticalFrameSize() +
r.common.Styles.StatusBar.GetHeight() +
r.common.Styles.Tabs.GetHeight() +
_, hm := r.getMargins()
hm += r.common.Styles.Tabs.GetHeight() +
r.common.Styles.Tabs.GetVerticalFrameSize()
mainStyle := repoBodyStyle.
Height(r.common.Height - hm)
Expand Down Expand Up @@ -307,17 +313,17 @@ func (r *Repo) headerView() string {
return ""
}
truncate := lipgloss.NewStyle().MaxWidth(r.common.Width)
name := r.selectedRepo.ProjectName()
if name == "" {
name = r.selectedRepo.Name()
header := r.selectedRepo.ProjectName()
if header == "" {
header = r.selectedRepo.Name()
}
name = r.common.Styles.Repo.HeaderName.Render(name)
header = r.common.Styles.Repo.HeaderName.Render(header)
desc := strings.TrimSpace(r.selectedRepo.Description())
if desc == "" {
desc = name
name = ""
} else {
desc = r.common.Styles.Repo.HeaderDesc.Render(desc)
if desc != "" {
header = lipgloss.JoinVertical(lipgloss.Top,
header,
r.common.Styles.Repo.HeaderDesc.Render(desc),
)
}
urlStyle := r.common.Styles.URLStyle.Copy().
Width(r.common.Width - lipgloss.Width(desc) - 1).
Expand All @@ -331,15 +337,12 @@ func (r *Repo) headerView() string {
fmt.Sprintf("%s-url", r.selectedRepo.Name()),
urlStyle.Render(url),
)

header = lipgloss.JoinHorizontal(lipgloss.Left, header, url)

style := r.common.Styles.Repo.Header.Copy().Width(r.common.Width)
return style.Render(
lipgloss.JoinVertical(lipgloss.Top,
truncate.Render(name),
truncate.Render(lipgloss.JoinHorizontal(lipgloss.Left,
desc,
url,
)),
),
truncate.Render(header),
)
}

Expand Down
2 changes: 1 addition & 1 deletion server/ui/styles/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func DefaultStyles() *Styles {
Margin(1, 0)

s.Repo.Header = lipgloss.NewStyle().
Height(2).
MaxHeight(2).
Border(lipgloss.NormalBorder(), false, false, true, false).
BorderForeground(lipgloss.Color("236"))

Expand Down

0 comments on commit 43b4331

Please sign in to comment.