Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A more thorough asciinema recording #23

Open
joelmccracken opened this issue Sep 29, 2020 · 3 comments
Open

A more thorough asciinema recording #23

joelmccracken opened this issue Sep 29, 2020 · 3 comments

Comments

@joelmccracken
Copy link
Owner

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

  • running non-interactively to see the state of the system; do this first before running in interactive mode because it will show off all the "dirty" items.
  • running interactively will then handle each of these items
  • i think usually I see w/ asciinema the demoer will echo messages to explain what is going on; that wont work great for reddup interactive because it doesnt provide opportunity for commentary between commands? not sure how to do this better.

what needs to handle:

  • inbox
    • files that should be deleted
    • files that may want to open using whatever command
    • refiling things
    • rename files
    • open a shell
    • demoing custom handlers?
  • git
    • handle "dirty" working dir (wip commit)
    • push branch to origin
@joelmccracken
Copy link
Owner Author

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
Copy link
Owner Author

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

  • I cant get expect to work. Seems broken. Unable to send any input to the reddup process.
  • I looked into doing it with just haskell but it quickly got to the point where it would be harder than is worth (see attached script, saving it for posterity. But this isn't a great solution anyway because I still don't have a way to message the user about what is going on!
  • I tried doing the following and I now think it is the best solution for the needs:
    • (do initial setup; prep git repos, prep "inbox" directory types)
    • start asciinema. (probably in a nix-shell -p asciinema with whatever else is necessary. Emacs? doom?
    • start 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.
    • split screen, with one screen being used for "user messages", the other being used for "displaying reddup interaction". write messages to user in split (similar to how *Messages* buffer works). will need to write an emacs lisp function like message for this, but that should not be hard.
    • open a M-x shell process (or one of the other shells) and send input to that process.
      • I believe a long time ago I figured out how to properly send input to m-x shell, i can look over my old stuff and see how I did it, or maybe ask #emacs on freenode.
      • probably can include sleeps etc in order to not even need to read from the process (which will be simpler to program in general), although a better solution will probably validate that the output is what is expected.
      • I think avdi also has something like this that he used for his own screencasting?
    • do the entire demo. My thought is to basically have the demo scripted as an emacs lisp file.
    • quit everything and then the user can check that the recording looks good.

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
Copy link
Owner Author

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
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant