#!/usr/bin/env newlisp (context 'Type) (constant 'escape "\027[") (set 'cls (string escape "2J")) (set 'column-zero (string escape ";0H")) (set 'move-away (string escape "25;25H")) (set 'typing-speed 100) (set 'reading-pause 1500) (define (display chars) (println column-zero chars move-away)) (define (Type:Type str) (println cls) (for (i 0 (length str)) (display (string (0 i str))) (if (< (char (str (- i 1))) 32) (sleep reading-pause) (sleep typing-speed))) "") (Type [text]; A typewriter effect for ANSI (VT100) terminals. ; First, we create a context for our stuff ; to avoid a lecture from the Scope Police (context 'Type) (constant 'escape "\027[") ; that's an ANSI escape signal. Make it a constant, it's not going to change. (set 'cls (string escape "2J")) ; That will clear the screen. (set 'column-zero (string escape ";0H")) ; and that will send the cursor back to the beginning of the line. (set 'move-away (string escape "25;25H")) ; That just sends the cursor somewhere else! (set 'typing-speed 100) ; How fast can you type? This is milliseconds. (set 'reading-pause 2000) ; And how fast can you read each line? (define (display chars) (println column-zero chars move-away)) ; that will print the characters and then move the cursor away. ; The context's default function sends the lines to (display). ; In slices. (define (Type:Type str) (println cls) (for (i 0 (length str)) (display (string (0 i str))) ; that's a slice from the beginning to i (if (< (char (str (- i 1))) 32) ; cr/lf - time for a short break (sleep reading-pause) ; how fast is that typing? (sleep typing-speed))) "") ; To run: (Type "text") > [/text])