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

68 lines
1.2 KiB

package main
import (
"bufio"
"fmt"
"os"
)
func PrintMenu() {
fmt.Printf("\n\n### 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("Which TODO to remove?\n> ")
}
if err := list.RemoveTodo(index); err != nil {
fmt.Print(err)
}
PrintMenu()
case 4:
fmt.Print("Quitting, goodbye!\n")
os.Exit(0)
default:
PrintMenu()
}
}
}