#!/usr/bin/perl -w use strict; use warnings; # # This a little test program to see what I can do with yad through Perl. # ################################################## my $TEMP_FILE = 'yad_links_289937.tmp'; my $HTML_FILE = 'yad_dialog_289937.htm'; ################################################## CLS(); my $CURDIR = ($^O =~ m/MSWIN|DOS/i) ? `cd` : `pwd`; # Get cur dir if ($^O =~ m/MSWIN|DOS/i) { $CURDIR =~ tr|\\|/|; } # Convert \ to / $CURDIR =~ tr/\x00-\x1F*?|<>//d; print "\nCurrent directory is : $CURDIR"; print "\nWriting html content to $HTML_FILE"; $HTML_FILE =~ tr|/||s; # Remove duplicate // local *OUTFILE; open OUTFILE, ">$HTML_FILE" or die "\nError: Could not create output file - $HTML_FILE\n"; while () { print OUTFILE $_; } close OUTFILE; my $CMD = "yad --html --uri=\"$HTML_FILE\" --print-uri --width=370 --height=470 --center --button=OK:1 --button=Save:2 --buttons-layout=center --title='QR Code Generator' > $TEMP_FILE"; print "\nExecuting : $CMD\n\n"; my $EXITCODE = system($CMD); print "\nExit code = $EXITCODE\n"; ################################################## # This is a quick shortcut to read a file: $ARGV[0] = $TEMP_FILE; print "\nThe following links were clicked in this order : \n\n\t"; while (<>) # Read one line at a time from temp file { my $LINK = ($_ =~ m/link([0-9]+)$/) ? $1 : 0; print " $LINK"; } ################################################## if ($EXITCODE == 2) { print "\nYou pressed Ctrl+C to abort this Perl program.\n"; EXIT(); } if ($EXITCODE == 64512) { print "\nYou closed the window without clicking on OK or SAVE.\n"; EXIT(); } if ($EXITCODE == 256) { print "\n\nOK was clicked\n\nBye!\n"; EXIT(); } if ($EXITCODE == 512) { print "\n\nSAVE button was clicked.\n"; # Saving an XWD snapshot only works on Linux for now. if ($^O =~ m/LINUX/i) { $CMD = 'xwd -silent -screen -root > qr.xwd'; print "\nExecuting : $CMD\n"; system($CMD); } else { print "\nUnfortunately, this feature is not implemented yet."; } } EXIT(); ################################################## sub EXIT { # Cleanup unlink $HTML_FILE; unlink $TEMP_FILE; } ################################################## # Terminal | v2024.4.22 # This function clears the terminal window. # It has been tested on Linux, Windows, DOS, and MacOS. # It may or may not work in other environments. # # Usage: CLS([COLOR]) # sub CLS { if ($^O =~ m/DOS/i) { return system('COMMAND.COM /C CLS'); } if ($^O =~ m/LINUX/i) { return print "\x1Bc\x1B[0m\x1B[3J\x1B[H\x1B[2J"; } if ($^O =~ m/MSWIN/i) { system('CLS'); system('COLOR 07'); return 1; } if ($^O =~ m/DARWIN/i) { return print "\x1B[3J"; } } ################################################## __DATA__