Skip to content

Instantly share code, notes, and snippets.

@opensussex
Created June 8, 2023 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opensussex/7b66fd271fde779729651e1f2cc9ce24 to your computer and use it in GitHub Desktop.
Save opensussex/7b66fd271fde779729651e1f2cc9ce24 to your computer and use it in GitHub Desktop.
Scritch a rough outline of a scratch pad using Racket
#lang racket/gui
(define f (new (class frame%
(super-new))
[label "Scritch"]
[width 800]
[height 600]))
(define c (new editor-canvas% [parent f]))
(define t (new text%))
(send c set-editor t)
(send f show #t)
(define filename "scritch.txt")
(if (file-exists? filename)
(begin
(display "File exists, reading content:\n")
(call-with-input-file filename
(lambda (in)
(let ((line (read-line in 'any)))
(unless (eof-object? line)
(send t insert line))))))
(display "File does not exist.\n"))
(define (write-to-file)
(call-with-output-file filename
#:exists 'replace
(lambda (out)
(write (send t get-text) out)
(newline out))))
(define timer (new timer% [notify-callback
(lambda ()
(write-to-file)
(newline))]
[interval 5000]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment