joelmccracken / reddup

Helping you keep your workstation nice and tidy
BSD 3-Clause "New" or "Revised" License
31 stars 6 forks source link

A more thorough asciinema recording #23

Open joelmccracken opened 4 years ago

joelmccracken commented 4 years ago

What should a asciinema recording show? Im guessing it would be good to show off each feature:

what needs to handle:

joelmccracken commented 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

joelmccracken commented 4 years ago

A couple of notes from me playing around to try to get this to work:

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)
joelmccracken commented 3 years ago

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
)