habits

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: MIT Imports: 8 Imported by: 0

README

Habit tracker

Description

Habit tracker is a command-line app written in Go. When trying to establish a new habit, it can be challenging to maintain focus and motivation. This command-line tool will help you to track and develop a habit in a 30-day challenge style.

Usage examples :

To track a habit, you need to write in your terminal name of the toll habit followed by the name of the habit you want to track.

Example for tracking a coding challenge:habit coding Next day check-in should also be: habit coding If you want to start tracking a new habit, change the name: habit meditating

Features :

  • Tracking habits for 30-days
  • Keeps you motivated with cool massages :)
  • Tracking multiple habits
  • Read data from and to a disk (JSON format)
  • Calculate time intervals so that you know whether to extend the current streak or start a new one

Future features:

  • Read and Write to and from multiple data sources
  • Access from the Web Interface
  • Data loss prevention

Thanks to @bitfield for his relaxed and unique way of mentoring!

Documentation

Index

Constants

View Source
const DBFile = "./data.db"

Variables

View Source
var Now = time.Now

Now passes the current system time

Functions

func RunCli

func RunCli()

Types

type Habit

type Habit struct {
	ID        int
	Name      string
	LastCheck time.Time
	Streak    int
	Done      bool
	Output    io.Writer
}

Habit struct has all habit attributes

func (Habit) LastCheckDays

func (h Habit) LastCheckDays(time time.Time) int

LastCheckDays method checks for number of days current date and

type Store

type Store struct {
	Habits []Habit
	Output io.Writer
	DB     *sql.DB
}

Store is a struct of all Store properties

func FromSQLite

func FromSQLite(dbFIle string) *Store

FromSQLite is checking for scheme to prepare it, if it doesn't exist and returns a store with connection

func (*Store) Add

func (s *Store) Add(name string)

Add method is adding a new habit to the table of Habits

func (*Store) AllHabits

func (s *Store) AllHabits() []Habit

AllHabits lists all Habits in the database

func (*Store) Break

func (s *Store) Break(habit Habit, time time.Time)

Break will restart a streak on a habit based on the LastCheck time

func (*Store) Done

func (s *Store) Done(habit Habit, time time.Time)

Done changes the habit status to done

func (*Store) GetHabit

func (s *Store) GetHabit(name string) (Habit, bool)

GetHabit takes habit name and returns a habit if it finds one

func (*Store) PerformHabit

func (s *Store) PerformHabit(h *Habit, days int, time time.Time)

PerformHabit makes a dissection based on days between current time and last checked date

func (Store) Print

func (s Store) Print(massage string, params ...interface{})

Print as Store method is wrapping Fprintf so that is not needed to specify the default output every time

func (*Store) UpdateYesterday

func (s *Store) UpdateYesterday(habit Habit, time time.Time)

UpdateYesterday changes the last checked date

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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