001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package org.apache.geronimo.gshell.branding;
021
022 import java.io.PrintWriter;
023 import java.io.StringWriter;
024
025 import jline.Terminal;
026 import org.apache.geronimo.gshell.ansi.Buffer;
027 import org.apache.geronimo.gshell.ansi.Code;
028 import org.apache.geronimo.gshell.ansi.RenderWriter;
029 import org.codehaus.plexus.component.annotations.Component;
030 import org.codehaus.plexus.component.annotations.Requirement;
031 import org.codehaus.plexus.util.StringUtils;
032
033 /**
034 * Provides the default branding for GShell.
035 *
036 * @version $Rev: 575227 $ $Date: 2007-09-13 01:55:32 -0700 (Thu, 13 Sep 2007) $
037 */
038 @Component(role=Branding.class, hint="default")
039 public class DefaultBranding
040 extends BrandingSupport
041 {
042 @Requirement
043 private VersionLoader versionLoader;
044
045 @Requirement
046 private Terminal terminal;
047
048 public String getName() {
049 return "gshell";
050 }
051
052 public String getDisplayName() {
053 return "GShell";
054 }
055
056 public String getProgramName() {
057 return System.getProperty("program.name", "gsh");
058 }
059
060 public String getAbout() {
061 StringWriter writer = new StringWriter();
062 PrintWriter out = new RenderWriter(writer);
063
064 out.println("For information about @|cyan GShell|, visit:");
065 out.println(" @|bold http://geronimo.apache.org/gshell.html| ");
066 out.flush();
067
068 return writer.toString();
069 }
070
071 public String getVersion() {
072 return versionLoader.getVersion();
073 }
074
075 /*
076 // Figlet font name: ???
077 private static final String[] BANNER = {
078 " ____ ____ _ _ _ ",
079 " / ___/ ___|| |__ ___| | |",
080 " | | _\\___ \\| '_ \\ / _ \\ | |",
081 " | |_| |___) | | | | __/ | |",
082 " \\____|____/|_| |_|\\___|_|_|",
083 };
084 */
085
086 // Figlet font name: Georgia11
087 private static final String[] BANNER = {
088 " ,, ,, ,,",
089 " .g8\"\"\"bgd .M\"\"\"bgd `7MM `7MM `7MM",
090 " .dP' `M ,MI \"Y MM MM MM",
091 " dM' ` `MMb. MMpMMMb. .gP\"Ya MM MM",
092 " MM `YMMNq. MM MM ,M' Yb MM MM",
093 " MM. `7MMF'. `MM MM MM 8M\"\"\"\"\"\" MM MM",
094 " `Mb. MM Mb dM MM MM YM. , MM MM",
095 " `\"bmmmdPY P\"Ybmmd\" .JMML JMML.`Mbmmd'.JMML..JMML."
096 };
097
098 /*
099 // Figlet font name: Georgia11
100 private static final String[] BANNER = {
101 " ,, ,, ,, ..",
102 " .g8\"\"\"bgd .M\"\"\"bgd `7MM `7MM `7MM `bq",
103 " .dP' `M ,MI \"Y MM MM MM YA",
104 " dM' ` `MMb. MMpMMMb. .gP\"Ya MM MM `Mb",
105 " MM `YMMNq. MM MM ,M' Yb MM MM mmmmmmmmm 8M",
106 " MM. `7MMF'. `MM MM MM 8M\"\"\"\"\"\" MM MM 8M",
107 " `Mb. MM Mb dM MM MM YM. , MM MM mmmmmmmmm ,M9",
108 " `\"bmmmdPY P\"Ybmmd\" .JMML JMML.`Mbmmd'.JMML..JMML. dM",
109 " .pY"
110 };
111 */
112
113 public String getWelcomeBanner() {
114 StringWriter writer = new StringWriter();
115 PrintWriter out = new RenderWriter(writer);
116 Buffer buff = new Buffer();
117
118 for (String line : BANNER) {
119 buff.attrib(line, Code.CYAN);
120 out.println(buff);
121 }
122
123 out.println();
124 out.println(" @|bold GShell| (" + getVersion() + ")");
125 out.println();
126 out.println("Type '@|bold help|' for more information.");
127
128 // If we can't tell, or have something bogus then use a reasonable default
129 int width = terminal.getTerminalWidth();
130 if (width < 1) {
131 width = 80;
132 }
133
134 out.print(StringUtils.repeat("-", width - 1));
135
136 out.flush();
137
138 return writer.toString();
139 }
140 }