Browse Source

add task to todo list

aeth 1 month ago
parent
commit
8e5583536c
4 changed files with 53 additions and 3 deletions
  1. 6 0
      Makefile
  2. 8 0
      cmd/main.go
  3. 3 3
      pkg/savestate.go
  4. 36 0
      pkg/userinterface.go

+ 6 - 0
Makefile

@@ -0,0 +1,6 @@
+.PHONY: build
+
+
+
+build:
+	go build -o ./build/itashi ./cmd/main.go 

+ 8 - 0
cmd/main.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"flag"
 	"fmt"
 	"os"
 
@@ -9,6 +10,13 @@ import (
 )
 
 func main() {
+	addtask := flag.Bool("add", false, "add a task to the shelf")
+	flag.Parse()
+	shelf := itashi.NewFilesystemShelf(itashi.FS_SAVE_LOCATION)
+	if *addtask {
+		itashi.AddTaskPrompt(shelf)
+		os.Exit(0)
+	}
 	p := tea.NewProgram(itashi.InitialModel())
 
 	if _, err := p.Run(); err != nil {

+ 3 - 3
pkg/savestate.go

@@ -2,7 +2,6 @@ package itashi
 
 import (
 	"bytes"
-	"fmt"
 	"log"
 	"os"
 	"strconv"
@@ -85,11 +84,13 @@ func NewFilesystemShelf(save string) *FilesystemShelf {
 	if err != nil {
 		log.Fatal("Could not parse the shelf template! ", err)
 	}
-	return &FilesystemShelf{
+	shelf := &FilesystemShelf{
 		SaveLocation: save,
 		Template:     tmpl,
 		Tasks:        []Task{},
 	}
+	shelf.Tasks = shelf.GetAll()
+	return shelf
 
 }
 
@@ -134,7 +135,6 @@ func parseFilesystemShelf(data []byte) []Task {
 	for i := range items {
 		sect := strings.Split(items[i], SHELF_COL_DELIM)
 		if len(sect) < 6 {
-			fmt.Printf("Length of item is not to spec.... length: %v. Item: %v\n", len(sect), sect)
 			continue
 		}
 		var id int

+ 36 - 0
pkg/userinterface.go

@@ -3,9 +3,12 @@
 package itashi
 
 import (
+	"bufio"
 	"bytes"
 	"fmt"
 	"log"
+	"os"
+	"strconv"
 	"text/template"
 	"time"
 
@@ -30,6 +33,17 @@ const HEADER_TEMPLATE = `
 {{.Time}} {{.Meridiem}} ({{.TtEod.Hours}}H, {{.TtEod.Minutes}}M -> EoD, {{.TtSun.Hours}}H, {{.TtSun.Minutes}}M -> {{.SunCycle}})
 `
 
+const TASK_ITEM = `
+Title: {{.Title}}
+-------------------------
+   {{.Desc}}
+
+Due: {{.Due}}
+Priority: {{.Priority}}
+Done?: {{.Priority}}
+
+`
+
 const TIME_TO_TEMPLATE = `{{.Hours}}H, {{.Minutes}}M`
 
 type HeaderData struct {
@@ -274,3 +288,25 @@ func (m model) View() string {
 	// Send the UI for rendering
 	return s
 }
+
+/*
+Add task to the shelf
+*/
+func AddTaskPrompt(shelf TaskShelf) {
+	task := &Task{}
+	var reader *bufio.Reader
+	reader = bufio.NewReader(os.Stdout)
+	fmt.Print("Enter Task Title: ")
+	task.Title, _ = reader.ReadString('\n')
+	fmt.Print("Task description: ")
+	task.Desc, _ = reader.ReadString('\n')
+	fmt.Print("Priority: ")
+	priority, _ := reader.ReadString('\n')
+	pri, err := strconv.Atoi(priority)
+	if err != nil {
+		fmt.Print("non-real number sry\n")
+	}
+	task.Priority = pri
+
+	shelf.AddTask(*task)
+}