Help us shape the future of Go! Take the 2026 Go Developer Survey

todo

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package todo implements parsing, serialisation, and file I/O for the todo.txt format (https://github.com/todotxt/todo.txt).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendLine

func AppendLine(rawLines []string, line string) []string

AppendLine appends a new line to rawLines.

func DeleteLine

func DeleteLine(rawLines []string, lineNumber int) []string

DeleteLine removes the line at 1-based lineNumber from rawLines.

func UpdateLine

func UpdateLine(rawLines []string, lineNumber int, newLine string) []string

UpdateLine replaces line at 1-based lineNumber with newLine in rawLines.

func WriteFile

func WriteFile(path string, rawLines []string) error

WriteFile writes rawLines back to path, creating the file if necessary.

Types

type Todo

type Todo struct {
	// LineNumber is the 1-based line number in todo.txt (insert order).
	LineNumber int

	Done        bool
	CompletedAt string // YYYY-MM-DD, only when Done == true
	Priority    string // single uppercase letter, empty if none
	CreatedAt   string // YYYY-MM-DD, empty if not set
	Description string // raw description text (includes +projects @contexts key:val tags)
	RawLine     string // original unparsed line (used as fallback)
	ParseFailed bool   // true if the line could not be parsed normally
}

Todo represents a single parsed todo.txt task.

func Parse

func Parse(line string, lineNumber int) Todo

Parse converts a raw line into a Todo. LineNumber must be set by the caller.

func ReadFile

func ReadFile(path string) ([]Todo, []string, error)

ReadFile reads all lines from path. If the file does not exist it returns an empty slice without error.

func (*Todo) Complete

func (t *Todo) Complete()

Complete marks the todo as done today, stripping priority and saving it as a pri:X tag in the description.

func (*Todo) Contexts

func (t *Todo) Contexts() []string

Contexts returns all @Context tokens from the description.

func (*Todo) Due

func (t *Todo) Due() string

Due returns the value of the due: tag, or empty string.

func (*Todo) Projects

func (t *Todo) Projects() []string

Projects returns all +Project tokens from the description.

func (*Todo) SavedPriority

func (t *Todo) SavedPriority() string

SavedPriority returns the value of the pri: tag (used to round-trip priority through completion), or empty string.

func (*Todo) String

func (t *Todo) String() string

String serialises the Todo back into a valid todo.txt line.

func (*Todo) Uncomplete

func (t *Todo) Uncomplete()

Uncomplete reverses a completion, restoring the pri: tag to the priority field if present.

Jump to

Keyboard shortcuts

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