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

User Interactive Inputs #1

Open
francescobianco opened this issue Apr 5, 2021 · 3 comments
Open

User Interactive Inputs #1

francescobianco opened this issue Apr 5, 2021 · 3 comments

Comments

@francescobianco
Copy link

francescobianco commented Apr 5, 2021

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

francescobianco commented Apr 5, 2021

On this javanile@88e67ff#diff-9d9229e32ca3173d8cf19f4cff5875b09d3d07b49ecc1412f5aee25ceb21dd4d

I did some tests but without success

The base ideas was:

  • Switch to cat "$1" | for loop to script file lines (the main while loop)
  • Use eval with explicit redirected input (but it works for BASH not for SH)
  • Use array for user_input buffer to add deplay between multiple inputs called for the same command (In this way when command ask for multiple question it play with delay on each differt input and not all at the same time)

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

@francescobianco francescobianco changed the title User Interactive input User Interactive Inputs Apr 5, 2021
@francescobianco
Copy link
Author

@ko1nksm any luck about this?

@ko1nksm
Copy link
Owner

ko1nksm commented Apr 30, 2021

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.

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

2 participants