Skip to content

Commit

Permalink
fix(snowcrash): run only when visible and use minimal dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
winny- committed Nov 12, 2024
1 parent 783f8a9 commit bdf7f45
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions site-lisp/snowcrash.el
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@

(defun snowcrash--draw ()
"Draw snowcrash in the current buffer."
(with-current-buffer (get-buffer snowcrash--buffer-name)
(read-only-mode -1)
(erase-buffer)
(dotimes (lines (1- (window-total-height nil 'floor)))
(dotimes (columns (1- (window-total-width nil 'floor)))
(insert-char (nth (random (length snowcrash--symbols))
snowcrash--symbols)))
(unless (= lines (- (window-total-height nil t) 2))
(newline)))
(goto-char (point-min))
(read-only-mode 1)))
(and-let* ((windows (get-buffer-window-list snowcrash--buffer-name))
(lines (1- (cl-loop for window in windows
minimize (window-total-height window 'floor))))
(columns (1- (cl-loop for window in windows
minimize (window-total-width window 'floor)))))
(with-current-buffer (get-buffer snowcrash--buffer-name)
(read-only-mode -1)
(erase-buffer)
(dotimes (i lines)
(dotimes (j columns)
(insert-char (nth (random (length snowcrash--symbols))
snowcrash--symbols)))
(unless (= i (1- lines))
(newline)))
(goto-char (point-min))
(read-only-mode 1))))

(defun snowcrash--tick ()
(snowcrash--draw)
Expand All @@ -35,7 +40,8 @@
(when (and (eq major-mode 'snowcrash-mode)
snowcrash--timer)
(cancel-timer snowcrash--timer)
(setq snowcrash--timer nil)))
(setq snowcrash--timer nil)
(remove-hook 'quit-window-hook #'snowcrash--quit-window-hook)))

(define-derived-mode
snowcrash-mode
Expand Down

0 comments on commit bdf7f45

Please sign in to comment.