Skip to content
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

feat: add current path indicator #97

Merged
merged 8 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/spf13/pflag v1.0.5
golang.design/x/clipboard v0.7.0
golang.org/x/term v0.18.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand All @@ -19,9 +20,7 @@ require (
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/microcosm-cc/bluemonday v1.0.21 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml v1.9.3 // indirect
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect
github.com/yuin/goldmark v1.5.2 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
Expand All @@ -30,7 +29,6 @@ require (
golang.org/x/image v0.14.0 // indirect
golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a // indirect
golang.org/x/net v0.23.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
Expand All @@ -39,7 +37,6 @@ require (
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/evertras/bubble-table v0.15.5
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/kkyr/fig v0.3.2
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
github.com/kkyr/fig v0.3.2 h1:+vMj52FL6RJUxeKOBB6JXIMyyi1/2j1ERDrZXjoBjzM=
github.com/kkyr/fig v0.3.2/go.mod h1:ItUILF8IIzgZOMhx5xpJ1W/bviQsWRKOwKXfE/tqUoA=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
Expand All @@ -48,8 +46,6 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/microcosm-cc/bluemonday v1.0.21 h1:dNH3e4PSyE4vNX+KlRGHT5KrSvjeUkoNPwEORjffHJg=
github.com/microcosm-cc/bluemonday v1.0.21/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM=
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
Expand All @@ -61,8 +57,6 @@ github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
Expand Down
137 changes: 34 additions & 103 deletions ui/components/views-tabs/viewstabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ type Tab struct {
}

type Model struct {
ctx *context.UserContext
log *log.Logger
SelectedTab string
keyMap KeyMap
tabs []Tab
size common.Size
Focused bool
Hidden bool
ifBorders bool

ctx *context.UserContext
log *log.Logger
SelectedTab string
keyMap KeyMap
tabs []Tab
size common.Size
Focused bool
Hidden bool
ifBorders bool
Path string
StartIdx int
EndIdx int
SelectedTabIdx int
Expand Down Expand Up @@ -64,12 +64,12 @@ func InitialModel(ctx *context.UserContext, logger *log.Logger) Model {
log := logger.WithPrefix(logger.GetPrefix() + "/" + WidgetId)

return Model{
ctx: ctx,
tabs: []Tab{},
log: log,
keyMap: DefaultKeyMap(),
ifBorders: true,

ctx: ctx,
tabs: []Tab{},
log: log,
keyMap: DefaultKeyMap(),
ifBorders: true,
Path: "",
StartIdx: 0,
EndIdx: 0,
SelectedTabIdx: 0,
Expand Down Expand Up @@ -145,116 +145,47 @@ func (m Model) View() string {
MaxWidth(m.size.Width + borderMargin)

var s []string

moreTabsIcon := " + "
tabPrefix := " Views |"
// s = append(s, " Views |")
suffix := ""

if len(m.tabs) == 0 {
s = append(s, " ")
return style.Render(
tabPrefix + strings.Join(s, ""),
)
if m.Path != "" {
suffix += " | " + m.Path
}
m.log.Debugf("Rendering %d tabs", len(m.tabs))

moreTabsIcon := " + "

// selectedTabVisible := false
for _, tab := range m.tabs {
// for i, tab := range m.tabs {
m.log.Debugf("Rendering tab: %s %s", tab.Name, tab.Id)
// m.EndIdx = i

t := ""
tabContent := " " + tab.Name + " "

style := inactiveTabStyle
if m.SelectedTab == tab.Id {
t = activeTabStyle.Render(tabContent)
// selectedTabVisible = true
} else {
t = inactiveTabStyle.Render(tabContent)
style = activeTabStyle
}
t = style.Render(tabContent)

content := " " + t + " "

if lipgloss.Width(tabPrefix+strings.Join(s, "")+content+moreTabsIcon) >= m.size.Width-borderMargin {
// if selectedTabVisible {
if lipgloss.Width(tabPrefix+strings.Join(s, "")+content+moreTabsIcon+suffix) >= m.size.Width-borderMargin {
s = append(s, moreTabsIcon)
break
// }
// s = s[4:]
}
s = append(s, content)

// if i != len(m.tabs)-1 {
s = append(s, "|")
// }
}
content := strings.Join(s, "")

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

return style.Render(
tabPrefix + strings.Join(s, ""),
tabPrefix + content + divider + suffix,
)
}

// func (m Model) View() string {
// bColor := lipgloss.Color("#FFF")
// if m.Focused {
// bColor = lipgloss.Color("#8909FF")
// }
//
// borderMargin := 0
// if m.ifBorders {
// borderMargin = 2
// }
//
// style := lipgloss.NewStyle().
// BorderStyle(lipgloss.RoundedBorder()).
// BorderForeground(bColor).
// BorderBottom(m.ifBorders).
// BorderRight(m.ifBorders).
// BorderTop(m.ifBorders).
// BorderLeft(m.ifBorders).
// Height(1).
// MaxHeight(1 + borderMargin).
// Width(m.size.Width - borderMargin).
// MaxWidth(m.size.Width + borderMargin)
//
// s := new(strings.Builder)
// s.WriteString(" Views |")
//
// if len(m.tabs) == 0 {
// s.WriteString(" ")
// return style.Render(s.String())
// }
// m.log.Debugf("Rendering %d tabs", len(m.tabs))
//
// moreTabsIcon := " + "
// for i, tab := range m.tabs {
// m.log.Debugf("Rendering tab: %s %s", tab.Name, tab.Id)
// // m.EndIdx = i
//
// t := ""
// tabContent := " " + tab.Name + " "
// if m.SelectedTab == tab.Id {
// t = activeTabStyle.Render(tabContent)
// } else {
// t = inactiveTabStyle.Render(tabContent)
// }
//
// content := " " + t + " "
//
// if lipgloss.Width(s.String()+content+moreTabsIcon) >= m.size.Width-borderMargin {
// s.WriteString(moreTabsIcon)
// break
// }
// s.WriteString(content)
//
// if i != len(m.tabs)-1 {
// s.WriteString("|")
// }
// }
//
// return style.Render(s.String())
// }

func (m Model) Init() tea.Cmd {
m.log.Info("Initializing...")
return nil
Expand Down
24 changes: 0 additions & 24 deletions ui/components/workspaces-list/workspaceslist.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
m.SelectedWorkspace = selectedWorkspace
return m, common.WorkspacePreviewCmd(selectedWorkspace.Id)
}

// switch {
// case key.Matches(msg, m.list.KeyMap.CursorDown):
// m.list.CursorUp()
// return m, nil
// }
}

m.list, cmd = m.list.Update(msg)
Expand All @@ -137,28 +131,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
return m, tea.Batch(cmds...)
}

// func (m Model) View() string {
func (m Model) View() string {
return m.list.View()
}

// bColor := lipgloss.Color("#FFF")
// if m.Focused {
// bColor = lipgloss.Color("#8909FF")
// }
//
// return lipgloss.NewStyle().
// BorderStyle(lipgloss.RoundedBorder()).
// BorderForeground(bColor).
// BorderBottom(m.ifBorders).
// BorderRight(m.ifBorders).
// BorderTop(m.ifBorders).
// BorderLeft(m.ifBorders).
// Render(
// m.list.View(),
// )
// }

func (m Model) Init() tea.Cmd {
m.log.Infof("Initializing...")
return nil
Expand Down
6 changes: 5 additions & 1 deletion ui/views/compact/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func (m Model) Update(msg tea.Msg) (common.View, tea.Cmd) {
var cmd tea.Cmd
var cmds []tea.Cmd

m.widgetViewsTabs.Path = m.widgetNavigator.GetPath()

switch msg := msg.(type) {
case tea.KeyMsg:
switch keypress := msg.String(); keypress {
Expand Down Expand Up @@ -107,6 +109,8 @@ func (m Model) Update(msg tea.Msg) (common.View, tea.Cmd) {
m.widgetTasks, cmd = m.widgetTasks.Update(msg)
}

m.widgetViewsTabs.Path = m.widgetNavigator.GetPath()

cmds = append(cmds, cmd)
return m, tea.Batch(cmds...)

Expand Down Expand Up @@ -144,7 +148,6 @@ func (m Model) Update(msg tea.Msg) (common.View, tea.Cmd) {
}

case spinner.TickMsg:
// m.log.Info("Received: spinner.TickMsg")
if m.showSpinner {
m.spinner, cmd = m.spinner.Update(msg)
cmds = append(cmds, cmd)
Expand Down Expand Up @@ -225,6 +228,7 @@ func (m Model) Update(msg tea.Msg) (common.View, tea.Cmd) {
m.widgetTasks = m.widgetTasks.SetFocused(false)
m.widgetViewsTabs = m.widgetViewsTabs.SetFocused(false)
m.widgetNavigator = m.widgetNavigator.SetFocused(true)
m.widgetViewsTabs.Path = m.widgetNavigator.GetPath()
}

m.widgetNavigator, cmd = m.widgetNavigator.Update(msg)
Expand Down
22 changes: 18 additions & 4 deletions ui/widgets/navigator/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ func (m *Model) SetWorksapce(workspace clickup.Workspace) {
m.componentWorkspacesList.SelectedWorkspace = workspace
}

func (m Model) GetPath() string {
switch m.state {
case workspaceslist.ComponentId:
return "/"
case spaceslist.ComponentId:
return "/" + m.componentWorkspacesList.SelectedWorkspace.Name
case folderslist.ComponentId:
return "/" + m.componentWorkspacesList.SelectedWorkspace.Name + "/" + m.componentSpacesList.SelectedSpace.Name
case listslist.ComponentId:
if m.Focused {
return "/" + m.componentWorkspacesList.SelectedWorkspace.Name + "/" + m.componentSpacesList.SelectedSpace.Name + "/" + m.componentFoldersList.SelectedFolder.Name
}
return "/" + m.componentWorkspacesList.SelectedWorkspace.Name + "/" + m.componentSpacesList.SelectedSpace.Name + "/" + m.componentFoldersList.SelectedFolder.Name + "/" + m.componentListsList.SelectedList.Name
default:
return ""
}
}

func InitialModel(ctx *context.UserContext, logger *log.Logger) Model {
s := spinner.New()
s.Spinner = spinner.Pulse
Expand Down Expand Up @@ -109,16 +127,12 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
m.log.Info("Received: Go to previous view")

switch m.state {
// case workspaceslist.ComponentId:
case spaceslist.ComponentId:
m.state = workspaceslist.ComponentId
// cmd = common.WorkspaceChangeCmd(m.componentWorkspacesList.SelectedWorkspace)
case folderslist.ComponentId:
m.state = spaceslist.ComponentId
// cmd = common.SpaceChangeCmd(m.componentSpacesList.SelectedSpace)
case listslist.ComponentId:
m.state = folderslist.ComponentId
// cmd = common.FolderChangeCmd(m.componentFoldersList.SelectedFolder)
}

cmds = append(cmds, cmd)
Expand Down
Loading