Save This Page
Home » j2ssh-0.2.9-src » com.sshtools.daemon.terminal » [javadoc | source]
    1   /*
    2    *  SSHTools - Java SSH2 API
    3    *
    4    *  Copyright (C) 2002-2003 Lee David Painter and Contributors.
    5    *
    6    *  Contributions made by:
    7    *
    8    *  Brett Smith
    9    *  Richard Pernavas
   10    *  Erwin Bolwidt
   11    *
   12    *  This program is free software; you can redistribute it and/or
   13    *  modify it under the terms of the GNU General Public License
   14    *  as published by the Free Software Foundation; either version 2
   15    *  of the License, or (at your option) any later version.
   16    *
   17    *  This program is distributed in the hope that it will be useful,
   18    *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   19    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20    *  GNU General Public License for more details.
   21    *
   22    *  You should have received a copy of the GNU General Public License
   23    *  along with this program; if not, write to the Free Software
   24    *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   25    */
   26   /**
   27    * SSHTools - Java SSH API The contents of this package has been derived from
   28    * the TelnetD library available from http://sourceforge.net/projects/telnetd
   29    * The original license of the source code is as follows: TelnetD library
   30    * (embeddable telnet daemon) Copyright (C) 2000 Dieter Wimberger This library
   31    * is free software; you can either redistribute it and/or modify it under the
   32    * terms of the GNU Lesser General Public License version 2.1,1999 as
   33    * published by the Free Software Foundation (see copy received along with the
   34    * library), or under the terms of the BSD-style license received along with
   35    * this library.
   36    */
   37   package com.sshtools.daemon.terminal;
   38   
   39   
   40   /**
   41    *
   42    *
   43    * @author $author$
   44    * @version $Revision: 1.12 $
   45    */
   46   public class ColorHelper {
   47       /**  */
   48       public static final String INTERNAL_MARKER = "\001";
   49   
   50       /**  */
   51       public static final int MARKER_CODE = 1;
   52   
   53       /**  */
   54       public static final String BLACK = "S";
   55   
   56       /**  */
   57       public static final String RED = "R";
   58   
   59       /**  */
   60       public static final String GREEN = "G";
   61   
   62       /**  */
   63       public static final String YELLOW = "Y";
   64   
   65       /**  */
   66       public static final String BLUE = "B";
   67   
   68       /**  */
   69       public static final String MAGENTA = "M";
   70   
   71       /**  */
   72       public static final String CYAN = "C";
   73   
   74       /**  */
   75       public static final String white = "W";
   76   
   77       /**  */
   78       public static final String BOLD = "f";
   79   
   80       /**  */
   81       public static final String BOLD_OFF = "d"; //normal color or normal intensity
   82   
   83       /**  */
   84       public static final String ITALIC = "i";
   85   
   86       /**  */
   87       public static final String ITALIC_OFF = "j";
   88   
   89       /**  */
   90       public static final String UNDERLINED = "u";
   91   
   92       /**  */
   93       public static final String UNDERLINED_OFF = "v";
   94   
   95       /**  */
   96       public static final String BLINK = "e";
   97   
   98       /**  */
   99       public static final String BLINK_OFF = "n";
  100   
  101       /**  */
  102       public static final String RESET_ALL = "a";
  103   
  104       /**
  105    *
  106    *
  107    * @param str
  108    * @param color
  109    *
  110    * @return
  111    */
  112       public static String colorizeText(String str, String color) {
  113           return INTERNAL_MARKER + color + str + INTERNAL_MARKER + RESET_ALL;
  114       }
  115   
  116       //colorizeText
  117       public static String colorizeBackground(String str, String color) {
  118           return INTERNAL_MARKER + color.toLowerCase() + str + INTERNAL_MARKER +
  119           RESET_ALL;
  120       }
  121   
  122       //colorizeBackground
  123       public static String colorizeText(String str, String fgc, String bgc) {
  124           return INTERNAL_MARKER + fgc + INTERNAL_MARKER + bgc.toLowerCase() +
  125           str + INTERNAL_MARKER + RESET_ALL;
  126       }
  127   
  128       //colorizeText
  129       public static String boldcolorizeText(String str, String color) {
  130           return INTERNAL_MARKER + BOLD + INTERNAL_MARKER + color + str +
  131           INTERNAL_MARKER + RESET_ALL;
  132       }
  133   
  134       //colorizeBoldText
  135       public static String boldcolorizeText(String str, String fgc, String bgc) {
  136           return INTERNAL_MARKER + BOLD + INTERNAL_MARKER + fgc +
  137           INTERNAL_MARKER + bgc.toLowerCase() + str + INTERNAL_MARKER +
  138           RESET_ALL;
  139       }
  140   
  141       //colorizeBoldText
  142       public static String boldText(String str) {
  143           return INTERNAL_MARKER + BOLD + str + INTERNAL_MARKER + BOLD_OFF;
  144       }
  145   
  146       //boldText
  147       public static String italicText(String str) {
  148           return INTERNAL_MARKER + ITALIC + str + INTERNAL_MARKER + ITALIC_OFF;
  149       }
  150   
  151       //italicText
  152       public static String underlinedText(String str) {
  153           return INTERNAL_MARKER + UNDERLINED + str + INTERNAL_MARKER +
  154           UNDERLINED_OFF;
  155       }
  156   
  157       //underlinedText
  158       public static String blinkingText(String str) {
  159           return INTERNAL_MARKER + BLINK + str + INTERNAL_MARKER + BLINK_OFF;
  160       }
  161   
  162       //blinkingText
  163       public static long getVisibleLength(String str) {
  164           int counter = 0;
  165           int parsecursor = 0;
  166           int foundcursor = 0;
  167           boolean done = false;
  168   
  169           while (!done) {
  170               foundcursor = str.indexOf(MARKER_CODE, parsecursor);
  171   
  172               if (foundcursor != -1) {
  173                   //increment counter
  174                   counter++;
  175   
  176                   //parseon from the next char
  177                   parsecursor = foundcursor + 1;
  178               } else {
  179                   done = true;
  180               }
  181           }
  182   
  183           return (str.length() - (counter * 2));
  184       }
  185   
  186       //getVisibleLength
  187   }
  188   
  189   
  190   //class ColorHelper

Save This Page
Home » j2ssh-0.2.9-src » com.sshtools.daemon.terminal » [javadoc | source]