You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
go-todo/main.go

107 lines
1.9 KiB

package main
import (
"bufio"
"fmt"
"os"
)
func PrintMenu() {
fmt.Printf("### TODO APP ###\n")
fmt.Printf("1: List Todo\n")
fmt.Printf("2: Add Todo\n")
fmt.Printf("3: Remove Todo (via index)\n")
fmt.Printf("\n\n0: List menu again\n")
fmt.Printf("4: Quit\n\n> ")
}
func main() {
fmt.Print("\033[H\033[2J") //clear
PrintMenu()
list := Todos{}
for {
var input int
n, err := fmt.Scanln(&input)
if n < 1 || err != nil {
fmt.Print("[ERR] Invalid input\n")
}
switch input {
case 0:
PrintMenu()
case 1:
list.ListTodo()
PrintMenu()
case 2:
in := bufio.NewReader(os.Stdin)
fmt.Print("Add Title:\n> ")
title, _ := in.ReadString('\n')
fmt.Print("Add Content:\n> ")
content, _ := in.ReadString('\n')
list.AddTodo(Todo{Title: title, Content: content})
fmt.Printf("Added %s to the list!\n", title)
PrintMenu()
case 3:
var index int
fmt.Printf("Which TODO to remove?\n> ")
if _, err := fmt.Scanf("%d", &index); err != nil {
fmt.Printf("Invalid input\n> ")
}
if err := list.RemoveTodo(index); err != nil {
fmt.Print(err)
}
PrintMenu()
case 4:
fmt.Print("Quitting, goodbye!\n")
os.Exit(0)
default:
PrintMenu()
}
}
/*
list := Todos{}
//todos := []Todo{}
//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")
list.RemoveTodo(1)
fmt.Println("Listing again...")
list.ListTodo()
*/
}