• Please review our updated Terms and Rules here

play ansi animation in linux terminal

binary.koala

New Member
Joined
May 9, 2006
Messages
9
hi folks,
sorry if my question is a little bit of offtopic kind, but i'm wondering how to play those old and sweet ANSI animations in modern linux terminal?
the problem is simple - it's just too quick. way too quick. i tried setting terminal speed with 'stty ospeed 300' but it didn't have any effect. how else could i slow down my terminal?

i attach one example
 

Attachments

  • trek.txt
    20.6 KB · Views: 1
Last edited:
It takes a little code.

Xterm can be used input and output for an arbitrary program - not just as the input and output for a command shell. One solution that takes advantage of this is a C program that does the following:

- Spawn an xterm process with stdin/stdout coming from the C program.
- Read the ANSI animation as a file
- Feed the bytes to the xterm periodicly. You will need to sleep for a few milliseconds between each byte to give the impression of a 300 or 1200 bps modem. (At 2400 bps the delay would be 4.2 millliseconds between characters.)


The xterm option you are looking for is -Sccn .. look up the man page and write some code.
 
thanks, that's pretty much as i was imagining it, though was hoping to find some existing software. well, then will try my little coding knowledge this weekend :)
 
Here is my attempt of a program. I haven't figured out how to delay output of every single character, at least not with buffered putchar/printf routines. Perhaps one can set the terminal in unbuffered mode? The call to fflush takes too long to be used for every character. I tried using setbuf(stdout,NULL) but it did not work as I wanted.

Code:
#include <stdio.h>
#include <stdlib.h> /* atoi */
#include <unistd.h> /* usleep */
int main(int argc,char *argv[]) {
  FILE *f;
  unsigned int d;
  int i=0;
  if (argc!=3) {
    fprintf(stderr,"Usage: %s animation speed\n",argv[0]);
  } else {
    d=atoi(argv[2])*1000;
    if (f=fopen(argv[1],"r")) {
      while (!feof(f)) {
        putchar(fgetc(f));
        if (++i == 80) {
          fflush(stdout); /* needs to flush output once in a while */
          usleep(d);
          i=0;
        }
      }
      fclose(f);
    } else {
      fprintf(stderr,"%s: Unable to open file %s\n",argv[0],argv[1]);
    }
  }
  return 0;
}

Happy hacking.
 
Back
Top