todo.scm 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. (use-modules (zenity)
  2. (srfi srfi-1))
  3. ;; todo.txt should start with this content:
  4. ;; ((#f "Wash the dishes") (#f "Tidy the kitchen") (#f "Study science") (#f "Meditate"))
  5. (define (todo-check-off)
  6. (let* (;; Read in the current todo list
  7. (todo (call-with-input-file "examples/todo.txt" read))
  8. ;; Display it as a list
  9. (checked (or (zenity-checklist "todo" (list "done?" "items") todo
  10. #:height 450)
  11. (exit)))
  12. ;; Remove any checked items off the list to find the unchecked items
  13. (unchecked (lset-difference equal? (map cadr todo) checked)))
  14. ;; Save a new version of the todo list out with all the checked off
  15. ;; items first
  16. (call-with-output-file "examples/todo.txt"
  17. (lambda (port)
  18. (write (append (map (lambda (item) (list #t item)) checked)
  19. (map (lambda (item) (list #f item)) unchecked))
  20. port)
  21. (newline port)))
  22. (exit)))
  23. (define (todo-add)
  24. (let* (;; First ask for the user to enter a new todo list item:
  25. (item (or (zenity-entry "Add todo list item:")
  26. (exit)))
  27. ;; Read in the todo list
  28. (todo (call-with-input-file "examples/todo.txt" read))
  29. ;; Add this new item to the end of our todo list
  30. (todo (append todo (list (list #f item)))))
  31. (call-with-output-file "examples/todo.txt"
  32. (lambda (port)
  33. (write todo port)
  34. (newline port)))
  35. (todo-option)))
  36. (define (todo-option)
  37. (if (zenity-question "Add new item? (or press No to check off things you've done)")
  38. (todo-add)
  39. (todo-check-off)))
  40. (todo-option)