more features!

main
simonkellet 1 year ago
parent d08834e39e
commit 694b4c2cdb
  1. 149
      main.go
  2. BIN
      todo

@ -1,78 +1,107 @@
package main package main
import ( import (
"bufio"
"fmt" "fmt"
"os"
) )
type Todo struct { func PrintMenu() {
Title string fmt.Printf("### TODO APP ###\n")
Content string fmt.Printf("1: List Todo\n")
} fmt.Printf("2: Add Todo\n")
fmt.Printf("3: Remove Todo (via index)\n")
type Todos struct { fmt.Printf("\n\n0: List menu again\n")
Items []Todo fmt.Printf("4: Quit\n\n> ")
}
func (todo *Todos) AddTodo(newTodo Todo) {
todo.Items = append(todo.Items, newTodo)
} }
func (todo *Todos) RemoveTodo(index int) { func main() {
//remove todo via index fmt.Print("\033[H\033[2J") //clear
todo.Items = append(todo.Items[:index], todo.Items[index+1:]...) PrintMenu()
} list := Todos{}
for {
var input int
n, err := fmt.Scanln(&input)
if n < 1 || err != nil {
fmt.Print("[ERR] Invalid input\n")
}
func (todo *Todos) ListTodosFull() { switch input {
//List all the contents case 0:
if len(todo.Items) == 0 { PrintMenu()
fmt.Printf("empty\n") case 1:
} list.ListTodo()
for k, v := range todo.Items { PrintMenu()
fmt.Printf("%d:%s\n", k, v) case 2:
} in := bufio.NewReader(os.Stdin)
}
func ListTodosSmall() { fmt.Print("Add Title:\n> ")
fmt.Println("ListTodosSmall func. not implemented") title, _ := in.ReadString('\n')
//List all the contents
}
func main() {
fmt.Println("TODO APP")
list := Todos{} fmt.Print("Add Content:\n> ")
//todos := []Todo{} content, _ := in.ReadString('\n')
//list := Todos{todos}
fmt.Println("Empty list: ") list.AddTodo(Todo{Title: title, Content: content})
list.ListTodosFull() fmt.Printf("Added %s to the list!\n", title)
PrintMenu()
fmt.Println("Adding entries...") case 3:
items := []Todo{ var index int
{ fmt.Printf("Which TODO to remove?\n> ")
Title: "test",
Content: "Here is some content",
},
{
Title: "test1",
Content: "Here is some more content",
},
{
Title: "test2",
Content: "Here is even MORE content",
},
}
//Add the items for testing if _, err := fmt.Scanf("%d", &index); err != nil {
for item := range items { fmt.Printf("Invalid input\n> ")
list.AddTodo(items[item]) }
if err := list.RemoveTodo(index); err != nil {
fmt.Print(err)
}
PrintMenu()
case 4:
fmt.Print("Quitting, goodbye!\n")
os.Exit(0)
default:
PrintMenu()
}
} }
fmt.Println("Listing...") /*
list.ListTodosFull() list := Todos{}
fmt.Println("Listing again...") //todos := []Todo{}
list.ListTodosFull() //list := Todos{todos}
fmt.Println("Empty list: ")
list.ListTodo()
fmt.Println("Adding entries...")
items := []Todo{
{
Title: "test",
Content: "Here is some content",
},
{
Title: "test1",
Content: "Here is some more content",
},
{
Title: "test2",
Content: "Here is even MORE content",
},
}
//Add the items for testing
for item := range items {
list.AddTodo(items[item])
}
fmt.Println("Listing...")
list.ListTodo()
fmt.Println("Listing again...")
list.ListTodo()
fmt.Println("Removing item2 via index 1") fmt.Println("Removing item2 via index 1")
list.RemoveTodo(1) list.RemoveTodo(1)
fmt.Println("Listing again...") fmt.Println("Listing again...")
list.ListTodosFull() list.ListTodo()
*/
} }

BIN
todo

Binary file not shown.