1a5ae21e4Smrg#!/usr/bin/env perl 204b94745Smrg# $XTermId: under-latin.pl,v 1.6 2020/01/31 00:16:52 tom Exp $ 3a5ae21e4Smrg# ----------------------------------------------------------------------------- 4a5ae21e4Smrg# this file is part of xterm 5a5ae21e4Smrg# 6a5ae21e4Smrg# Copyright 2020 by Thomas E. Dickey 7a5ae21e4Smrg# 8a5ae21e4Smrg# All Rights Reserved 9a5ae21e4Smrg# 10a5ae21e4Smrg# Permission is hereby granted, free of charge, to any person obtaining a 11a5ae21e4Smrg# copy of this software and associated documentation files (the 12a5ae21e4Smrg# "Software"), to deal in the Software without restriction, including 13a5ae21e4Smrg# without limitation the rights to use, copy, modify, merge, publish, 14a5ae21e4Smrg# distribute, sublicense, and/or sell copies of the Software, and to 15a5ae21e4Smrg# permit persons to whom the Software is furnished to do so, subject to 16a5ae21e4Smrg# the following conditions: 17a5ae21e4Smrg# 18a5ae21e4Smrg# The above copyright notice and this permission notice shall be included 19a5ae21e4Smrg# in all copies or substantial portions of the Software. 20a5ae21e4Smrg# 21a5ae21e4Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 22a5ae21e4Smrg# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23a5ae21e4Smrg# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24a5ae21e4Smrg# IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 25a5ae21e4Smrg# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 26a5ae21e4Smrg# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27a5ae21e4Smrg# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28a5ae21e4Smrg# 29a5ae21e4Smrg# Except as contained in this notice, the name(s) of the above copyright 30a5ae21e4Smrg# holders shall not be used in advertising or otherwise to promote the 31a5ae21e4Smrg# sale, use or other dealings in this Software without prior written 32a5ae21e4Smrg# authorization. 33a5ae21e4Smrg# ----------------------------------------------------------------------------- 34a5ae21e4Smrg# Print a text-test pattern using Latin-1 characters that have these features: 35a5ae21e4Smrg# a) accents 36a5ae21e4Smrg# b) descenders 37a5ae21e4Smrg# c) underlining 38a5ae21e4Smrg 39a5ae21e4Smrguse strict; 40a5ae21e4Smrguse warnings; 41a5ae21e4Smrg 42a5ae21e4Smrguse Getopt::Std; 43a5ae21e4Smrguse Term::ReadKey; 44a5ae21e4Smrg 45a5ae21e4Smrg$| = 1; 46a5ae21e4Smrg 47a5ae21e4Smrgour ( $opt_b, $opt_i, $opt_u ); 48a5ae21e4Smrg 49a5ae21e4Smrgour $ROWS = 24; 50a5ae21e4Smrgour $COLS = 4; 51a5ae21e4Smrg 52a5ae21e4Smrgour @sample; 53a5ae21e4Smrg 54a5ae21e4Smrgsub underlined($$) { 55a5ae21e4Smrg my $text = shift; 56a5ae21e4Smrg my $code = shift; 57a5ae21e4Smrg $text = sprintf "\033[4m%s\033[24m", $text if ($code); 58a5ae21e4Smrg return $text; 59a5ae21e4Smrg} 60a5ae21e4Smrg 61a5ae21e4Smrgsub print_row($) { 62a5ae21e4Smrg my $y = shift; 63a5ae21e4Smrg my $cells = $y * 5; 64a5ae21e4Smrg for my $x ( 0 .. $COLS ) { 65a5ae21e4Smrg printf "%s", 66a5ae21e4Smrg &underlined( $sample[ $cells % 2 ], ( $cells % 4 ) > 1 ? 1 : 0 ); 67a5ae21e4Smrg ++$cells; 68a5ae21e4Smrg } 69a5ae21e4Smrg} 70a5ae21e4Smrg 71a5ae21e4Smrgsub main::HELP_MESSAGE() { 72a5ae21e4Smrg printf STDERR <<EOF 73a5ae21e4SmrgUsage: $0 [options] 74a5ae21e4Smrg 75a5ae21e4SmrgOptions: 76a5ae21e4Smrg 77a5ae21e4Smrg-b write a pattern in bold-text 78a5ae21e4Smrg-i write a pattern in italic-text 79a5ae21e4Smrg-u write text in UTF-8 80a5ae21e4SmrgEOF 81a5ae21e4Smrg ; 82a5ae21e4Smrg exit; 83a5ae21e4Smrg} 84a5ae21e4Smrg 85a5ae21e4Smrg$Getopt::Std::STANDARD_HELP_VERSION = 1; 86a5ae21e4Smrg&getopts('biu') || &main::HELP_MESSAGE; 87a5ae21e4Smrg 88a5ae21e4Smrgif ( -t 0 ) { 89a5ae21e4Smrg my $size = `stty size`; 90a5ae21e4Smrg chomp $size; 91a5ae21e4Smrg if ( $size =~ /^\d+\s+\d+$/ ) { 92a5ae21e4Smrg my @size = split /\s+/, $size; 93a5ae21e4Smrg $ROWS = $size[0]; 94a5ae21e4Smrg $COLS = $size[1] - 4; 95a5ae21e4Smrg $COLS /= 2 if ( $opt_b or $opt_i ); 96a5ae21e4Smrg $COLS /= 7; 97a5ae21e4Smrg $COLS = int($COLS) - 1; 98a5ae21e4Smrg } 99a5ae21e4Smrg} 100a5ae21e4Smrg 101a5ae21e4Smrgbinmode( STDOUT, ":utf8" ) if ($opt_u); 102a5ae21e4Smrg 103a5ae21e4Smrg$sample[0] = sprintf "%c%c%c%c%c%c%c", 192, 193, 194, 195, 196, 197, 198; 104a5ae21e4Smrg$sample[1] = sprintf "gjpqy%c%c", 199, 255; 105a5ae21e4Smrg 106a5ae21e4Smrgfor my $y ( 0 .. ( $ROWS - 1 ) ) { 107a5ae21e4Smrg printf "%3d ", $y + 1; 108a5ae21e4Smrg printf "\033[1m" if ( $opt_b and $opt_i ); 109a5ae21e4Smrg &print_row($y); 110a5ae21e4Smrg printf "\033[22m" if ( $opt_b and $opt_i ); 111a5ae21e4Smrg if ( $opt_b or $opt_i ) { 112a5ae21e4Smrg printf "\033[%dm", $opt_i ? 3 : 1; 113a5ae21e4Smrg &print_row($y); 114a5ae21e4Smrg printf "\033[%dm", $opt_i ? 23 : 22; 115a5ae21e4Smrg } 116a5ae21e4Smrg printf "\n" unless ( $y + 1 >= $ROWS ); 117a5ae21e4Smrg} 118a5ae21e4Smrg 119a5ae21e4Smrgif ( -t 1 ) { 120a5ae21e4Smrg printf "\033[m"; 121a5ae21e4Smrg ReadMode 'cbreak'; 122a5ae21e4Smrg my $key = ReadKey(30); 123a5ae21e4Smrg ReadMode 'normal'; 124a5ae21e4Smrg} 125a5ae21e4Smrgprintf "\n"; 126a5ae21e4Smrg 127a5ae21e4Smrg1; 128