Open joelmccracken opened 4 years ago
I'd LOVE to be able to script this whole thing e.g. what I asked here. https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/3
If/when i get around to doing this I will be definitely looking into that. Setting all of these things up etc will be a big pain if I cant re-record the screencast via a script
A couple of notes from me playing around to try to get this to work:
expect
to work. Seems broken. Unable to send any input to the reddup process. nix-shell -p asciinema
with whatever else is necessary. Emacs? doom?emacs -nw
. I am using doom currently; a fully reproducible script environment should either not use doom or should set it up for the recorder.*Messages*
buffer works). will need to write an emacs lisp function like message
for this, but that should not be hard. M-x shell
process (or one of the other shells) and send input to that process. expect
ed. the haskell script:
#!/usr/bin/env stack
-- stack --resolver lts-16.10 script --package turtle --package text --package string-interpolate --package directory --package process
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
import Data.String.Interpolate (i)
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import GHC.IO.Handle
import Prelude hiding (FilePath)
import System.Directory
import System.Process
import qualified Turtle as Tu
main :: IO ()
main = do
(Just hin, Just hout, _, _) <- createProcess (shell "stack exec -- reddup -i") {std_in = CreatePipe, std_out = CreatePipe}
-- readUntil "Choice: " hin
Tu.sleep 5
readUntil "Choice: " hout
-- cs <- takeChars 20 hout
-- putStrLn cs
putStrLn "FOUND IT"
undefined
readUntil :: String -> Handle -> IO ()
readUntil needle h = do
let l = length needle
search' :: String -> IO ()
search' "" = do
newBuffer <- takeChars l h
putStr newBuffer
search' newBuffer
search' buf@(x:xs) = do
if length buf < l then do
buf' <- takeChars (l - length buf) h
putStr buf'
search' (buf ++ buf')
else if doesBufferMatch buf then
return ()
else
search' xs
doesBufferMatch buffer =
take l buffer == needle
search' ""
takeChars :: Int -> Handle -> IO String
takeChars n h = do
loop n
where
loop 0 = pure ""
loop i = do
c <- hGetChar h
cs <- loop (i - 1)
pure (c:cs)
more thoughts on this: doRecordingScript.sh:
someOtherScriptThatSetsUpAllThePrerequsites.sh
emacs -q -l my-script.el
nowWhateverCommandToStartAsciinema.sh
my-script.el:
(progn
(sleep 5) ;; sleep to give asciinema a second to start
(ansi-term)
(window-split-1)
(other-window)
(buffer-switch "*User Messages*")
(with-current-buffer "*User-Messages*"
(insert "Welcome to the demo for Reddup! Messages for you, the viewer, will appear up here. What appears below is a demo shell session."))
(with-current-buffer "*Shell*"
(goto-char (point-max))
(insert "reddup -i\n"))
;; -- a lot of other stuff here
)
What should a asciinema recording show? Im guessing it would be good to show off each feature:
what needs to handle:
open
using whatever command