diff --git a/create.scm b/create.scm new file mode 100644 index 0000000..79099cc --- /dev/null +++ b/create.scm @@ -0,0 +1,12 @@ +(display "Name?") +(let ([name (get-line (current-input-port))]) + (display "Question?") + (let ([question (get-line (current-input-port))]) + (display "Answer?") + (let ([answer (get-line (current-input-port))]) + (display answer) + ;append to file + ; + ) + ) +) \ No newline at end of file diff --git a/install b/install old mode 100644 new mode 100755 diff --git a/local-install b/local-install index 00a36d3..4bdc8a2 100755 --- a/local-install +++ b/local-install @@ -1,4 +1,5 @@ #!/bin/sh +rm -rf ~/.local/bin/ming-flashcards mkdir ~/.local/bin/ming-flashcards cp *.scm ~/.local/bin/ming-flashcards/ cp mingMisc_Flashcards ~/.local/bin/mingMisc_Flashcards diff --git a/main.scm b/main.scm index bfd5f80..d177be7 100644 --- a/main.scm +++ b/main.scm @@ -1,20 +1,13 @@ (source-directories '("./" "./ming-flashcards")) (load "ipc.scm") +(load "storage.scm") (define-record-type flashcards (fields (mutable dimensions) (mutable input) ;questions to ask, to be removed when correctly answered (mutable questions) - ;current question - (mutable current) - ;correct answer(s) - (mutable answers) - ;total questions correctly asked - (mutable correct) - ;total questions asked - (mutable total) ;if false, command mode (mutable answer-mode) )) @@ -43,6 +36,7 @@ [ (is-escape arg) (let* ( + [questions (flashcards-questions self)] [answer-mode (flashcards-answer-mode self)] [change (if answer-mode #t @@ -51,7 +45,9 @@ ) (if change (begin (flashcards-answer-mode-set! self (not answer-mode)) - (cons self '("JustRedraw")) + ;and reset input + (flashcards-input-set! self "") + (list self "JustRedraw") ) (list self "DoNothing") )) @@ -61,19 +57,47 @@ ;process flashcards.input (if (flashcards-answer-mode self) ;check to see if answer is correct - (display "placeholder") - ; - ;process command - (display "placeholder") - ; + (let ([ans (cadar (flashcards-questions self))]) + (if (string=? (flashcards-input self) ans) + (begin + (flashcards-input-set! self "") + (flashcards-questions-set! self (cdr (flashcards-questions self))) + (list self "JustRedraw") + ) + (begin + (flashcards-input-set! self ans) + (list self "JustRedraw") + ) + ) + ) + (cond + [ + (string-starts-with? (flashcards-input self) "load ") + (let* ( + [parts (split-string (flashcards-input self) #\space 2)] + [name (list-ref parts 1)] + [questions (load-questions name)] + ) (begin + (flashcards-questions-set! self questions) + ;set answer mode to true, reset input + (flashcards-answer-mode-set! self #t) + (flashcards-input-set! self "") + (list self "JustRedraw") + )) + ] + [ + else + (list self "DoNothing") + ] + ) ) ] [ (is-backspace arg) - (if (= (length (flashcards-input self)) 0) - '(self '("DoNothing")) + (if (= (string-length (flashcards-input self)) 0) + (list self "DoNothing") (let ([input (flashcards-input self)]) - (flashcards-input-set! self (substring input 0 (- (length input) 1))) + (flashcards-input-set! self (substring input 0 (- (string-length input) 1))) (list self "JustRedraw") ) ) @@ -102,12 +126,16 @@ [coords (flashcards-dimensions self)] [width (car coords)] [height (car (cdr coords))] + [questions (flashcards-questions self)] ) (list + (draw-instructions-text (list 5 5) '("nimbus-roman") (if (> (length questions) 0) + (caar questions) + "No questions loaded" + ) (theme-info-text ti) (theme-info-background ti) #f #f) (draw-instructions-text (list 5 (- height 15)) '("nimbus-roman") (string-append (if (flashcards-answer-mode self) "ANS: " "CMD: " ) (flashcards-input self)) (theme-info-text ti) (theme-info-background ti) #f #f) - "b" ) ) )) @@ -124,4 +152,12 @@ '(420 300) )) -(listen (make-flashcards '(0 0) "" '() "" '() 0 0 #f) handle-message draw title resizable "Window" ideal-dimensions) +(if (file-exists? "~/.local/share/ming-wm/logs.txt") + ;rude, yeah. later, fix to append + (delete-file "~/.local/share/ming-wm/logs.txt") +) + +(display (guard + (x [else (condition-message x)]) + (listen (make-flashcards '(0 0) "" '() #f) handle-message draw title resizable "Window" ideal-dimensions) +) (open-output-file "~/.local/share/ming-wm/logs.txt")) diff --git a/storage.scm b/storage.scm new file mode 100644 index 0000000..861e16f --- /dev/null +++ b/storage.scm @@ -0,0 +1,14 @@ +(load "utils.scm") + +(define load-questions (lambda (name) + ;load and parse files + (define load-questions-tail (lambda (file questions) + (let ([line (get-line file)]) + (if (eof-object? line) + questions + (load-questions-tail file (append questions (list (line->question line)))) + ) + ) + )) + (load-questions-tail (open-input-file (string-append "~/.local/share/ming-wm/flashcards/" name ".flashq")) '()) +)) diff --git a/utils.scm b/utils.scm index 9f829f0..5c6323e 100644 --- a/utils.scm +++ b/utils.scm @@ -1,3 +1,10 @@ +(define line->question (lambda (line) + ;question and answer separated by #\x1F, I guess + (let ([parts (split-string line #\x1F -1)]) + (cons (car parts) (cdr parts)) ;return pair. list would be funnier though + ) +)) + (define-record-type theme-info (fields top background border-left-top border-right-bottom text top-text alt-background alt-text alt-secondary)) ;s-string->theme-info @@ -38,11 +45,12 @@ ;max should be -1 if no max is desired (define split-string (lambda (str split-char max) (define split-string-tail (lambda (chars current splitted) - (if (or (= (length chars) 0) (= (length splitted) max)) + ;(= (length splitted) max) + (if (= (length chars) 0) (reverse (cons current splitted)) (let ( [c (car chars)] - ) (if (char=? c split-char) + ) (if (and (char=? c split-char) (not (= (- max 1) (length splitted)))) (split-string-tail (cdr chars) "" (cons current splitted)) (split-string-tail (cdr chars) (string-append current (string c)) splitted) )) @@ -51,6 +59,22 @@ (split-string-tail (string->list str) "" '()) )) +(define string-starts-with? (lambda (str starts-str) + (define string-starts-with-tail (lambda (index max) + (if (= index max) + #t + (if (char=? (string-ref str index) (string-ref starts-str index)) + (string-starts-with-tail (+ index 1) max) + #f + ) + ) + )) + (if (< (string-length str) (string-length starts-str)) + #f + (string-starts-with-tail 0 (string-length starts-str)) + ) +)) + (define s-string->list (lambda (str) (split-string str #\x1F -1) )) @@ -66,7 +90,7 @@ (define draw-instructions-text (lambda (point fonts text colour bg-colour option-horiz-spacing option-mono-width) ;Text(Point, Vec, String, RGBColor, RGBColor, Option, Option), //font and text - (string-append "Text/\x1E;" (s-list->string point) (s-list->string fonts) text (s-list->string colour) (s-list->string bg-colour) (s-option->string option-horiz-spacing) (s-option->string option-mono-width)) + (string-append "Text/" (s-list->string point) "\x1E;" (s-list->string fonts) "\x1E;" text "\x1E;" (s-list->string colour) "\x1E;" (s-list->string bg-colour) "\x1E;" (s-option->string option-horiz-spacing) "\x1E;" (s-option->string option-mono-width)) )) (define is-escape (lambda (c)