Last active
July 3, 2024 21:13
-
-
Save amno1/92f6c81518049d58b3cd8dfe7273d40d to your computer and use it in GitHub Desktop.
Ascii cat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; sleepy-cat.el --- Animate an ascii cat in Emacs -*- lexical-binding: t; -*- | |
;; Copyright (C) 2024 Arthur Miller | |
;; Author: Arthur Miller <[email protected]> | |
;; Keywords: | |
;; This program is free software; you can redistribute it and/or modify | |
;; it under the terms of the GNU General Public License as published by | |
;; the Free Software Foundation, either version 3 of the License, or | |
;; (at your option) any later version. | |
;; This program is distributed in the hope that it will be useful, | |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
;; GNU General Public License for more details. | |
;; You should have received a copy of the GNU General Public License | |
;; along with this program. If not, see <https://www.gnu.org/licenses/>. | |
;;; Commentary: | |
;; Animation frames stolen from: | |
;; https://www.youtube.com/watch?v=lbrXeV4hN08&t=14s | |
;;; Code: | |
(require 'org) | |
(defface cat-face | |
'((t (:inherit font-lock-function-name-face :height 300))) | |
"") | |
(cl-defstruct cat-stuff | |
face | |
buffer | |
config-to-restore | |
cat-wake-up | |
(current-frame 0) | |
X Y | |
(frames [" | |
/\\_/\\ | |
( o.o ) | |
>>>^<<< | |
"" | |
/\\_/\\ | |
( -.o ) | |
>^<<< | |
"" | |
/\\_/\\ | |
( -.- ) | |
>^< | |
"" | |
/\\_/\\ | |
( o.- ) | |
>>>^< | |
"" | |
/\\_/\\ | |
( -.- ) | |
>^< | |
"" | |
/\\_/\\ | |
( +.+ ) | |
<^> | |
"])) | |
(defvar the-cat) | |
(defun do-cat-stuff () | |
(setf the-cat (make-cat-stuff | |
:buffer (get-buffer-create "*Sleeping Cat*") | |
:config-to-restore (current-window-configuration) | |
:cat-wake-up t)) | |
(delete-other-windows) | |
(setf (cat-stuff-Y the-cat) (- (/ (window-size) 2) 10) | |
(cat-stuff-X the-cat) (+ (/ (window-size nil t) 2) 8)) | |
(with-current-buffer (cat-stuff-buffer the-cat) | |
(setq mode-line-format nil | |
fringe-indicator-alist | |
'((continuation nil nil))) | |
(fringe-mode -1) | |
(switch-to-buffer (current-buffer)) | |
(let ((spacer-x (make-string (cat-stuff-X the-cat) ?\s)) | |
(spacer-y (make-string (cat-stuff-Y the-cat) ?\n))) | |
(condition-case _ | |
(while (cat-stuff-cat-wake-up the-cat) | |
(erase-buffer) | |
(insert spacer-y) | |
(dolist (line (split-string | |
(aref (cat-stuff-frames the-cat) | |
(cat-stuff-current-frame the-cat)) "\n" t)) | |
(insert (propertize (concat spacer-x line "\n") 'face 'cat-face))) | |
(setf (cat-stuff-current-frame the-cat) | |
(if (= 5 (cat-stuff-current-frame the-cat)) | |
0 | |
(1+ (cat-stuff-current-frame the-cat)))) | |
(sit-for 0.2) | |
(message (format "Meow %s" | |
(make-string (cat-stuff-current-frame the-cat) ?.)))) | |
(quit (sleepy-go-sleep)))))) | |
(defun sleepy-go-sleep () | |
(setf (cat-stuff-cat-wake-up the-cat) nil) | |
(kill-buffer (cat-stuff-buffer the-cat)) | |
(set-window-configuration (cat-stuff-config-to-restore the-cat))) | |
(defun sleepy-cat () | |
"Display a cute cat in an Emacs frame." | |
(interactive) | |
(do-cat-stuff)) | |
(provide 'sleepy-cat) | |
;;; cat.el ends here | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, of course!
For some reason "line" got erased there. I had in on my computer. No idea what happened :). Thanks.