#!/usr/bin/env perl use strict; use warnings; use Curses; my $CENTERIMAGE = 0; # ASCII art to display my $art = <<'ASCII_ART'; _______ / \ | | | | \_______/ ASCII_ART # Initialize Curses initscr(); # Initialize screen / Start curses mode noecho(); # Don't echo (display) characters typed by the user cbreak(); # Line buffering disabled, Pass on keypad(1); # It enables the reading of function keys like F1, F2, arrow keys etc. curs_set(0); # Hide the active cursor # Get terminal dimensions my $rows; my $cols; getmaxyx(stdscr(), $rows, $cols); # Calculate the center position for displaying the ASCII art my @parts = split/\n/, $art; my $linecount = scalar @parts; my $rowcount = 0; foreach my $part (@parts) { if(length($part) > $rowcount) { $rowcount = length($part); } } my ($xoffs, $yoffs); if($CENTERIMAGE) { # Center $xoffs = int(($cols - $rowcount) / 2); $yoffs = int(($rows - $linecount) / 2); } else { # Lower right $xoffs = int(($cols - $rowcount)); $yoffs = int(($rows - $linecount)); } clear(); # Clear the screen # Display the ASCII art for(my $i = 0; $i < $linecount; $i++) { move($yoffs + $i, $xoffs); addstr($parts[$i]); } refresh(); # Refresh the screen (e.g. actually put what we have drawn into the terminal) getch(); # Wait for a keypress endwin(); # Exit curses mode