|
|
|
@ -1,49 +1,77 @@ |
|
|
|
|
package main |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"bufio" |
|
|
|
|
"fmt" |
|
|
|
|
"os" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type Todo struct { |
|
|
|
|
Title string |
|
|
|
|
Content string |
|
|
|
|
} |
|
|
|
|
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") |
|
|
|
|
|
|
|
|
|
type Todos struct { |
|
|
|
|
Items []Todo |
|
|
|
|
} |
|
|
|
|
fmt.Printf("\n\n0: List menu again\n") |
|
|
|
|
fmt.Printf("4: Quit\n\n> ") |
|
|
|
|
|
|
|
|
|
func (todo *Todos) AddTodo(newTodo Todo) { |
|
|
|
|
todo.Items = append(todo.Items, newTodo) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (todo *Todos) RemoveTodo(index int) { |
|
|
|
|
//remove todo via index
|
|
|
|
|
todo.Items = append(todo.Items[:index], todo.Items[index+1:]...) |
|
|
|
|
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") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (todo *Todos) ListTodosFull() { |
|
|
|
|
//List all the contents
|
|
|
|
|
if len(todo.Items) == 0 { |
|
|
|
|
fmt.Printf("empty\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> ") |
|
|
|
|
} |
|
|
|
|
for k, v := range todo.Items { |
|
|
|
|
fmt.Printf("%d:%s\n", k, v) |
|
|
|
|
|
|
|
|
|
if err := list.RemoveTodo(index); err != nil { |
|
|
|
|
fmt.Print(err) |
|
|
|
|
} |
|
|
|
|
PrintMenu() |
|
|
|
|
case 4: |
|
|
|
|
fmt.Print("Quitting, goodbye!\n") |
|
|
|
|
os.Exit(0) |
|
|
|
|
default: |
|
|
|
|
PrintMenu() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func ListTodosSmall() { |
|
|
|
|
fmt.Println("ListTodosSmall func. not implemented") |
|
|
|
|
//List all the contents
|
|
|
|
|
} |
|
|
|
|
func main() { |
|
|
|
|
fmt.Println("TODO APP") |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
list := Todos{} |
|
|
|
|
//todos := []Todo{}
|
|
|
|
|
//list := Todos{todos}
|
|
|
|
|
fmt.Println("Empty list: ") |
|
|
|
|
list.ListTodosFull() |
|
|
|
|
list.ListTodo() |
|
|
|
|
|
|
|
|
|
fmt.Println("Adding entries...") |
|
|
|
|
items := []Todo{ |
|
|
|
@ -67,12 +95,13 @@ func main() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fmt.Println("Listing...") |
|
|
|
|
list.ListTodosFull() |
|
|
|
|
list.ListTodo() |
|
|
|
|
fmt.Println("Listing again...") |
|
|
|
|
list.ListTodosFull() |
|
|
|
|
list.ListTodo() |
|
|
|
|
|
|
|
|
|
fmt.Println("Removing item2 via index 1") |
|
|
|
|
list.RemoveTodo(1) |
|
|
|
|
fmt.Println("Listing again...") |
|
|
|
|
list.ListTodosFull() |
|
|
|
|
list.ListTodo() |
|
|
|
|
*/ |
|
|
|
|
} |
|
|
|
|