Help language development. Donate to The Perl Foundation

Terminal::ANSI cpan:BDUGGAN last updated on 2020-11-30

Terminal-ANSI-0.0.5/

Terminal::ANSI

This is a library of ANSI escape sequences.

Example

use Terminal::ANSI;

save-screen;
clear-screen;
home;

hide-cursor;

sub scroll($row,$col = 1, $height = 7) {
  print-at $row,$col, "━" x 20;
  print-at $row + $height,$col, "━" x 20;
  my $on = $row;
  for 20000, 19999 ... 0 {
    atomically {
      set-scroll-region($row + 1,$row + $height - 1);
      scroll-up if $on >= $row + $height - 1;
      print-at ++$on min $row + $height - 1, $col, "counting down..$_";
    }
  }
}

my $p1 = start scroll(2);
my $p2 = start scroll(12,10,10);
my $p3 = start scroll(24);
await Promise.allof($p1,$p2,$p3);
sleep 1;

reset-scroll-region;
show-cursor;
restore-screen;

See the eg/ directory for more examples.

Description

The functions in this module print ANSI escape sequences to stdout. There are functions for cursor movement, scroll regions, colors, and other screen functionality. There aren't functions for any of the esoteric escape codes.

The atomically function suppresses printing, and instead concatenates the output and emits the entire line at the end. This is helpful for multi-threaded situations, where the output of several functions needs to be in one piece.

There is also an OO interface (see the examples).

Functions

atomically(&callable) Combine a series of outputs into one.

bold() Bold (increased intensity)

clear-screen() Clear the screen.

cursor-down($amt = 1) Move cursor down.

cursor-left($amt = 1) Move cursor left.

cursor-off() Turn off cursor (civis).

cursor-on() Turn on cursor (cnorm).

cursor-right($amt = 1) Move cursor right.

cursor-up($amt = 1) Move cursor up.

erase-to-end-of-line() Erase to end of line.

faint() Faint (lower intensity)

hide-cursor() Hide the cursor.

home() Move to home (0,0).

move-to($l, $c = 1) Move the cursor to line, column.

normal-video() Normal video

parse-input($str) Return a description of the given input sequence

print-at($r, $c, $str) Atomic move + print.

reset-scroll-region() Reset the scroll region.

restore-cursor() restore the cursor position.

restore-screen() Restore screen (rmcup).

reverse-video() Reverse video

save-cursor() Save the cursor position.

save-screen() Save screen state (smcup).

scroll-down() Scroll down 1.

scroll-up() Scroll up 1.

set-bg-color($n) Set bg color to $n.

set-fg-color($n) Set fg color to $n.

set-scroll-region($top, $bottom) Set scroll region to top, bottom.

show-cursor() Show the cursor.

start-of-line() Move to start of line.

tget(&callable) Get strings instead of printing them.

Author

Brian Duggan