emad-elsaid / hydra

𓆚 C implementation of the famous Emacs Hydra package to be used in terminal. Groups commands and assign each command a key binding
https://hydra.emadelsaid.com/
GNU General Public License v3.0
20 stars 3 forks source link

choices on stdin #5

Open edrex opened 11 months ago

edrex commented 11 months ago

Hi, just found your project, neat!

To make this more useful in scripts, it would be cool if I could pipe choices in, eg cat ./hydras/* | ./hydra or

cat <<EOF | ./hydra
c,Check directory,just check
r,Run in dev mode,just run
EOF

Also

emad-elsaid commented 11 months ago

I expected this to work:

echo "c,Check directory,just check" | hydra /dev/stdin

but it didn't. I'll try to debug it, but I'm tight on time nowadays so if you got some time to check why this doesn't work that would be great

edrex commented 11 months ago

This form works, but there's an issue with calling tcsetattr on stdin:

~/s/g/e/hydra (master)> ./hydra /dev/stdin < hydras/git
g âž” +Git     
tcsetattr(): Inappropriate ioctl for device
tcsetattr ICANON: Inappropriate ioctl for device
Git:
F âž”  Pull       b âž” +Branch     d âž”  Diff       i âž”  Init       l âž”  Log        p âž”  Push       s âž”  Status     z âž” +Stash      
tcsetattr(): Inappropriate ioctl for device

Not sure why the difference between the two forms. The joys of 50yo programming interfaces :)

emad-elsaid commented 11 months ago

I guess that's the line that tries to get the width of the window because that's the only function I recall I have used from sys/ioctl.h https://github.com/emad-elsaid/hydra/blob/master/hydra.c#L79