You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2011/01/31 12:26:02 UTC

svn commit: r1065564 - in /karaf/trunk: manual/src/main/webapp/developers-guide/branding-console.conf manual/src/main/webapp/developers-guide/index.conf shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java

Author: jbonofre
Date: Mon Jan 31 11:26:02 2011
New Revision: 1065564

URL: http://svn.apache.org/viewvc?rev=1065564&view=rev
Log:
[KARAF-426] Manager Karaf prompt by branding.

Added:
    karaf/trunk/manual/src/main/webapp/developers-guide/branding-console.conf
Modified:
    karaf/trunk/manual/src/main/webapp/developers-guide/index.conf
    karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java

Added: karaf/trunk/manual/src/main/webapp/developers-guide/branding-console.conf
URL: http://svn.apache.org/viewvc/karaf/trunk/manual/src/main/webapp/developers-guide/branding-console.conf?rev=1065564&view=auto
==============================================================================
--- karaf/trunk/manual/src/main/webapp/developers-guide/branding-console.conf (added)
+++ karaf/trunk/manual/src/main/webapp/developers-guide/branding-console.conf Mon Jan 31 11:26:02 2011
@@ -0,0 +1,106 @@
+
+
+h1. Branding the Console
+
+This chapter will guide you how to brand the Karaf console.
+
+By branding, it means that you can define your own welcome message and console prompt.
+
+h2. Create your branding bundle
+
+At startup, Karaf is looking for a bundle which export {{org.apache.karaf.branding}} package containing a {{branding.properties}}
+file.
+
+So you need to create a very simply bundle just containing a {{org/apache/karaf/branding/branding.properties}} file.
+
+The Maven POM of your branding bundle should looks like:
+
+{code:lang=xml}
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>your.group.id</groupId>
+    <artifactId>your.branding.artifact.id</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+    <name>Your Branding Bundle Name</name>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>2.2</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</bundle-SymbolicName>
+                        <Import-Package>*</Import-Package>
+                        <Private-Package>!*</Private-Package>
+                        <Export-Package>
+                            org.apache.karaf.branding
+                        </Export-Package>
+                        <Spring-Context>*;public-context:=false</Spring-Context>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
+{code}
+
+Now, add a {{src/main/resources/org/apache/karaf/branding/branding.properties}} looking like:
+
+{{code}}
+welcome = \
+\u001B[36m        __ __                  ____      \u001B[0m\r\n\
+\u001B[36m       / //_/____ __________ _/ __/      \u001B[0m\r\n\
+\u001B[36m      / ,<  / __ `/ ___/ __ `/ /_        \u001B[0m\r\n\
+\u001B[36m     / /| |/ /_/ / /  / /_/ / __/        \u001B[0m\r\n\
+\u001B[36m    /_/ |_|\\__,_/_/   \\__,_/_/         \u001B[0m\r\n\
+\r\n\
+\u001B[1m  Apache Karaf\u001B[0m (${project.version})\r\n\
+\r\n\
+Hit '\u001B[1m<tab>\u001B[0m' for a list of available commands\r\n\
+   and '\u001B[1m[cmd] --help\u001B[0m' for help on a specific command.\r\n\
+Hit '\u001B[1m<ctrl-d>\u001B[0m' or '\u001B[1mosgi:shutdown\u001B[0m' to shutdown Karaf.\r\n
+
+prompt = \u001B[1m${USER}@${APPLICATION}\u001B[0m>
+{{code}}
+
+As you can see, the {{branding.properties}} contains two properties:
+* welcome is the welcome message displayed when you start Karaf.
+* prompt is the string used to display the console prompt. This string supports variables:
+** ${USER}} defines the user name of the prompt. NB: up to know, it's hard coded to "karaf". However you can define
+your own static user name.
+** ${{APPLICATION}} defines the Karaf instance name.
+
+As you can see, both strings support ASCII escaped format. For instance \u001B[1m switch the foreground in bold and \u001B[0m
+switch back to normal.
+
+Some prompt examples follow:
+
+{code}
+# Define a user with fanzy colors
+prompt = \u001B[36mmy-karaf-user\u001B[0m\u001B[1m@\u001B[0m\u001B[34m${APPLICATION}\u001B[0m>
+{code}
+
+{code}
+# Static sober prompt
+prompt = my-user@my-karaf>
+{code}
+
+h2. Installing the branding bundle
+
+Build your branding bundle:
+
+{code}
+mvn install
+{code}
+
+and simply drop the generated jar file into the Karaf lib directory.
+
+Start Karaf and you will see your branded Karaf console.
\ No newline at end of file

Modified: karaf/trunk/manual/src/main/webapp/developers-guide/index.conf
URL: http://svn.apache.org/viewvc/karaf/trunk/manual/src/main/webapp/developers-guide/index.conf?rev=1065564&r1=1065563&r2=1065564&view=diff
==============================================================================
--- karaf/trunk/manual/src/main/webapp/developers-guide/index.conf (original)
+++ karaf/trunk/manual/src/main/webapp/developers-guide/index.conf Mon Jan 31 11:26:02 2011
@@ -1,5 +1,6 @@
 h1. Developers Guide
 
+* [Branding the Console|branding-console]
 * [Extending the Console|extending-console]
 * [Security Framework|security-framework]
 * [Using features-maven-plugin|features-maven-plugin]

Modified: karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java?rev=1065564&r1=1065563&r2=1065564&view=diff
==============================================================================
--- karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java (original)
+++ karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java Mon Jan 31 11:26:02 2011
@@ -301,7 +301,19 @@ public class Console implements Runnable
             String prompt;
             try {
                 Object p = session.get(PROMPT);
-                prompt = p != null ? p.toString() : DEFAULT_PROMPT;
+                if (p != null) {
+                    prompt = p.toString();
+                } else {
+                    Properties properties = loadBrandingProperties();
+                    if (properties.getProperty("prompt") != null) {
+                        prompt = properties.getProperty("prompt");
+                        // we put the PROMPT in ConsoleSession to avoid to read
+                        // the properties file each time.
+                        session.put(PROMPT, prompt);
+                    } else {
+                        prompt = DEFAULT_PROMPT;
+                    }
+                }
             } catch (Throwable t) {
                 prompt = DEFAULT_PROMPT;
             }