Skip to content

Commit

Permalink
feat: if path is longer than 0.4 of the bar, replace its parts with .…
Browse files Browse the repository at this point in the history
….. (#131)
  • Loading branch information
prgres committed Jun 4, 2024
1 parent f8f194d commit 3747c39
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
39 changes: 32 additions & 7 deletions ui/components/views-tabs/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,41 @@ func (m Model) View() string {
Width(m.size.Width - borderMargin).
MaxWidth(m.size.Width + borderMargin)

var s []string

moreTabsIcon := " + "
tabPrefix := " Views |"
prefix := " Views |"
suffix := ""

if m.Path != "" {
suffix += " | " + m.Path
suffixMaxWidth := int(float32(m.size.Width-borderMargin) * 0.4)
pathMaxWidth := suffixMaxWidth - lipgloss.Width(" "+"|"+" "+""+" ")
path := m.Path

if lipgloss.Width(m.Path) > pathMaxWidth {
pathParts := strings.Split(m.Path, "/")
for i := range pathParts {
if i == 0 {
pathParts[i] = ""
// the first elem is / so it has to be skipped
continue
}
if i == len(pathParts)-1 {
// the last elem has to be always visible
continue
}

pathParts[i] = "..."

if lipgloss.Width(strings.Join(pathParts, "/")) <= pathMaxWidth {
break
}
}
path = strings.Join(pathParts, "/")
}

suffix = " " + "|" + " " + path + " "
}

var s []string
for _, tab := range m.tabs {
t := ""
tabContent := " " + tab.Name + " "
Expand All @@ -123,7 +148,7 @@ func (m Model) View() string {

content := " " + t + " "

if lipgloss.Width(tabPrefix+strings.Join(s, "")+content+moreTabsIcon+suffix) >= m.size.Width-borderMargin {
if lipgloss.Width(prefix+strings.Join(s, "")+content+moreTabsIcon+suffix) >= m.size.Width-borderMargin {
s = append(s, moreTabsIcon)
break
}
Expand All @@ -132,14 +157,14 @@ func (m Model) View() string {
}
content := strings.Join(s, "")

dividerWidth := m.size.Width - borderMargin - lipgloss.Width(tabPrefix+content+moreTabsIcon+suffix)
dividerWidth := m.size.Width - borderMargin - lipgloss.Width(prefix+content+moreTabsIcon+suffix)
if dividerWidth < 0 {
dividerWidth = 0
}
divider := strings.Repeat(" ", dividerWidth)

return style.Render(
tabPrefix + content + divider + suffix,
prefix + content + divider + suffix,
)
}

Expand Down
2 changes: 1 addition & 1 deletion ui/widgets/navigator/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (m *Model) SetWorksapce(workspace clickup.Workspace) {
func (m Model) GetPath() string {
switch m.state {
case m.componentWorkspacesList.Id():
return "/"
return ""
case m.componentSpacesList.Id():
return "/" + m.componentWorkspacesList.Selected.Name
case m.componentFoldersList.Id():
Expand Down

0 comments on commit 3747c39

Please sign in to comment.