todo

package module
v0.0.0-...-09229cc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

CLI Todo App in Go

This project represents a simple but efficient CLI pplication written in Go, which allows you to manage your tasks through a simple and intuitive interface directly from your terminal. This is one of my first Go projects and it was initially inspired by the work of Abah Joseph. However, I've adopted quite a few distinct approaches and significantly expanded upon the initial concept.

Demo

Setup

Before using the CLI todo app, you need to have Go installed on your system. You can download and install Go from the official Go website.

Once you have Go installed, you can build the project using the following steps:

  1. Clone the repository:
git clone https://github.com/davidandw190/simple-todo-go.git
  1. Navigate to the project directory and build the project:
cd todo && go build ./cmd/todo
  1. Add the directory containing the executable to the system's PATH environment variable. I will showcase how to do it on LINUX, but it will work through other means on Windows too:
export PATH=$PATH:/full/path/to/the/program/here

Usage

The todo app currently supports the following functionalities:

List Tasks

To list all tasks, run the following command:

todo -l

By default, all tasks are listed. You can use additional flags to customize the output:

  • To show only completed tasks: -sc or --completed
  • To show only the pending tasks: -sp or --pending
Add Task

To add a new task, run the following command, and the CLI will prompt you for input:

todo -a
Edit Task

To edit an existing task, run the following command and the CLI will prompt you for input:

todo -e <taskIndex>
Complete Task

To mark a task as completed, run the following command:

todo -c <taskIndex>
Delete Task

To delete an existing task, run the following command:

todo -d <taskIndex>
Delete All Tasks

To delete all existing tasks, run the following command:

todo -da

Documentation

Overview

Package todo provides functionality for a simple CLI todo application.

Index

Constants

View Source
const (
	ColorDefault = "\x1b[39m"

	ColorRed   = "\x1b[91m"
	ColorGreen = "\x1b[32m"
	ColorBlue  = "\x1b[94m"
	ColorGrey  = "\x1b[90m"
)

Variables

This section is empty.

Functions

func Blue

func Blue(s string) string

func Green

func Green(s string) string

func Grey

func Grey(s string) string

func PrintBlue

func PrintBlue(w io.Writer, s string)

func PrintGreen

func PrintGreen(w io.Writer, s string)

func PrintGrey

func PrintGrey(w io.Writer, s string)

func PrintRed

func PrintRed(w io.Writer, s string)

func PrintRedStderr

func PrintRedStderr(s string)

PrintRedStderr prints red text to os.Stderr

func Red

func Red(s string) string

Types

type Item

type Item struct {
	Task        string
	Done        bool
	CreatedAt   time.Time
	CompletedAt time.Time
}

Item represents a single todo item.

type Todos

type Todos []Item

Todos is a collection of todo items.

func (*Todos) Add

func (t *Todos) Add(task string)

Add adds a new task to the todo list.

func (*Todos) Complete

func (t *Todos) Complete(index int) error

Complete marks a task as completed by index.

func (*Todos) Delete

func (t *Todos) Delete(index int) error

Delete removes a task by index.

func (*Todos) DeleteAll

func (t *Todos) DeleteAll() error

DeleteAll removes all the existing tasks.

func (*Todos) Edit

func (t *Todos) Edit(index int, newTask string) error

Edit modifies the task of an existing todo item, found by index.

func (*Todos) Load

func (t *Todos) Load(filename string) error

Load reads and deserializes todo items from a file.

func (Todos) Print

func (t Todos) Print()

Print prints all the todo items to the console.

func (Todos) PrintCompleted

func (t Todos) PrintCompleted()

PrintCompleted prints only the completed todo items to the console.

func (Todos) PrintPending

func (t Todos) PrintPending()

PrintPending prints only the pending todo items to the console.

func (*Todos) Store

func (t *Todos) Store(filename string) error

Store writes the todo items to a file in JSON format.

Directories

Path Synopsis
cmd
todo command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL