Skip to content

Commit

Permalink
adding color and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hardikkum444 committed Nov 17, 2024
1 parent 5fbc475 commit 6d82592
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
47 changes: 32 additions & 15 deletions cmd/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@ package cmd

import (
"fmt"
"strconv"
// "strings"
"time"

"github.com/gdamore/tcell/v2"
"github.com/hardikkum444/go-do-it/storage"
"github.com/rivo/tview"
// "github.com/gdamore/tcell/v2"
// "github.com/spf13/cobra"
"strconv"
"time"
)

func CenterTable(width, height int, p tview.Primitive) tview.Primitive {
return tview.NewFlex().
AddItem(nil, 0, 1, false).
AddItem(tview.NewFlex().
SetDirection(tview.FlexRow).
AddItem(nil, 0, 1, false).
AddItem(p, height, 1, true).
AddItem(nil, 0, 1, false), width, 1, true).
AddItem(nil, 0, 1, false)
}

func renderTable() {
table := tview.NewTable().
SetBorders(true)
Expand All @@ -27,19 +35,28 @@ func renderTable() {
return
}

table.SetCell(0, 0, tview.NewTableCell("#"))
table.SetCell(0, 1, tview.NewTableCell("Title"))
table.SetCell(0, 2, tview.NewTableCell("Completed"))
table.SetCell(0, 3, tview.NewTableCell("Deadline"))
table.SetCell(0, 4, tview.NewTableCell("Notes"))
table.SetCell(0, 5, tview.NewTableCell("CreatedAt"))
table.SetCell(0, 6, tview.NewTableCell("CompletedAt"))
table.SetCell(0, 0, tview.NewTableCell("#").SetTextColor(tcell.ColorYellow))
table.SetCell(0, 1, tview.NewTableCell("Title").SetTextColor(tcell.ColorYellow))
table.SetCell(0, 2, tview.NewTableCell("Completed").SetTextColor(tcell.ColorYellow))
table.SetCell(0, 3, tview.NewTableCell("Deadline").SetTextColor(tcell.ColorYellow))
table.SetCell(0, 4, tview.NewTableCell("Notes").SetTextColor(tcell.ColorYellow))
table.SetCell(0, 5, tview.NewTableCell("CreatedAt").SetTextColor(tcell.ColorYellow))
table.SetCell(0, 6, tview.NewTableCell("CompletedAt").SetTextColor(tcell.ColorYellow))

for r, todo := range todosall {
row := r + 1
table.SetCell(row, 0, tview.NewTableCell(strconv.Itoa(row)))
table.SetCell(row, 1, tview.NewTableCell(todo.Title))
table.SetCell(row, 2, tview.NewTableCell(strconv.FormatBool(todo.Completed)))
var symbol string
symbolColor := tcell.ColorWhite
if todo.Completed == true {
symbol = "✔️"
symbolColor = tcell.ColorGreen
} else {
symbol = "❌"
symbolColor = tcell.ColorRed
}
table.SetCell(row, 2, tview.NewTableCell(symbol).SetTextColor(symbolColor))
table.SetCell(row, 3, tview.NewTableCell(todo.Deadline))
table.SetCell(row, 4, tview.NewTableCell(todo.Notes))
table.SetCell(row, 5, tview.NewTableCell((todosall[r].CreatedAt).Format(time.RFC1123)))
Expand All @@ -65,7 +82,7 @@ func renderTable() {
AddItem(table, 0, 3, false).
AddItem(form, 0, 1, false)

center := Center(120, 40, flex1)
center := CenterTable(120, 35, flex1)

if err := app.SetRoot(center, true).EnableMouse(true).SetFocus(form).Run(); err != nil {
panic(err)
Expand Down
6 changes: 1 addition & 5 deletions cmd/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ Copyright © 2024 man44 <[email protected]>
package cmd

import (
// "fmt"
"os"
"strconv"
// "strings"
"time"

"github.com/hardikkum444/go-do-it/storage"
"github.com/rivo/tview"
// "github.com/gdamore/tcell/v2"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -59,7 +55,7 @@ func createMenuList() *tview.List {
AddItem("delete all", "delete all tasks", 'x', func() {
renderDelall()
}).
AddItem("render table", "render tasks table", 'p', func() {
AddItem("render table", "render tasks table", 'r', func() {
renderTable()
}).
AddItem("quit", "quit application", 'q', func() {
Expand Down

0 comments on commit 6d82592

Please sign in to comment.