karaf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Baptiste Onofré ...@nanthrax.net>
Subject Re: how to get Karaf's terminal width?
Date Wed, 07 Dec 2016 18:19:51 GMT
Hi Max,

AFAIR, the Session should contain the width. Let me check.

Regards
JB

On 12/07/2016 07:16 PM, Max Spring wrote:
> Is there a way to get the actual jline terminal object in a Karaf command?
> I want to format the command output depending on the terminal width.
> I'm on Ubuntu 16.04, Java 1.8.0_60-x64, and Karaf 3.0.5.
>
> This one
>
>   package org.example;
>
>   import jline.TerminalFactory;
>   import org.apache.karaf.shell.commands.Command;
>   import org.apache.karaf.shell.console.OsgiCommandSupport;
>
>   @Command(scope = "example", name = "term-wdith", description = "get
> the terminal width")
>   public class TermWidthCmd extends OsgiCommandSupport{
>
>       protected Object doExecute() throws Exception {
>           int w = TerminalFactory.get().getTerminalWidth();
>
>           return null;
>       }
>   }
>
> gives:
>
> | 2016-12-07 10:10:17,443 | ERROR | l for user karaf |
> ShellUtil                        | 27 - org.apache.karaf.shell.console -
> 3.0.5 | Exception caught while executing command
> | java.lang.IncompatibleClassChangeError: Found interface
> jline.Terminal, but class was expected
> |     at org.example.TermWidthCmd.doExecute(TermWidthCmd.java:11)
> |     at
> org.apache.karaf.shell.console.AbstractAction.execute(AbstractAction.java:33)
>
> |     at
> org.apache.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:39)
>
> |     at
> org.apache.karaf.shell.commands.basic.AbstractCommand.execute(AbstractCommand.java:33)
>
> |     at Proxy68e7a8f7_5f52_4001_8cfa_f4b37a3fc958.execute(Unknown Source)
> |     at Proxy68e7a8f7_5f52_4001_8cfa_f4b37a3fc958.execute(Unknown Source)
> |     at
> org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:78)
> |     at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)
> |     at
> org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)
> |     at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
> |     at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)
> |     at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)
> |     at
> org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)
>
> |     at
> org.apache.karaf.shell.console.impl.jline.ConsoleImpl.run(ConsoleImpl.java:210)
>
> |     at
> org.apache.karaf.shell.console.impl.jline.LocalConsoleManager$2$1$1.run(LocalConsoleManager.java:109)
>
> |     at java.security.AccessController.doPrivileged(Native
> Method)[:1.8.0_60]
> |     at
> org.apache.karaf.jaas.modules.JaasHelper.doAs(JaasHelper.java:57)[28:org.apache.karaf.jaas.modules:3.0.5]
>
> |     at
> org.apache.karaf.shell.console.impl.jline.LocalConsoleManager$2$1.run(LocalConsoleManager.java:102)[27:org.apache.karaf.shell.console:3.0.5]
>
>
> The 2nd approach
>
>   package org.example;
>
>   import jline.NoInterruptUnixTerminal;
>   import jline.Terminal;
>   import org.apache.karaf.shell.commands.Command;
>   import org.apache.karaf.shell.console.OsgiCommandSupport;
>
>   @Command(scope = "example", name = "term-wdith", description = "get
> the terminal width")
>   public class TermWidthCmd extends OsgiCommandSupport{
>
>       protected Object doExecute() throws Exception {
>           Terminal term = session != null ? (Terminal)
> session.get(".jline.terminal") : null;
>           NoInterruptUnixTerminal uterm = (NoInterruptUnixTerminal)term;
>           int w = term.getTerminalWidth();
>
>           return null;
>       }
>   }
>
> basically gives the same exception:
>
> | 2016-12-07 10:09:11,964 | ERROR | l for user karaf |
> ShellUtil                        | 27 - org.apache.karaf.shell.console -
> 3.0.5 | Exception caught while executing command
> | java.lang.IncompatibleClassChangeError: Found interface
> jline.Terminal, but class was expected
> |     at org.example.TermWidthCmd.doExecute(TermWidthCmd.java:14)
> |     at
> org.apache.karaf.shell.console.AbstractAction.execute(AbstractAction.java:33)
>
> |     at
> org.apache.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:39)
>
> |     at
> org.apache.karaf.shell.commands.basic.AbstractCommand.execute(AbstractCommand.java:33)
>
> |     at Proxy1c55bc35_2cb4_47b2_b9f4_f593e49a68ce.execute(Unknown Source)
> |     at Proxy1c55bc35_2cb4_47b2_b9f4_f593e49a68ce.execute(Unknown Source)
> |     at
> org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:78)
> |     at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)
> |     at
> org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)
> |     at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
> |     at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)
> |     at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)
> |     at
> org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)
>
> |     at
> org.apache.karaf.shell.console.impl.jline.ConsoleImpl.run(ConsoleImpl.java:210)
>
> |     at
> org.apache.karaf.shell.console.impl.jline.LocalConsoleManager$2$1$1.run(LocalConsoleManager.java:109)
>
> |     at java.security.AccessController.doPrivileged(Native
> Method)[:1.8.0_60]
> |     at
> org.apache.karaf.jaas.modules.JaasHelper.doAs(JaasHelper.java:57)[28:org.apache.karaf.jaas.modules:3.0.5]
>
> |     at
> org.apache.karaf.shell.console.impl.jline.LocalConsoleManager$2$1.run(LocalConsoleManager.java:102)[27:org.apache.karaf.shell.console:3.0.5]
>
>
> What am I missing?
>
> Thanks!
> -Max
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Mime
View raw message