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

Cleanup and styling #35

Merged
merged 2 commits into from
May 15, 2023
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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/charmbracelet/bubbles v0.15.0
github.com/charmbracelet/bubbletea v0.23.2
github.com/charmbracelet/bubbletea v0.24.0
github.com/charmbracelet/lipgloss v0.7.1
github.com/cli/go-gh v1.2.1
github.com/cli/shurcooL-graphql v0.0.3
Expand All @@ -15,7 +15,7 @@ require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/cli/safeexec v1.0.1 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/henvic/httpretty v0.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
Expand All @@ -31,7 +31,7 @@ require (
github.com/rivo/uniseg v0.4.4 // indirect
github.com/sahilm/fuzzy v0.1.0 // indirect
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/charmbracelet/bubbles v0.15.0/go.mod h1:Y7gSFbBzlMpUDR/XM9MhZI374Q+1p
github.com/charmbracelet/bubbletea v0.23.1/go.mod h1:JAfGK/3/pPKHTnAS8JIE2u9f61BjWTQY57RbT25aMXU=
github.com/charmbracelet/bubbletea v0.23.2 h1:vuUJ9HJ7b/COy4I30e8xDVQ+VRDUEFykIjryPfgsdps=
github.com/charmbracelet/bubbletea v0.23.2/go.mod h1:FaP3WUivcTM0xOKNmhciz60M6I+weYLF76mr1JyI7sM=
github.com/charmbracelet/bubbletea v0.24.0 h1:l8PHrft/GIeikDPCUhQe53AJrDD8xGSn0Agirh8xbe8=
github.com/charmbracelet/bubbletea v0.24.0/go.mod h1:rK3g/2+T8vOSEkNHvtq40umJpeVYDn6bLaqbgzhL/hg=
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
github.com/charmbracelet/lipgloss v0.6.0/go.mod h1:tHh2wr34xcHjC2HCXIlGSG1jaDF0S0atAUvBMP6Ppuk=
github.com/charmbracelet/lipgloss v0.7.1 h1:17WMwi7N1b1rVWOjMT+rCh7sQkvDU75B2hbZpc5Kc1E=
Expand All @@ -22,6 +24,8 @@ github.com/cli/shurcooL-graphql v0.0.3 h1:CtpPxyGDs136/+ZeyAfUKYmcQBjDlq5aqnrDCW
github.com/cli/shurcooL-graphql v0.0.3/go.mod h1:tlrLmw/n5Q/+4qSvosT+9/W5zc8ZMjnJeYBxSdb4nWA=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -88,6 +92,8 @@ golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20220923203811-8be639271d50/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -104,6 +110,7 @@ golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
13 changes: 5 additions & 8 deletions models/orgModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func (m OrgModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyLeft:
m.repoModel.PreviousTab()
}
m.repoModel, cmd = m.repoModel.Update(msg)
} else {
switch msg.String() {
case tea.KeyEnter.String():
Expand All @@ -105,15 +106,10 @@ func (m OrgModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyUp.String(), tea.KeyDown.String(), tea.KeyLeft.String(), tea.KeyRight.String():
m.repoModel.SelectRepo(m.getSelectedRepo(), half(m.width), m.height)
}
m.repoList, cmd = m.repoList.Update(msg)
}
}

if m.tabsHaveFocus {
_, cmd = m.repoModel.Update(msg)
} else {
m.repoList, cmd = m.repoList.Update(msg)
}

return m, cmd
}

Expand Down Expand Up @@ -155,8 +151,9 @@ func buildRepoListModel(organizationQuery structs.OrganizationQuery, width, heig
items[i] = structs.NewListItem(repo.Node.Name, repo.Node.Url)
}

list := list.New(items, list.NewDefaultDelegate(), width, height-2)
list.Title = organizationQuery.Organization.Login
list := list.New(items, defaultDelegate, width, height-2)
list.Title = "Organization: " + organizationQuery.Organization.Login
list.Styles.Title = titleStyle
list.SetStatusBarItemName("Repository", "Repositories")
list.SetShowHelp(false)
list.SetShowTitle(true)
Expand Down
43 changes: 30 additions & 13 deletions models/repoModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,38 @@ func (m RepoModel) Init() tea.Cmd {

func (m *RepoModel) SelectRepo(RepositoryQuery structs.RepositoryQuery, width, height int) {
m.repoSettingsTabs = structs.BuildRepoSettings(RepositoryQuery)
m.settingsTable = NewSettingsTable(m.repoSettingsTabs[m.activeTab], width)

m.width = width
m.height = height
}

func (m *RepoModel) NextTab() {
m.activeTab = min(m.activeTab+1, len(m.repoSettingsTabs)-1)
m.settingsTable = NewSettingsTable(m.repoSettingsTabs[m.activeTab], m.width)
}

func (m *RepoModel) PreviousTab() {
m.activeTab = max(m.activeTab-1, 0)
m.settingsTable = NewSettingsTable(m.repoSettingsTabs[m.activeTab], m.width)
}

func (m RepoModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m RepoModel) Update(msg tea.Msg) (RepoModel, tea.Cmd) {
var cmd tea.Cmd

switch msg.(type) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
if !m.loaded {
m.loaded = true
}
return m, nil
case tea.KeyMsg:
switch msg.Type {
case tea.KeyDown:
m.settingsTable.MoveDown(1)
case tea.KeyUp:
m.settingsTable.MoveUp(1)
}
}

return m, cmd
Expand All @@ -73,29 +83,36 @@ func (m RepoModel) View() string {
}

settingsStyle := appStyle.Copy().Border(settingsBorder()).
BorderForeground(lipgloss.Color(pink)).Padding(0).Margin(0)

m.buildSettingsTable()
BorderForeground(pink).Padding(0).Margin(0)

var tabs = RenderTabs(m.repoSettingsTabs, m.width, m.activeTab)
var settings = settingsStyle.Padding(0).Width(m.width - 2).Height(m.height - 7).Render(m.settingsTable.View())
var settings = settingsStyle.Width(m.width - 2).Render(m.settingsTable.View())
// var settings = settingsStyle.Width(m.width - 2).Height(m.height - 7).Render(m.settingsTable.View())

return lipgloss.JoinVertical(lipgloss.Left, tabs, settings)
}

func (m *RepoModel) buildSettingsTable() {
activeSettings := m.repoSettingsTabs[m.activeTab]
widthWithoutBorder := m.width - 2
func NewSettingsTable(activeSettings structs.RepositorySettingsTab, width int) table.Model {
widthWithoutBorder := width - 2
quarterWidth := quarter(widthWithoutBorder)

columns := []table.Column{{Title: "", Width: (widthWithoutBorder - quarterWidth)}, {Title: "", Width: quarterWidth}}
columns := []table.Column{
{Title: "Setting", Width: (widthWithoutBorder - quarterWidth)},
{Title: "Value", Width: quarterWidth}}

rows := make([]table.Row, len(activeSettings.Settings))
for i, setting := range activeSettings.Settings {
rows[i] = table.Row{setting.Name, setting.Value}
}

m.settingsTable = table.New(
table.WithColumns(columns),
table.WithRows(rows))
return table.New(table.WithColumns(columns),
table.WithRows(rows), table.WithFocused(true), table.WithStyles(GetTableStyles()))
}

func GetTableStyles() table.Styles {
return table.Styles{
Selected: lipgloss.NewStyle().Bold(true).Foreground(blueDarker),
Header: lipgloss.NewStyle().Bold(true).Foreground(pinkDarker).Underline(true).Padding(0, 0, 1, 0),
Cell: lipgloss.NewStyle().Padding(0),
}
}
38 changes: 29 additions & 9 deletions models/styles.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
package models

import "github.com/charmbracelet/lipgloss"
import (
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/lipgloss"
)

var (
// Colors
// purple = "#cdb4db"
pink = "#ffc8dd"
// pinkDarker = "#ffafcc"
// blue = "#bde0fe"
blueDarker = "#a2d2ff"
white = "#FFFDF5"

appStyle = lipgloss.NewStyle().Padding(0, 0)
purple = lipgloss.Color("#cdb4db")
pink = lipgloss.Color("#ffc8dd")
pinkDarker = lipgloss.Color("#ffafcc")
blue = lipgloss.Color("#bde0fe")
blueDarker = lipgloss.Color("#a2d2ff")
// white = lipgloss.Color("#FFFDF5")

appStyle = lipgloss.NewStyle().Padding(0, 0).Foreground(purple).BorderForeground(blue)

titleStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color(blueDarker)).
Border(lipgloss.RoundedBorder(), true).
Padding(0, 1)

defaultDelegate = buildDefaultDelegate()
)

func buildDefaultDelegate() list.DefaultDelegate {
defaultDelegate := list.NewDefaultDelegate()
defaultDelegate.Styles.SelectedTitle.Foreground(blueDarker)
defaultDelegate.Styles.SelectedTitle.BorderForeground(blueDarker)
defaultDelegate.Styles.SelectedDesc.Foreground(blueDarker)
defaultDelegate.Styles.SelectedDesc.BorderForeground(blueDarker)

return defaultDelegate
}
15 changes: 11 additions & 4 deletions models/tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
func RenderTabs(tabSettings []structs.RepositorySettingsTab, width, activeTab int) string {
inactiveTabBorder := tabBorderWithBottom("┴", "─", "┴")
activeTabBorder := tabBorderWithBottom("┘", " ", "└")
borderColor := lipgloss.Color(pink)
inactiveTabStyle := lipgloss.NewStyle().Border(inactiveTabBorder, true).BorderForeground(borderColor).Padding(0)
inactiveTabStyle := lipgloss.NewStyle().Border(inactiveTabBorder, true).BorderForeground(pink).Padding(0)
activeTabStyle := inactiveTabStyle.Copy().Border(activeTabBorder, true)

tabs := []string{}
Expand Down Expand Up @@ -41,10 +40,18 @@ func RenderTabs(tabSettings []structs.RepositorySettingsTab, width, activeTab in
border.BottomRight = "┤"
}

style = style.Border(border)

if i == activeTab {
style = style.Foreground(blueDarker)
} else {
style = style.Foreground(pinkDarker)
}

if isLast {
style = style.Border(border).Width(tabWidth + (width % len(tabs)))
style = style.Width(tabWidth + (width % len(tabs)))
} else {
style = style.Border(border).Width(tabWidth)
style = style.Width(tabWidth)
}

renderedTabs = append(renderedTabs, style.Render(t))
Expand Down
15 changes: 4 additions & 11 deletions models/userModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)

type UserModel struct {
Expand Down Expand Up @@ -61,7 +60,7 @@ func (m UserModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil

case messages.OrgListMsg:
m.list = buildOrgListModel(msg.Organisations, m.width, m.height)
m.list = buildOrgListModel(msg.Organisations, m.width, m.height, m.User)
return m, nil

case tea.KeyMsg:
Expand Down Expand Up @@ -92,21 +91,15 @@ func (m UserModel) View() string {
return appStyle.Render(m.list.View())
}

func buildOrgListModel(organisations []structs.Organisation, width, height int) list.Model {

titleStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(white)).
Background(lipgloss.Color(blueDarker)).
Padding(0, 1)

func buildOrgListModel(organisations []structs.Organisation, width, height int, user structs.User) list.Model {
items := make([]list.Item, len(organisations))
for i, org := range organisations {
items[i] = structs.NewListItem(org.Login, org.Url)
}

list := list.New(items, list.NewDefaultDelegate(), width, height-2)
list := list.New(items, defaultDelegate, width, height-2)

list.Title = "Organisations"
list.Title = "User: " + user.Name
list.SetStatusBarItemName("Organisation", "Organisations")
list.Styles.Title = titleStyle
list.SetShowTitle(true)
Expand Down
2 changes: 1 addition & 1 deletion structs/yesNo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ func YesNo(b bool) string {
if b {
return "✔️"
}
return ""
return "✖️"
}
2 changes: 1 addition & 1 deletion structs/yesNo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestYesNo(t *testing.T) {
want string
}{
{"Yes", args{true}, "✔️"},
{"No", args{false}, ""},
{"No", args{false}, "✖️"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down