ko1nksm / ghostplay

Automatic terminal input tool - ghost types your script!
MIT License
26 stars 2 forks source link

User Interactive Inputs #1

Open francescobianco opened 3 years ago

francescobianco commented 3 years ago

I want record into asciicinema a script with user inputs something like this

The idea is to introduce a directive to pass input, if called command ask for human inputs

Actually I have a command line program that ask for three question like this:

$ vtiger init
Where is your CRM?
 /var/www/html    <--(This is a human input but I want handle usign directive)
What your password?
 secret       <--(This is a human input but I want handle usign directive)
Give a name to this CRM?
 MyPersonal CRM       <--(This is a human input but I want handle usign directive)
Done.

My idea is create a file with the following instructions

#!/bin/bash

#ghostplay input /var/www/html 
#ghostplay input secret
#ghostplay input MyPersonal CRM
vtiger init

#ghostplay input Y
vtiger destroy
francescobianco commented 3 years ago

On this https://github.com/javanile/ghostplay/commit/88e67ff58dc41796957e3fc2f2f72727fa52a5ca#diff-9d9229e32ca3173d8cf19f4cff5875b09d3d07b49ecc1412f5aee25ceb21dd4d

I did some tests but without success

The base ideas was:

I think in other way is impossible show user input in screen play.

francescobianco commented 3 years ago

@ko1nksm any luck about this?

ko1nksm commented 3 years ago

Sorry for the late reply. This project is currently low priority for me and is not actively maintained. Therefore, I am replying with fragmentary information without sufficient confirmation.

The idea is to introduce a directive to pass input, if called command ask for human inputs

I don't think it's a bad idea, but there may be another way. For example, could the following code be used as a workaround?

#!/bin/sh
vtiger init < ./input.txt
yes | vtiger destroy

Use eval with explicit redirected input (but it works for BASH not for SH)

I would like to support POSIX shells as well as bash only whenever possible. However, this is not a requirement. I wrote the following script. And it worked. This means it may be able to support POSIX shells.

#!/bin/sh

echo "/var/www/html" > ./input.txt
echo "secret" >> ./input.txt
echo "MyPersonal CRM" >> ./input.txt
exec <./input.txt

echo "Where is your CRM?"
read line
echo "> $line"

echo "What your password?"
read line
echo "> $line"

echo "Give a name to this CRM?"
read line
echo "> $line"

In this way when command ask for multiple question it play with delay on each differt input and not all at the same time

Named pipes can be used to delay the input.

#!/bin/sh

mkfifo ./input.txt
( for i in $(seq 5); do sleep 1; echo $i; done > ./input.txt ) &

while IFS= read -r line; do
  echo "$line"
done < ./input.txt

rm ./input.txt

Switch to cat "$1" | for loop to script file lines (the main while loop)

Perhaps it would be better to use < "$1" instead of cat. See Useless use of cat (UUOC).

When running with asciicinema, you may encounter unexpected problems. This is because asciicinema is capturing STDIN/STDOUT, and I have experienced this once.

I'm not familiar with vtiger, but passwords are sensitive information and may be read from the TTY instead of STDIN. In that case, it will be difficult to handle. Using expect or stty may solve that problem.

I built this project without fully designing it, and I feel it needs to be redesigned. However, Currently, I don't have enough time, so I can't start working right away.