1a5ae21e4Smrg#!/usr/bin/env perl 204b94745Smrg# $XTermId: bold-italics.pl,v 1.1 2019/09/22 19:44:57 tom Exp $ 3a5ae21e4Smrg# ----------------------------------------------------------------------------- 4a5ae21e4Smrg# this file is part of xterm 5a5ae21e4Smrg# 6a5ae21e4Smrg# Copyright 2019 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# Test bold-italics for single- and double-width characters. 35a5ae21e4Smrg 36a5ae21e4Smrguse strict; 37a5ae21e4Smrguse warnings; 38a5ae21e4Smrg 39a5ae21e4Smrguse I18N::Langinfo qw(langinfo CODESET); 40a5ae21e4Smrg 41a5ae21e4Smrgour $encoding = lc( langinfo( CODESET() ) ); 42a5ae21e4Smrgour $single_text = "ABCDEFGH"; 43a5ae21e4Smrgour $double_text = ""; 44a5ae21e4Smrg 45a5ae21e4Smrgsub showcase($$) { 46a5ae21e4Smrg my $testcase = shift; 47a5ae21e4Smrg my $sgr_code = shift; 48a5ae21e4Smrg printf "\033[%sm", $sgr_code; 49a5ae21e4Smrg printf "%-8s%s\n", $testcase, $single_text; 50a5ae21e4Smrg printf "%-8s%s\n", " ", $double_text if ( $encoding eq "utf-8" ); 51a5ae21e4Smrg printf "\033[%sm", "0"; 52a5ae21e4Smrg} 53a5ae21e4Smrg 54a5ae21e4Smrgsub doit() { 55a5ae21e4Smrg my $bold = "1"; 56a5ae21e4Smrg my $italics = "3"; 57a5ae21e4Smrg &showcase( "Normal", "0" ); 58a5ae21e4Smrg &showcase( "Bold", $bold ); 59a5ae21e4Smrg &showcase( "Italics", $italics ); 60a5ae21e4Smrg &showcase( "Both:BI", "$bold;$italics" ); 61a5ae21e4Smrg} 62a5ae21e4Smrg 63a5ae21e4Smrgif ( $encoding eq "utf-8" ) { 64a5ae21e4Smrg binmode( STDOUT, ":utf8" ); 65a5ae21e4Smrg for my $n ( 0 .. length($single_text) - 1 ) { 66a5ae21e4Smrg my $chr = substr( $single_text, $n, 1 ); 67a5ae21e4Smrg $double_text .= chr( 0xff00 + ord($chr) - 32 ); 68a5ae21e4Smrg } 69a5ae21e4Smrg} 70a5ae21e4Smrg&doit; 71a5ae21e4Smrg 72a5ae21e4Smrg1; 73