Use right prompt only when the terminal supports 256 colors Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/604da250 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/604da250 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/604da250
Branch: refs/heads/master Commit: 604da2501da98b74844eada8194bab1ab1aaef6c Parents: 0ee2e63 Author: Guillaume Nodet <[email protected]> Authored: Wed Dec 7 16:38:13 2016 +0100 Committer: Guillaume Nodet <[email protected]> Committed: Thu Dec 8 18:05:25 2016 +0100 ---------------------------------------------------------------------- .../main/resources/resources/etc/shell.init.script | 11 ++++++++--- .../karaf/shell/impl/console/ConsoleSessionImpl.java | 14 ++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/604da250/assemblies/features/base/src/main/resources/resources/etc/shell.init.script ---------------------------------------------------------------------- diff --git a/assemblies/features/base/src/main/resources/resources/etc/shell.init.script b/assemblies/features/base/src/main/resources/resources/etc/shell.init.script index 382c759..f8076c3 100644 --- a/assemblies/features/base/src/main/resources/resources/etc/shell.init.script +++ b/assemblies/features/base/src/main/resources/resources/etc/shell.init.script @@ -40,9 +40,14 @@ prompt = "[1m${USER}[0m@${APPLICATION}(${SUBSHELL})> " __load_class = { (($.reader class) classLoader) loadClass $1 } -__rprompt_formatter = (((__load_class java.text.SimpleDateFormat) getConstructor (__load_class java.lang.String)) newInstance \'$'\u001B\[90m'\'HH:mm:ss) -__date_class = (__load_class java.util.Date) -\#rprompt = { $__rprompt_formatter format ($__date_class newInstance) } + +# On 256 colors terminal, add a right prompt +max_colors = ($.jline.terminal getNumericCapability max_colors) +if { %(max_colors >= 256) } { + __rprompt_formatter = (((__load_class java.text.SimpleDateFormat) getConstructor (__load_class java.lang.String)) newInstance \'$'\u001B\[90m'\'HH:mm:ss) + __date_class = (__load_class java.util.Date) + \#rprompt = { $__rprompt_formatter format ($__date_class newInstance) } +} setopt group keymap "^[OA" up-line-or-search http://git-wip-us.apache.org/repos/asf/karaf/blob/604da250/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java ---------------------------------------------------------------------- diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java index fcd29be..970668c 100644 --- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java +++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java @@ -621,12 +621,14 @@ public class ConsoleSessionImpl implements Session { } catch (Throwable t) { prompt = def; } - Matcher matcher = Pattern.compile("\\$\\{([^}]+)\\}").matcher(prompt); - while (matcher.find()) { - Object rep = session.get(matcher.group(1)); - if (rep != null) { - prompt = prompt.replace(matcher.group(0), rep.toString()); - matcher.reset(prompt); + if (prompt != null) { + Matcher matcher = Pattern.compile("\\$\\{([^}]+)\\}").matcher(prompt); + while (matcher.find()) { + Object rep = session.get(matcher.group(1)); + if (rep != null) { + prompt = prompt.replace(matcher.group(0), rep.toString()); + matcher.reset(prompt); + } } } return prompt;
