Skip to content

Commit

Permalink
#25 use tmux capture-pane to create meaninful screen captures
Browse files Browse the repository at this point in the history
  • Loading branch information
fstamour committed Dec 15, 2021
1 parent ffad59a commit f15b404
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 8 deletions.
112 changes: 112 additions & 0 deletions scratch-files/annotation.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

(defvar *demo-root* (concat
(vc-find-root
(buffer-file-name
(current-buffer))
".git")
"/demo"))

(defvar *demo-annotations* ())

(defun demo-frame-annotation (svg)
(assoc-string
svg
*demo-annotations*))

(defun demo-annotate-frame (root svg)
(save-window-excursion
;; (toggle-frame-fullscreen )
(save-excursion
(let ((buffer
(find-file (concat root "/" svg))))
(unwind-protect
(progn
(delete-other-windows)
(with-current-buffer buffer
(let* ((size (image-size (image--get-image)))
(width (car size))
(height (cdr size))
(scale (min (/ (window-width) width)
(/ (window-height) height))))
(image--change-size scale)))
(push
(cons svg
(read-string "Annotate this frame: "))
*demo-annotations*))
(kill-buffer buffer))))))

(defun demo-annotate-all-frames-in-folder (root)
(cl-loop for svg in (directory-files root nil "\\.svg$")
repeat 1
unless (demo-frame-annotation svg)
do (demo-annotate-frame root svg)))

(demo-annotate-all-frames-in-folder
(concat
*demo-root*
"/annotated"))




(defun demo-read-annotation-from-text-file (file)
(cl-loop for line in
(split-string
(with-temp-buffer
(insert-file-contents file)
(buffer-substring-no-properties (point-min) (point-max)))
"\n"
t)
collect
(save-match-data
(and (string-match
"^\\([a-z0-9]+\\) \\([^ ]+\\) ?\\(.*\\)$" line)
(let ((filename
(match-string 2 line))
(hash (match-string 1 line))
(annotation (match-string 3 line)))
(list
filename
:sha1 hash
:annotation
(if (string-empty-p annotation)
;; Get from global variable
(getf
(cdr (demo-frame-annotation
(match-string 2 line)))
:annotation)
annotation)))))))



(defvar *demo-annotation-from-file*
(let* ((root (concat
*demo-root*
"/annotated"))
(file (concat root "/annotations.txt")))
(demo-read-annotation-from-text-file file)))


(getf
(cdr
(assoc-string "termtosvg_00001.svg"
*demo-annotation-from-file*))
:annotation)

;; (setf *demo-annotations* *demo-annotation-from-file*)
;; (setf *demo-annotation-from-file* *demo-annotations*)

;; Write it back
(let* ((root (concat
*demo-root*
"/annotated"))
(file (concat root "/annotations2.txt")))
(with-temp-buffer
(cl-loop for (filename _ hash _ annotation) in *demo-annotation-from-file*
do (insert hash " " filename " " annotation "\n"))
(when (file-writable-p file)
(write-region (point-min)
(point-max)
file))
(buffer-substring-no-properties (point-min) (point-max))
))
27 changes: 27 additions & 0 deletions scripts/animate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env sh
#
# This is an example of how to take a bunch of capture made with tmux
# and assemble them with termtosvg
#
# usage: termtosvg output.svg -c ./animate.sh
# or: termtosvg $demo_root -s -c ./animate.sh
#

# Stop on first error
set -e

# Move to repo's root
cd "$(git rev-parse --show-toplevel)"

demo_root=scripts/demo/

if [ ! -d "$demo_root" ]; then
echo "Demo folder doesn't exits"
exit 1
fi

for capture in $(echo $demo_root/*.capture | sort -n) ; do
# echo "$capture"
cat "$capture"
sleep 0.5
done
44 changes: 39 additions & 5 deletions scripts/demo.el
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,40 @@
:load-path '("src/"
"scripts/emacs-director/"))

(defvar *demo-root* (concat
(vc-find-root
(or (buffer-file-name
(current-buffer))
(pwd))
".git")
"/scripts/demo"))

(defvar *demo-window-config* nil)

;; Can use this to pass arguments to the script
;; (print argv)

(defvar hardcopy-counter 0)

(defun screen-hardcopy ()
(interactive)
(shell-command
(format
"screen -X hardcopy -h demo/%s.hardcopy" hardcopy-counter))
(incf hardcopy-counter))

(defun tmux-capture-pane ()
(interactive)
(shell-command
(format
"tmux capture-pane -e -p > %s/%s.capture" *demo-root*
hardcopy-counter))
(incf hardcopy-counter))

(defun capture ()
(interactive)
(tmux-capture-pane))

(director-run
:version 1
:before-start (lambda ()
Expand All @@ -35,9 +67,9 @@
;; Load breeze
(require 'breeze)
;; Start slime
;; (slime)
)
:steps '((:type "\M-x")
(slime-connect "localhost" 40050))
:steps '((:call capture)
(:type "\M-x")
(:type "breeze")
(:type [return])
(:wait 2)
Expand All @@ -46,14 +78,16 @@
(lambda ()
(interactive)
(set-window-configuration *demo-window-config*)))

;; Breeze-mode
(:call lisp-mode)
(:call breeze-mode)
(:call capture)
;; Calling quickfix
(:call breeze-quickfix)
(:wait 5))
(:call capture))
:typing-style 'human
:log-target '(file . "demo.log")
:log-target (cons 'file (concat *demo-root* "/demo.log"))
:delay-between-steps 0.5
:after-end (lambda () (kill-emacs 0))
:on-failure (lambda () (kill-emacs 1))
Expand Down
7 changes: 7 additions & 0 deletions scripts/demo.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; Setup a lisp process before making a demo

(cl:in-package #:cl)

(ql:quickload '(swank breeze))

(swank:create-server :port 40050 :dont-close t)
22 changes: 19 additions & 3 deletions scripts/demo.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
#!/usr/bin/env sh
#
# In another shell, run
# sbcl --load demo.lisp
#

# Stop on first error
set -e

# Move to repo's root
cd "$(git rev-parse --show-toplevel)"

termtosvg demo.svg -c 'emacs -nw -Q -l scripts/emacs-director/util/director-bootstrap.el -l scripts/demo.el'
# firefox demo.svg
demo_root=scripts/demo
mkdir -p scripts/demo

tail demo.log
screencast="demo.svg"
command='emacs -nw -Q -l scripts/emacs-director/util/director-bootstrap.el -l scripts/demo.el -- asdf'
# ^^^ -- asdf is just an example of passing arguments (e.g. swank's
# port).

if true; then
$command
else
termtosvg "$screencast" -m 100 -c "$command"
# firefox demo.svg
fi

tail $demo_root/demo.log

0 comments on commit f15b404

Please sign in to comment.