commit ca44373013cbfe3a38b896b3ae025426c6dc2c04 Author: stjet <49297268+stjet@users.noreply.github.com> Date: Mon Apr 7 21:36:00 2025 +0000 empty window diff --git a/install b/install new file mode 100644 index 0000000..b0edd22 --- /dev/null +++ b/install @@ -0,0 +1,5 @@ +#!/bin/sh +mkdir /usr/local/bin/ming-flashcards +cp *.scm /usr/local/bin/ming-flashcards/ +cp mingMisc_Flashcards /usr/local/bin/mingMisc_Flashcards +chmod +x /usr/local/bin/mingMisc_Flashcards \ No newline at end of file diff --git a/ipc.scm b/ipc.scm new file mode 100644 index 0000000..0b138ef --- /dev/null +++ b/ipc.scm @@ -0,0 +1,47 @@ +(load "utils.scm") + +;since it will be the wm talking to us, invalid inputs won't happen +(define listen (lambda (handle-message draw title resizable subtype ideal-dimensions) + (display (let* ( + [_input (get-line (current-input-port))] + [parts (split-string _input #\space 2)] + [command (car parts)] + [rest (if (= (length parts) 2) + (car (cdr parts)) + "" ;if this is the case `rest` won't be used + )] + ) (cond; + [ + (string=? command "handle_message") + (symbol->string (car (handle-message ""))) ;doesn't handle clipboard copy request yet... or parse the message, for that matter + ] + ;draw + [ + (string=? command "draw") + (draw "") ;placeholder, doesn't parse theme info or serialise + ] + [ + (string=? command "title") + (title) + ] + [ + (string=? command "resizable") + (s-bool->string (resizable)) + ] + [ + (string=? command "subtype") + subtype + ] + [ + (string=? command "ideal_dimensions") + ;placeholder + (s-list->string (ideal-dimensions (s-string->list rest))) + ] + [ + else + "invalid" + ] + ))) + (newline) + (listen handle-message draw title resizable subtype ideal-dimensions) +)) \ No newline at end of file diff --git a/local-install b/local-install new file mode 100755 index 0000000..00a36d3 --- /dev/null +++ b/local-install @@ -0,0 +1,5 @@ +#!/bin/sh +mkdir ~/.local/bin/ming-flashcards +cp *.scm ~/.local/bin/ming-flashcards/ +cp mingMisc_Flashcards ~/.local/bin/mingMisc_Flashcards +chmod +x ~/.local/bin/mingMisc_Flashcards \ No newline at end of file diff --git a/main.scm b/main.scm new file mode 100644 index 0000000..cd97a3b --- /dev/null +++ b/main.scm @@ -0,0 +1,28 @@ +(source-directories '("./" "./ming-flashcards")) + +(load "ipc.scm") + +(define handle-message (lambda (message) + ;placeholder + ;return either ('DoNothing) ('JustRedraw) or ('Request "string") clipboard copy request + (cons (string->symbol "JustRedraw") '()) +)) + +(define draw (lambda (theme-info) + ;placeholder + "" +)) + +(define title (lambda () + "Flashcards" +)) + +(define resizable (lambda () + #t +)) + +(define ideal-dimensions (lambda (_) + '(300 300) +)) + +(listen handle-message draw title resizable "Window" ideal-dimensions) \ No newline at end of file diff --git a/mingMisc_Flashcards b/mingMisc_Flashcards new file mode 100755 index 0000000..357c7ba --- /dev/null +++ b/mingMisc_Flashcards @@ -0,0 +1,3 @@ +#!/bin/sh +cd "$(dirname "${BASH_SOURCE[0]}")" #thanks stackoverflow +scheme --script ./ming-flashcards/main.scm diff --git a/utils.scm b/utils.scm new file mode 100644 index 0000000..3beb05a --- /dev/null +++ b/utils.scm @@ -0,0 +1,46 @@ +(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 +(define s-string->theme-info (lambda (str) + ;split by : and then \x1F + (display "placeholder") +)) + +(define s-bool->string (lambda (b) + (if b "true" "false") +)) + +(define join-string (lambda (li j-str) + (string-append (car li) + (fold-left (lambda (a x) + (string-append a x) + ) + "" + (map (lambda (e) (string-append j-str e)) (cdr li)) + ) + ) +)) + +(define s-list->string (lambda (li) + (join-string (map number->string li) "\x1F;") +)) + +;max should be 0 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) 1) max)) + (reverse (cons current splitted)) + (let ( + [c (car chars)] + ) (if (char=? c split-char) + (split-string-tail (cdr chars) "" (cons current splitted)) + (split-string-tail (cdr chars) (string-append current (string c)) splitted) + )) + ) + )) + (split-string-tail (string->list str) "" '()) +)) + +(define s-string->list (lambda (str) + (split-string str #\x1F 0) +)) \ No newline at end of file