-
Notifications
You must be signed in to change notification settings - Fork 0
/
done.go
39 lines (29 loc) · 800 Bytes
/
done.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func renderDoneCommandBullet(i int) string {
return strconv.Itoa(i+1) + " "
}
func doneCommand(todos []todo) []todo {
scanner := bufio.NewScanner(os.Stdin)
fmt.Println("Which one should be marked as done?")
scanner.Scan()
selectedOrder, err := strconv.Atoi(scanner.Text())
if err != nil {
fmt.Println("Couldn't find the todo with this number")
return todos
}
selectedIndex := selectedOrder - 1
if selectedIndex < 0 || selectedIndex >= len(todos) {
fmt.Println("Couldn't find the todo with this number")
return todos
}
// todos = append(todos[:selectedIndex], todos[selectedIndex+1])
todos[selectedIndex].completed = true
printHero("Your new list:", todosToString(todos, renderDoneCommandBullet))
return todos
}