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

Add support for ascii movies ;-) #5

Open
micw opened this issue Apr 28, 2017 · 6 comments
Open

Add support for ascii movies ;-) #5

micw opened this issue Apr 28, 2017 · 6 comments

Comments

@micw
Copy link

micw commented Apr 28, 2017

Hey, great stuff, I really like it.
If you integrate it with https://github.com/nitram509/ascii-telnet-server we cold use slack as movie player ^^

@mroth
Copy link
Owner

mroth commented Apr 28, 2017

hey, looks like that should more or less already work in theory.

from the options listed for that ascii movie project in the README:

--stdout              Run with STDIN and STDOUT, for example in XINETD
                      instead of stand alone TCP server. Use with python
                      option '-u' for unbuffered STDIN STDOUT communication

slacknimate is already designed to take input from STDIN, so you can just pipe it like:

python ascii_telnet_server.py --stdout | slacknimate -c "#movietime"

depending on what the text output looks like, you might want to pipe it through another script in the middle to "clean" it before posting to slack (e.g. possibly wrapping it in the ` backticks so Slack renders it as monospaced font, etc).

@micw
Copy link
Author

micw commented Apr 28, 2017

Glad to see that you notice the importance of this killer-feature :-D
The backtick quoting works, I already used it to create a (single line) moving text animation. Preprocessing in a separate script seems to be doable but it might be more easy to directly support the ascii movie format. See https://github.com/nitram509/ascii-telnet-server/blob/master/sample_movies/short_intro.txt for example: 1 Line contains integer with duration for the next frame. The frame itself consists of exactly 13 lines, then comes the next duration line and the next frame. Since you don't need all the VT100 terminal magic for cursor moves and resets, it's no much left to do ;)

@micw
Copy link
Author

micw commented Apr 28, 2017

I'll try my luck, maybe learn golang today ^^ I had a look to the code. Should be doable by introducing a new scanner, right? The only problem is the delay but maybe I can set it to 0 and delay within the scanner

@mroth
Copy link
Owner

mroth commented Apr 28, 2017 via email

@micw
Copy link
Author

micw commented Apr 28, 2017

Hm, read this too late. Meanwhile I got a brief impression of golang and wrote an initial release (see my fork at https://github.com/micw/slacknimate.
Basically it works, frame duration is ignored yet. For some reason it does not exit at the end of the channel (do I need to close it?).

A converting program might work but it can only have either loop or correct delays, not both...

Edit: Example: curl -s https://raw.githubusercontent.com/nitram509/ascii-telnet-server/master/sample_movies/short_intro.txt | bin/slacknimate --api-token xoxp-... --channel ... --movie

@mroth
Copy link
Owner

mroth commented Apr 28, 2017

Hm, read this too late. Meanwhile I got a brief impression of golang and wrote an initial release (see my fork at https://github.com/micw/slacknimate.

Fun! Since you mentioned you were just learning Go now -- Even though I suspect we'll end up with the separate program piping solution, let me know if you want me to code review this commit for idiomatic Go and offer some pointers in case you're curious to learn more about the language (I'm certainly no expert, and it's not exactly my favorite language, but I can probably point out some things.)

Basically it works, frame duration is ignored yet. For some reason it does not exit at the end of the channel (do I need to close it?).

That's correct. You'll see in main.go that frames is set to the return value of either LoopingStdinScanner() or StdinScanner(). In both of these cases, the return value of the function is a channel, so the for loop is ranging over a channel. The range function is fairly magic in Go, and does different things for different data types. When the for...range construct is used on a channel, it will block until it receives a new value over the channel and then execute the inner loop with the received value, repeating forever until the channel is closed, then it breaks the for loop. (Beware, trying to write to a channel after it's been closed in Go will cause a runtime panic and crash -- there is sadly no safety to prevent this.)

A converting program might work but it can only have either loop or correct delays, not both...

Actually you should technically still be able to do this -- have your program handle the looping vs not looping and post stuff to STDOUT with the timing you want (and probably disable buffering if you are using a language that automatically buffers stdout), and run slacknimate in normal mode so it posts input whenever it receives it. When your program exits, it will automatically EOF the stdout, which will cause slacknimate to detect this and stop posting gracefully and exit itself.

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