can now display what was added to a list, even though nothing was haha
This commit is contained in:
		
							parent
							
								
									1c26fa59fc
								
							
						
					
					
						commit
						ba21738540
					
				
							
								
								
									
										52
									
								
								rodo.rkt
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								rodo.rkt
									
									
									
									
									
								
							@ -7,21 +7,26 @@
 | 
			
		||||
(define program-directory ".rodo/")
 | 
			
		||||
(define program-path "~/")
 | 
			
		||||
 | 
			
		||||
(define (d-hash-ref key)
 | 
			
		||||
  (displayln (hash-ref messages key)))
 | 
			
		||||
(define (d-hash-ref hash-list key)
 | 
			
		||||
  (display (hash-ref messages key)))
 | 
			
		||||
 | 
			
		||||
(define (d-vector-ref args key)
 | 
			
		||||
  (display (vector-ref args key)))
 | 
			
		||||
 | 
			
		||||
(define messages 
 | 
			
		||||
  (hash 
 | 
			
		||||
    'incorrect-usage (string-append "> For usage type `" program-name " -h` or `" program-name " --help`")
 | 
			
		||||
    'creating (string-append "> Creating a " program-directory " folder in " program-path "...")
 | 
			
		||||
    'creation-error (string-append "> Error: Could not create " program-directory " in " program-path ".\n> This may be due to directory permissions")
 | 
			
		||||
    'already-exists (string-append "> " program-directory " folder already exists in " program-path)
 | 
			
		||||
    'successfully-created (string-append "> " program-path program-directory " has been successfully created") 
 | 
			
		||||
    'not-found (string-append "> " program-directory " has not been setup in " program-path "\n> Would you like to set it up now? [y/n]")
 | 
			
		||||
    'item-added "> Added item to list" 
 | 
			
		||||
    'item-removed "> Added item to list"
 | 
			
		||||
    'terminating (string-append "> Exiting " program-name "...")
 | 
			
		||||
    'choose-y/n "> Error: Please choose y or n"))
 | 
			
		||||
    'incorrect-usage (string-append "> For usage type `" program-name " -h` or `" program-name " --help`\n")
 | 
			
		||||
    'creating (string-append "> Creating a " program-directory " folder in " program-path "...\n")
 | 
			
		||||
    'creation-error (string-append "> Error: Could not create " program-directory " in " program-path ".\n> This may be due to directory permissions\n")
 | 
			
		||||
    'already-exists (string-append "> " program-directory " folder already exists in " program-path "\n")
 | 
			
		||||
    'successfully-created (string-append "> " program-path program-directory " has been successfully created\n") 
 | 
			
		||||
    'not-found (string-append "> " program-directory " has not been setup in " program-path "\n> Would you like to set it up now? [y/n]\n")
 | 
			
		||||
    'item-added-prefix "> Added " 
 | 
			
		||||
    'item-added-suffix " to list\n" 
 | 
			
		||||
    'item-removed-prefix "> Removed "
 | 
			
		||||
    'item-removed-suffix "from list\n"
 | 
			
		||||
    'terminating (string-append "> Exiting " program-name "...\n")
 | 
			
		||||
    'choose-y/n "> Error: Please choose y or n\n"))
 | 
			
		||||
 | 
			
		||||
;; some possible user-input related "mistakes" that will be accepted for input
 | 
			
		||||
(define y/n 
 | 
			
		||||
@ -44,18 +49,18 @@
 | 
			
		||||
 | 
			
		||||
;; prompt user for file initial file creation 
 | 
			
		||||
(define (prompt-user chosen-message)
 | 
			
		||||
  (d-hash-ref chosen-message)
 | 
			
		||||
  (d-hash-ref messages chosen-message)
 | 
			
		||||
  (display "> ")
 | 
			
		||||
  (let ([user-input (read-line)])
 | 
			
		||||
    (cond
 | 
			
		||||
      [(member user-input (hash-ref y/n 'yes))  
 | 
			
		||||
       (d-hash-ref 'creating)
 | 
			
		||||
       (d-hash-ref messages 'creating)
 | 
			
		||||
       (create-folder)
 | 
			
		||||
       (if (check-for-folder)
 | 
			
		||||
         (d-hash-ref 'successfully-created)
 | 
			
		||||
         (d-hash-ref 'creation-error))]
 | 
			
		||||
         (d-hash-ref messages 'successfully-created)
 | 
			
		||||
         (d-hash-ref messages 'creation-error))]
 | 
			
		||||
      [(member user-input (hash-ref y/n 'no))  
 | 
			
		||||
       (d-hash-ref 'terminating)]
 | 
			
		||||
       (d-hash-ref messages 'terminating)]
 | 
			
		||||
      [else 
 | 
			
		||||
        (prompt-user 'choose-y/n)])))
 | 
			
		||||
 | 
			
		||||
@ -63,19 +68,22 @@
 | 
			
		||||
  (let ([args-length (vector-length args)])
 | 
			
		||||
    (cond
 | 
			
		||||
      [(or (equal? args-length 0) (> args-length 2))
 | 
			
		||||
       (d-hash-ref 'incorrect-usage)]
 | 
			
		||||
       (d-hash-ref messages 'incorrect-usage)]
 | 
			
		||||
      [(and (equal? args-length 2) (equal? (vector-member "add" args) 0))
 | 
			
		||||
       (d-hash-ref 'item-added)]
 | 
			
		||||
       ;;       (d-hash-ref messages 'item-added-prefix) (vector-ref args 1)]
 | 
			
		||||
       (d-hash-ref messages 'item-added-prefix) 
 | 
			
		||||
       (d-vector-ref args 1) 
 | 
			
		||||
       (d-hash-ref messages 'item-added-suffix)]
 | 
			
		||||
      [(and (equal? args-length 2) (equal? (vector-member "remove" args) 0))
 | 
			
		||||
       (d-hash-ref 'item-removed)]
 | 
			
		||||
       (d-hash-ref messages 'item-removed-prefix)]
 | 
			
		||||
      [(and (equal? args-length 1) (equal? (vector-member "init" args) 0))
 | 
			
		||||
       (todo-list-exist?)]
 | 
			
		||||
      [else (d-hash-ref 'incorrect-usage)])))
 | 
			
		||||
      [else (d-hash-ref messages 'incorrect-usage)])))
 | 
			
		||||
 | 
			
		||||
;; does the file exist that holds the list(s?)
 | 
			
		||||
(define (todo-list-exist?)
 | 
			
		||||
  (if (check-for-folder)
 | 
			
		||||
    (d-hash-ref 'already-exists)
 | 
			
		||||
    (d-hash-ref messages 'already-exists)
 | 
			
		||||
    (prompt-user 'not-found)))
 | 
			
		||||
 | 
			
		||||
(define (main)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user