diff --git a/go.mod b/go.mod index 0d447ae..e1e9fdc 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,6 @@ require ( github.com/charmbracelet/bubbletea v0.27.1 github.com/charmbracelet/lipgloss v0.13.0 github.com/charmbracelet/log v0.4.0 - github.com/evertras/bubble-table v0.16.1 go.etcd.io/bbolt v1.3.11 golang.org/x/mod v0.20.0 golang.org/x/term v0.23.0 @@ -22,7 +21,6 @@ require ( require ( github.com/andybalholm/cascadia v1.3.2 // indirect - github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/charmbracelet/x/ansi v0.2.3 // indirect github.com/charmbracelet/x/term v0.2.0 // indirect @@ -34,7 +32,6 @@ require ( github.com/mattn/go-runewidth v0.0.16 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect - github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.15.2 // indirect github.com/rivo/uniseg v0.4.7 // indirect golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 // indirect diff --git a/go.sum b/go.sum index 99bf152..a00f907 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,6 @@ github.com/PuerkitoBio/goquery v1.9.2 h1:4/wZksC3KgkQw7SQgkKotmKljk0M6V8TUvA8Wb4 github.com/PuerkitoBio/goquery v1.9.2/go.mod h1:GHPCaP0ODyyxqcNoFGYlAprUFH81NuRPd0GX3Zu2Mvk= github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss= github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU= -github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= -github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/charmbracelet/bubbles v0.19.0 h1:gKZkKXPP6GlDk6EcfujDK19PCQqRjaJZQ7QRERx1UF0= @@ -22,8 +20,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= -github.com/evertras/bubble-table v0.16.1 h1:RKkOD+6LUoA3SifWceTSE7zchKyhBZy0f4B/K1/XN0o= -github.com/evertras/bubble-table v0.16.1/go.mod h1:SPOZKbIpyYWPHBNki3fyNpiPBQkvkULAtOT7NTD5fKY= github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= @@ -32,20 +28,16 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= -github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= -github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= -github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= 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= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= diff --git a/internal/resources/UserView.go b/internal/resources/UserView.go index 03e9767..a2239d8 100644 --- a/internal/resources/UserView.go +++ b/internal/resources/UserView.go @@ -2,14 +2,15 @@ package resources import ( "fmt" + "strconv" "dalton.dog/aocgo/internal/styles" "dalton.dog/aocgo/internal/utils" "github.com/charmbracelet/bubbles/spinner" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/lipgloss/table" "github.com/charmbracelet/log" - "github.com/evertras/bubble-table/table" ) // Message to indicate a puzzle has finished loading @@ -21,7 +22,7 @@ type loadDoneMsg struct { // Message to indicate that the user table is ready to display type tableDoneMsg struct { - table table.Model + table table.Table } // LoadUserModel is the BubbleTea model for loading and displaying @@ -33,7 +34,7 @@ type LoadUserModel struct { curDate int finished bool - table table.Model + table table.Table spinner spinner.Model status string } @@ -107,7 +108,7 @@ func (m LoadUserModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m LoadUserModel) View() string { if m.finished { - sOut := fmt.Sprintf("%v\n%v\n%v\n", header(m.user.DisplayName), m.table.View(), footer()) + sOut := fmt.Sprintf("%v\n%v\n%v\n", styles.NormalTextStyle.Render(header(m.user.DisplayName)), m.table.Render(), styles.NormalTextStyle.Render(footer())) return styles.GlobalSpacingStyle.Render(sOut) } else { return styles.GlobalSpacingStyle.Render(m.spinner.View() + " " + m.status) @@ -134,61 +135,37 @@ func loadPuzzle(year, day int, userToken string) tea.Cmd { func generateTable(userToken string) tea.Cmd { return func() tea.Msg { - var rows []table.Row maxYear, maxDay := utils.GetCurrentMaxYearAndDay() + t := table.New(). + Headers("Year", "01", "02", "03", "04", "05", "06", "07", "08", "09", + "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", + "20", "21", "22", "23", "24", "25", "Num"). + Border(lipgloss.NormalBorder()). + BorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("99"))) + y := utils.FIRST_YEAR for y <= maxYear { day := 25 if y == maxYear { day = maxDay } - rows = append(rows, getRowForYear(userToken, y, day)) + t.Row(getRowForYear(userToken, y, day)...) y++ } - newTable := table.New([]table.Column{ - table.NewColumn("Year", "Year", 4), - table.NewColumn("1", "1", 2), - table.NewColumn("2", "2", 2), - table.NewColumn("3", "3", 2), - table.NewColumn("4", "4", 2), - table.NewColumn("5", "5", 2), - table.NewColumn("6", "6", 2), - table.NewColumn("7", "7", 2), - table.NewColumn("8", "8", 2), - table.NewColumn("9", "9", 2), - table.NewColumn("10", "10", 2), - table.NewColumn("11", "11", 2), - table.NewColumn("12", "12", 2), - table.NewColumn("13", "13", 2), - table.NewColumn("14", "14", 2), - table.NewColumn("15", "15", 2), - table.NewColumn("16", "16", 2), - table.NewColumn("17", "17", 2), - table.NewColumn("18", "18", 2), - table.NewColumn("19", "19", 2), - table.NewColumn("20", "20", 2), - table.NewColumn("21", "21", 2), - table.NewColumn("22", "22", 2), - table.NewColumn("23", "23", 2), - table.NewColumn("24", "24", 2), - table.NewColumn("25", "25", 2), - table.NewColumn("Num", "Num", 3), - }).WithRows(rows).BorderRounded().WithBaseStyle(styles.UserTableStyle) - return tableDoneMsg{table: newTable} + return tableDoneMsg{table: *t} } } -func getRowForYear(userToken string, year, day int) table.Row { - stars := make([]string, 26) +func getRowForYear(userToken string, year, day int) []string { + stars := make([]string, 27) d := 1 numStars := 0 for d <= day { p := LoadOrCreatePuzzle(year, d, userToken) var sOut string - // log.Info(numStars) if p.AnswerTwo != "" { sOut = lipgloss.NewStyle().Foreground(styles.BothStarsColor).Render("*") numStars += 2 @@ -201,7 +178,7 @@ func getRowForYear(userToken string, year, day int) table.Row { numStars += 1 } } else { - sOut = lipgloss.NewStyle().Foreground(styles.NoStarsColor).Render("-") + sOut = lipgloss.NewStyle().Foreground(styles.SubtitleColor).Render(".") } stars[d] = sOut d++ @@ -213,33 +190,8 @@ func getRowForYear(userToken string, year, day int) table.Row { } } - return table.NewRow(table.RowData{ - "Year": year, - "1": stars[1], - "2": stars[2], - "3": stars[3], - "4": stars[4], - "5": stars[5], - "6": stars[6], - "7": stars[7], - "8": stars[8], - "9": stars[9], - "10": stars[10], - "11": stars[11], - "12": stars[12], - "13": stars[13], - "14": stars[14], - "15": stars[15], - "16": stars[16], - "17": stars[17], - "18": stars[18], - "19": stars[19], - "20": stars[20], - "21": stars[21], - "22": stars[22], - "23": stars[23], - "24": stars[24], - "25": stars[25], - "Num": numStars, - }) + stars[0] = strconv.Itoa(year) + stars[26] = strconv.Itoa(numStars) + + return stars }