Skip to content
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
62 changes: 59 additions & 3 deletions cli/tasky/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import (
"errors"
"flag"
"fmt"
"github/tasky"
"io"
"os"
"strconv"
"strings"
"time"

"github.com/alexeyco/simpletable"

Comment on lines +14 to +16
Copy link

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Group external imports (github.com/alexeyco/simpletable, github/tasky) on a separate block below the stdlib imports for clarity.

Suggested change
"github.com/alexeyco/simpletable"
)
import (
"github.com/alexeyco/simpletable"

Copilot uses AI. Check for mistakes.
"github/tasky"
)

const (
Expand Down Expand Up @@ -106,7 +110,7 @@ func run() error {
case removeTask > 0:
return handleRemoveTask(tasks, removeTask)
case listTasks:
tasks.Print()
PrintTable(*tasks)
return nil
default:
return errInvalidUsage
Expand All @@ -124,7 +128,10 @@ func handleAddTask(tasks *tasky.Todos) error {
return fmt.Errorf("failed to store tasks: %w", err)
}

fmt.Printf("\nBoom! Task added: %s 🤘➕.\nNow go crush it like a boss—or just let it chill like your unread PMs😜! \n\n", task)
fmt.Printf(
"\nBoom! Task added: %s 🤘➕.\nNow go crush it like a boss—or just let it chill like your unread PMs😜! \n\n",
task,
)

return nil
}
Expand Down Expand Up @@ -224,3 +231,52 @@ func getInput(r io.Reader, args ...string) (string, error) {

return text, nil
}

func PrintTable(tasks tasky.Todos) {
table := simpletable.New()

table.Header = &simpletable.Header{
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Text: "#"},
{Align: simpletable.AlignCenter, Text: "Tasks"},
{Align: simpletable.AlignCenter, Text: "State"},
{Align: simpletable.AlignRight, Text: "Created At"},
{Align: simpletable.AlignRight, Text: "Completed At"},
},
}

var cells [][]*simpletable.Cell
for index, item := range tasks {
task := tasky.Blue(item.Task)
done := "❌"
completedAt := "-"

if item.Done {
task = tasky.Green(item.Task) // green(item.Task)
Copy link

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the commented-out // green(item.Task) comment to clean up redundant code.

Suggested change
task = tasky.Green(item.Task) // green(item.Task)
task = tasky.Green(item.Task)

Copilot uses AI. Check for mistakes.
done = tasky.Green("✅")
completedAt = item.CompletedAt.Format(time.RFC822)
}

cells = append(cells, []*simpletable.Cell{
{Text: fmt.Sprintf("%d", index+1)},
{Text: task},
{Text: done},
{Text: item.CreatedAt.Format(time.RFC822)},
{Text: completedAt},
})
}

table.Body = &simpletable.Body{Cells: cells}
table.Footer = &simpletable.Footer{
Cells: []*simpletable.Cell{
{
Align: simpletable.AlignCenter,
Span: 5,
Text: tasky.Red(fmt.Sprintf("You have %d pending tasks", tasks.CountPending())),
},
},
}

table.SetStyle(simpletable.StyleUnicode)
table.Println()
}
6 changes: 3 additions & 3 deletions colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ const (
ColorGray = "\x1b[90m"
)

func red(s string) string {
func Red(s string) string {
return fmt.Sprintf("%s%s%s", ColorRed, s, ColorDefault)
}

func green(s string) string {
func Green(s string) string {
return fmt.Sprintf("%s%s%s", ColorGreen, s, ColorDefault)
}

func blue(s string) string {
func Blue(s string) string {
return fmt.Sprintf("%s%s%s", ColorBlue, s, ColorDefault)
}

Expand Down
54 changes: 1 addition & 53 deletions tasky.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import (
"os"
"path/filepath"
"time"

"github.com/alexeyco/simpletable"
)

var (
errInvalidIndex = errors.New("invalid index")
errEmptyTask = errors.New("task cannot be empty")
errEmptyTask = errors.New("task cannot be empty")
)

type item struct {
Expand Down Expand Up @@ -119,55 +117,6 @@ func (t *Todos) Store(filename string) error {
return nil
}

func (t *Todos) Print() {
table := simpletable.New()

table.Header = &simpletable.Header{
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Text: "#"},
{Align: simpletable.AlignCenter, Text: "Tasks"},
{Align: simpletable.AlignCenter, Text: "State"},
{Align: simpletable.AlignRight, Text: "Created At"},
{Align: simpletable.AlignRight, Text: "Completed At"},
},
}

var cells [][]*simpletable.Cell
for index, item := range *t {
task := blue(item.Task)
done := "❌"
completedAt := "-"

if item.Done {
task = green(item.Task)
done = green("✅")
completedAt = item.CompletedAt.Format(time.RFC822)
}

cells = append(cells, []*simpletable.Cell{
{Text: fmt.Sprintf("%d", index+1)},
{Text: task},
{Text: done},
{Text: item.CreatedAt.Format(time.RFC822)},
{Text: completedAt},
})
}

table.Body = &simpletable.Body{Cells: cells}
table.Footer = &simpletable.Footer{
Cells: []*simpletable.Cell{
{
Align: simpletable.AlignCenter,
Span: 5,
Text: red(fmt.Sprintf("You have %d pending tasks", t.CountPending())),
},
},
}

table.SetStyle(simpletable.StyleUnicode)
table.Println()
}

func (t *Todos) CountPending() int {
total := 0
for _, item := range *t {
Expand All @@ -181,4 +130,3 @@ func (t *Todos) CountPending() int {
func (t *Todos) isValidIndex(index int) bool {
return index > 0 && index <= len(*t)
}