Accessibility Prototype For The Linux Console (fwd)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This just came up on the blinux list. Thought folks here would like to 
give this a spin, too.

---------- Forwarded message ----------
From: Mike Cross <mrcross@xxxxxxxxxx>

Hello,

  I am writing a console accessability program and am
interested in contributing it to your site.
 The program is a wrapper around three programs two of which
are at http://leb.net and the other at http://metalab.unc.edu.
provides easier useability for three GPL programs. They
They are volume, locktones, and SVGATextMode. I will tar
them up with an install script so nobody has to download
anything e;se and install the pieces.
   Volume controls the volume. Locktones sets up   musical
tones indicating that the user has touched caps lock or
num lock or scroll lock. SVGATextMode installs a font for
the console. Large and small fonts are available. The
program can be invoked from a shell within EMACSPEAK. I
layed out my screens to be readable with the large fonts.
  I also present menus to  change foreground and background
colors via the kernel. So you can see that users with low
vision are considered as well as totally blind users.
The program is in Perl 5. It can be run from EMACSPEAK.
The code is listed below. I'm sure there are many improvements
to be made. Feel free. I thought about making up and down arrow
flush the buffer but I wanted to confine this to the
standard Perl 5 that everyone is likely to have.
----------------------

#!/usr/bin/perl

# Author Michael R  Cross August 31, 2001 11:21 pm
# -e favorite.vol && die( ... );
# This program presents a menu of console mode access
# options. These options are as follows:
#   1. set Defaults
#   2. volume control
#   3. SVGATextMode large fonts
#   4. Locked Tones
#   5. foreground Background color changes
#  NOTES:
# 1. Unpack volume-2.1.tar.gz in /usr/bin
# rpm install locktones
# rpm install SVGATextMode

###############################################
# main  Accessibility For The Linux Console
###############################################
{
# array colors
@colors =
( black, red, green, brown, blue, magenta,  cyan,
  gray, dark_gray, light_red, light_green, yellow,
  light_blue, light_magenta,    light_cyan, white, not_set);
 # end array definition


system("clear");
  print "August 31, 2001  3:35 P M\n";
print "Welcome To the Console Accessibility Tool\n";
print "You should be logged in as root to run this program!\n";
print "if you are not, quit this program and login again.\n";
# print "again.\n\n";

 $ret1 = &catch_your_breath();

do # while
{
print "Main Menu: Select an item & press enter.\n";
print "Your options are\n";
print " 1 for restore all Defaults.\n";
print " 2 for Volume controls.    \n";
  $volume_path ="/bin/volume_2.1";
print " 3 for font menu.         \n";
print " 4 for lock Tones.         \n";
  $tone_path ="/usr/bin";
print " 5 for Foreground Background Changes.\n";
print " 6 for readme text.                   \n";
  $font_path ="/usr/sbin";
print " q to quit this program.\n";
print "Type q or an integer 1 to 6 and press enter now!\n";

 $in_key = <STDIN>;
 chop( $in_key );
   $ret = &strip_white_space();
#  print "in_key is \<$in_key\>\n";
  system( "clear" );

if( $in_key == 1 )
{
  system("locktones" );
  $ret = &small_font();
  $ret = &init_vol();
  print "\033[33;1m\n"; # yellow foreground
  print "\033[40m\n"; # black background
}
elsif( $in_key == 2 )
{
  $ret1 = &change_volume();
}
elsif( $in_key == 3 ) # fonts
{
  # Select from a menu of fonts of different sizes.
  $ret1 = &font_menu();
}
elsif( $in_key == 4 )
{
  # Set tones to sound when you touch caps lock, num lock, & scroll lock.
  system( "clear" );
  print "   Note about locktone:\n";
  print "locktones will play  a tone if you \n";
  print "touch Caps Lock, Num Lock, or Scroll \n";
  print "Lock.\n";
  print "   End Of Note:\n";
  print " Do you want to set up these tones? y/n\n";
  $in_key = <STDIN>;
   $ret = &strip_white_space();
  if(($in_key eq "y") || ($in_key eq "Y"))
  {
    system( "locktones" );
    print "locktones have now been set up.";
  }
  else
  {
    print "locktones were not set up.";
  }
}
elsif( $in_key == 5 ) # background foreground changess
{
  # foreground Background color change tool.
  $ret1 = &change_color_scheme();
}
elsif ($in_key == 6 ) # read me text
{
  # Info about URLs, directories, and installing.
  $ret = &readme();
} # end if select a function

  # elsif( $in_key =~ /\e/ )
} while( $in_key ne "q" );

  $ret = &exit_program();
} # end main program

###############################################
# change_volume
#################################################
sub change_volume
{
  $delta_v = 20; # change per keystroke
  $top_v = 240; # max volume
  system( "clear" );

  $old_v = 50;
   $cannot_open = 0; # false
  unless( open( FAVORITEVOL, "/bin/favorite.vol") ) {
   # die("Cannot open file: /bin/favorite.vol.\n\n");
   $cannot_open = 1; # true
   $ret = &init_vol();
  }

  if( $cannot_open == 0 )
  {
    $old_v = <FAVORITEVOL>;
    chop( $old_v );
    close( FAVORITEVOL );
  } # end if cannot_open == 0

  print "Your current volume setting is $old_v.\n";
  $new_v = $old_v; # starting volume
    $cmd = "volume_path/volume -l ".$new_v." -r ".$new_v;
#    print "cmd is \<$cmd\>.\n";
       system( $cmd ); # execute the command
  $final_change = 0; # false

     print "Volume Control Menu:\n";
     print "To return to the Main Menu press r and\n";
     print "enter. The old volume will be restored.\n";
     print "To rexit the program press q and\n";
     print "enter. The old volume will be restored.\n";
     print "  Each time you press d and enter\n";
     print "the  volume will be decreased.\n";
     print "  Each time you press i and enter\n";
     print "the  volume will be increased.\n";
     print "When finished changing volume press \n";
     print "enter by itself.\n";

  while( $final_change == 0 )
  {
     $in_key = <STDIN>;
     chop( $in_key );
     $ret = &strip_white_space();

#    print "in_key \<$in_key\>\n";

     system( "clear" ); # clear screen
     if( $in_key eq "i")
     {
       $new_v += $delta_v;
       if( $new_v > $top_v )
       {
         $new_v = $top_v;
       }

       print "volume is $new_v.\n";
       $cmd = "/bin/volume-2.1/volume -l ".$new_v." -r ".$new_v;
#    print "cmd is \<$cmd\>\n";
       system( $cmd ); # execute the command
     }
     elsif( $in_key eq "d" )
     {
       $new_v -= $delta_v;
       if( $new_v <  $delta_v )
       {
         $new_v = $delta_v;
       }

       print "volume is $new_v.\n";
       $cmd = "/bin/volume-2.1/volume -l ".$new_v." -r ".$new_v;
#    print "cmd is \<$cmd\>\n";
       system( $cmd ); # execute the command
     }
     elsif( $in_key eq "" ) # enter by itself
     {
       $final_change = 1;
       print "Your Final Volume is $new_v.\n";
       $final_change = 1;

       print "Do you want $new_v to be your volume setting? y/n ";
       $in_key = <STDIN>;
       chop( $in_key );
       $ret = &strip_white_space();
       if(($in_key eq "y") || ($in_key eq "Y"))
       {
         system( "rm /bin/favorite.vol" );
         unless( open( FAVORITEVOL, ">/bin/favorite.vol") ) {
           die("Cannot open file: /bin/favorite.vol!\n\n");
         }
         print FAVORITEVOL "$new_v\n";
         print "Save new volume setting $new_v in /bin/favorite.vol.\n\n";
       } # end if saving new volume setting
     }
     elsif( $in_key eq "r" ) # return to main menu
     {
       $final_change = 1;
       $cmd = "/bin/volume-2.1/volume -l ".$old_v." -r ".$old_v;
       system( $cmd ); # execute the command
     }
     elsif( $in_key eq "q" ) # exit program
     {
       $final_change = 1;
       $cmd = "/bin/volume-2.1/volume -l ".$old_v." -r ".$old_v;
       system( $cmd ); # execute the command
       $ret = &exit_program();
     } # end   volume execute branch
  } # end while not final_change
} # end subroutine change_volume

##############################################
# init_vol initialize volume to 50 and save it
################################################
sub init_vol
{
  system("volume -l 40 -r 40" );
  system("rm /bin/favorite.vol" );

  unless( open( FAVORITEVOL, ">/bin/favorite.vol") ) {
    die("Cannot open file: /bin/favorite.vol!\n\n");
  }
  $new_v = 40;
  print FAVORITEVOL "$delta_v\n";
  print "SavING volume 40 in /bin/favorite.vol.\n\n";
} # end sub routine set_vol

##############################################
# font_menu choice of 5 fonts of dirrerence sizes
###############################################
sub font_menu
{
  $old_f = "80x25";
  $cannot_open == 0; # false
  unless( open( FAVORITEFON, "/usr/sbin/favorite.fon") ) {
   $ret = &small_font();
   $cannot_open == 1; # true
  }

  if( $cannot_open == 0 )
  {
    $old_f = <FAVORITEFON>;
    chop( $old_f );
    close( FAVORITEFON );
  } # end if cannot_open == 0
  system( "SVGATextMode $old_f" );

do # while
{
  system( "clear" );
  print "Current font is $old_f.\n";

  print "Select a font then press enter.\n";
  print "Your options are\n";
  print "1 for the 80x25 font.  \n";
  print "2 for the 40x12x8 font.  \n";
  print "3 for the 40x12x9 font.  \n";
  print "4 for the 40x15x8 font.  \n";
  print "5 for the 40x15x9 font.  \n";
  print "r to  return to Main Menu.\n";
  print "q to  exit the program.\n";
  print "Select an item and press Enter now!\n";
  $in_key = <STDIN>;
  chop( $in_key );
  $ret = &strip_white_space();

    $valid_font = 1; # yes
  if( $in_key == 1 )
  {
    system( "SVGATextMode 80x25" );
    $new_f = "80x25";
  }
  elsif( $in_key == 2 )
  {
    system( "SVGATextMode 40x12x8" );
    $new_f = "40x12x8";
  }
  elsif( $in_key == 3 )
  {
    system( "SVGATextMode 40x12x9" );
    $new_f = "40x12x9";
  }
  elsif( $in_key == 4 )
  {
    system( "SVGATextMode 40x15x8" );
    $new_f = "40x15x8";
  }
  elsif( $in_key == 5 )
  {
    system( "SVGATextMode 40x15x9" );
    $new_f = "40x15x9";
  }
  elsif( $in_key eq "r" ) # return to main menu
  {
    $valid_font = 0; # no
    # system( "SVGATextMode $old_f" );
  }
  elsif( $in_key eq "q" ) # exit program
  {
    $valid_font = 0; # no
    # system( "SVGATextMode $old_f" );
    $ret = &exit_program();
  } # end if pick a new font
  system( "clear" );

  if( $valid_font == 1 )
  {
    print "Do you want $new_f to be your font setting? y/n ";
    $in_key = <STDIN>;
    chop( $in_key );
    $ret = &strip_white_space();
#   print "in_key is \<$in_key\>.n";
    if(($in_key eq "y") || ($in_key eq "Y"))
    {
      system( "rm /usr/sbin/favorite.fon" );
      unless( open( FAVORITEFON, ">/usr/sbin/favorite.fon") ) {
        die("Cannot open file: /usr/sbin/favorite.fon! \n\n");
      }
      print FAVORITEFON "$new_f\n";
      print "Saving new font setting $new_f in /usr/sbin/favorite.fon.\n\n";
      $old_f = $new_f;
    }
    else # do not save new font
    {
      system( "SVGATextMode $old_f" );
    } # end if saving new font setting
  } # end if $valid_font == 1 yes

  system( "clear" );
} while( $in_key ne "r" ); # return to main menu
} # end subroutine font_menu


##############################################
# small_font to 80x25 and save it
################################################
sub small_font
{
  system("SVGATextMode 80x25" );
  # system("rm /usr/sbin/favorite.fon" );

  unless( open( FAVORITEFON, ">/usr/sbin/favorite.fon") ) {
    die("Cannot open file: /usr/sbin/favorite.fon!\n\n");
  }
  print FAVORITEFON "80x25\n";
  print "Save Font 80x25 in /usr/sbin/favorit4.fon.\n\n";
} # end subroutine small_font


##############################################
# readme  show urls and install paths
################################################
sub readme
{
  system("clear" );
 print "Download volume from \n";
 print "   ftp://metalab.unc.edu/pub/Linux/apps/sound/soundcard/.\n";;
  print "When untarred it creates directory      \n";
  print "volume-2.1.   \n";

 print " The URL for locktones & SVGATextmode is:\n";
 print "  http://leb.net/pub/blinux/.\n";;
  print "To install type the following:\n";
 print "   rpm -i SVGATextMode*.rpm and press enter.\n";
 print "   rpm -i locktones*.rpm and press enter.\n";
  print "The SVGATextMode binary will be put at /usr/sbin.\n\n";
  print "The locktones binary will be put in two places:\n";
  print "   /usr/bin and /bin\n\n";
  print "  SVGA Text Mode is very talkative.\n";
  print "In /etc/Textconfig, delete all lines\n";
  print "starting with the word echo.         \n";
  print "  If you start Emacspeak and pick the\n";
  print "option to change colors, the color   \n";
  print "choices are saved in the favorites \n";
  print "files but Emacspeak does not allow   \n";
  print "the colors to actually change. Run   \n";
  print "this outside Emacspeak to see colors \n";
  print "change.          \n";
  print "  If volume is increased beyond 240,\n";
  print "the sound level suddenly drops to 0.\n";
  print "  If you create favorite.vol etc.   \n";
  print "with an editor, make sure each line \n";
  print "ends with a new line character.     \n";
  print "\n Press any key when finished reading.\n";
  $in_key = <STDIN>;
} # end subroutine readme

# ---- foreground background subroutines ----

#################################################
# change_color_scheme
########################################################
sub change_color_scheme
{
  print "Welcome To Foreground Backgroung Change Tool.\n\n";

  do # while
  {
#  system( "clear" );
    print "Main Menu: Foreground Background Change Tool\n";
   print "Your options are\n";
    print "1 to change Foreground color.\n";
    print "2 to change Background color.\n";
    print "3 to restore the default colors.\n";
    print "r to return to Main Menu.\n";
    print "q to quit this program.\n";
    print "Type 1 2 3 r or q and press ENTER now!\n";
    $in_key = <STDIN>;
    chop( $in_key );
    $ret = &strip_white_space();
    if( $in_key == 1 )
    {
      $focus_num = "3"; # foreground 3 is hardcoded
      $focus_word = "foreground";
      $ret1 = &change_foreground();
      system( "clear" );
    }
    elsif( $in_key == 2 )
    {
      $focus_word = "background";
      $focus_num = "4"; # focus is background
      $ret1 = &change_background();
      system( "clear" );
    }
    elsif( $in_key == 3 )
    {
      print "Setting foreground and background\n";
      print "to original colors.         \n";
      system("echo -e \"\033[35;1m Bac to original colors \033[0m\"" );
    } # end if statement
  } while(($in_key ne "r") && ($in_key ne "q"));

 system( "clear" );
 if( $in_key eq "q" )
 {
   $ret = &exit_program();
 }
} # end subroutine change_color_scheme

########################################
# change_foreground
########################################
sub change_foreground
{
  $old_c = "17"; # unknown
  $cannot_open = 0; # false
 unless( open( FAVORITEFG, "/usr/sbin/favorite.fg") ) {
   print "File /usr/sbin/favorite.fg can't be opened!\n";
   $cannot_open = 1; # true
 } # end unless

 if( $cannot_open == 0 )
 {
   $old_c = <FAVORITEFG>;
   chop( $old_c );
   $color = $old_c;
   $ret1 = &set_color();
#  print "old_c \<$old_fg\>.\n";
   close( FAVORITEFG );
 } # end if cannot_open == 0

 system( "clear" );
 print "Current $focus_word is $old_c $colors[$old_c -1].\n";
# print "Press a key to continue.";
# $in_key = <STDIN>;

 $ret1 = &show_color_menu();

 $ret1 = &set_color();

 if( $valid_choice == 1 )
 {
   print "Do you want your $focus_word $colors[$color -1]? y/n ";
   $in_key = <STDIN>;
   chop( $in_key );
   $ret = &strip_white_space();
#  print "in_key is \<$in_key>.\n";
   if(($in_key eq "y") || ($in_key eq "Y"))
   {
     system( "rm  /usr/sbin/favorite.fG" );
   unless( open( FAVORITEFG, ">/usr/sbin/favorite.fg") ) {
      die("Cannot open file: /usr/sbin/favorite.fg!\n\n");
   } # end unless

     print FAVORITEFG "$color\n";
     print "Saving $color $colors[$color -1] $focus_word.\n\n";
   }
   else # no
   {
      $color = $old_c;
      print "Restoring old $focus_word $old_c $colors[$old_fg -1].\n";
      $ret1 = &set_color(); # $old_fg );
   } # end if saving new color setting
 } # end if $valid_choice == 1 yes
} # end subroutine change_foreground


################################################
# set_color of either foreground or background
################################################
sub set_color
{
  # print "\n*** sub change_background ***\n";
  # If $focus_num eq "3", foreground gets set.
  # If $focus_num eq "4", background gets set.

  if((0 < $color) && ($color < 9))
  {
    $n = $color - 1;
    print "\033["."$focus_num"."$n"."m\n";
    $valid_bg = 1; # true
  }
  elsif((8 < $color) && ($color < 17))
  {
    $n = $color - 9;
    print "\033["."$focus_num"."$n".";1m\n";
    $valid_bg = 1; # true
  }
  else
  {
    $valid_bg = 0; # false
  } # end if
} # end subroutine set_color

###############################################
# show_color_menu
###############################################
sub show_color_menu
{
  system( "clear" );
  print "Select a color from 1 to 16 and press Enter.\n";

  # Display color menu on screen.
  for( $j=1 ; $j < 17 ; $j++ )
  {
    print " $j for $colors[$j - 1].\n";
  } # end for loop that prints body of menu
  print "Type an integer from 1 to 16 and press ENTER now!\n";

  $color = <STDIN>;
  chop( $color );
  $color =~ s/^\s+//; # strip lead & trail white space
  $color =~ s/\s+$//;
# $color = substr( $color, 0, 1 );

  if((0 < $color) && ($color < 17) )
  {
    $valid_choice = 1;
  }
  else
  {
    $valid_choice = 0; # false
  }
} # end subroutine show_color_menu


########################################
# change_background
########################################
sub change_background
{
  $old_c = "17"; # unknown
  $cannot_open = 0; # false
 unless( open( FAVORITEBG, "/usr/sbin/favorite.bg") ) {
   print "File /usr/sbin/favorite.bg can't be opened!\n";
   $cannot_open = 1; # true
 } # end unless

 if( $cannot_open == 0 )
 {
   $old_c = <FAVORITEBG>;
   chop( $old_c );
   $color = $old_c;
   $ret1 = &set_color();
   print "old_c \<$old_c\>.\n";
   close( FAVORITEBG );
 } # end if cannot_open == 0

 system( "clear" );
 print "Current $focus_word is $old_c $colors[$old_c -1].\n";

 $ret1 = &show_color_menu();

 $ret1 = &set_color();

 if( $valid_choice == 1 )
 {
   print "Do you want your $focus_word $colors[$color -1]? y/n ";
   $in_key = <STDIN>;
   chop( $in_key );
   $ret = &strip_white_space();
#  print "in_key is \<$in_key>.\n";
   if(($in_key eq "y") || ($in_key eq "Y"))
   {
     system( "rm  /usr/sbin/favorite.fG" );
   unless( open( FAVORITEFG, ">/usr/sbin/favorite.bg") ) {
      die("Cannot open file: /usr/sbin/favorite.bg!\n\n");
   } # end unless

     print FAVORITEBG "$color\n";
     print "Saving $color $colors[$color -1] $focus_word.\n\n";
   }
   else # no
   {
      $color = $old_c;
      print "Restoring old $focus_word $old_c $colors[$old_fg -1].\n";
      $ret1 = &set_color(); # $old_fg );
   } # end if saving new color setting
 } # end if $valid_choice == 1 yes
} # end subroutine change_background

########################################
# catch_your_breath
########################################
sub catch_your_breath
{
  local( $i);

  for( $i = 0 ; $i < 10000 ; $i++ ) {
    $keep_quiet = 1;
  } # end for loop
} # end subroutine catch_your_breath

##########################################################
# strip_white_space
##########################################################
sub strip_white_space
{
   $in_key =~ s/^\s+//; # chop leading white space
   $in_key =~ s/\s+$//; # chop trailing white space
   $in_key = substr( $in_key, 0, 1 ); # reduce to first char only
} # end subroutine strip_white_space


##########################################################
# exit_program prints a message and exits
##########################################################
sub exit_program
{
  print "\n\n\n\nExiting Accessibility Settings For The Linux Console \n";
} # end subroutine exit_program


Michael R. Cross
LTS - Linux Information Development
Mike Cross/Austin/IBM   (mrcross at us.ibm.com)
512-838-0087  / tl 678-0087



_______________________________________________
Blinux-list mailing list
Blinux-list at redhat.com
https://listman.redhat.com/mailman/listinfo/blinux-list





[Index of Archives]     [Linux for the Blind]     [Fedora Discussioin]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]
  Powered by Linux