#1847 fanline

kaushik Mon 19 Mar 2012

Continuing Alex's tip on http://fantom.org/sidewalk/topic/1818 , I created Fanline which executes Shell commands using JLine providing arrow keys and other cool shell commands support. fanline.pod .

Run using

fan fanline

Edit: updated pod location

brian Mon 19 Mar 2012

Hi @kaushik,

What version of JLine did you pull for that? Googling around looks like Jline is released under BSD, so we could bundle that into the core. Your fanline.pod is only 186KB, so if that is a complete working solution seems like we could just always include it as part of core. Guess we'd have to think how it got created as a reusable API though (beyond just better fansh).

kaushik Tue 20 Mar 2012

Hi brian,

I just pulled the latest version and built it.I guess it's 2.7.

The code seems to work fine for me (Mac 10.6.8), though, since jline uses native code, it would make sense to have input from others too before including it in the core.

fanline.pod is complete in itself (includes the jline.jar within it)

The code itself just uses jline for input and forwards it to fansh::Shell.

Edit: Fixed a few bugs and updated fanline.pod location. Tested on mac and RHL.

Xan Fri 23 Mar 2012

Is this related about my question Can you explain a little bit? If this will it merge to main fantom branch?

Thanks,

kaushik Fri 23 Mar 2012

Yes. Thanks for you question and alex's tip on using fanline. I've always faced that problem and then lazily ignored it until I came across your post a couple of days ago:)

Can you explain a little bit?

Well, the code uses the current fansh code except the line input. which is done using Jline.

If this will it merge to main fantom branch?

I think brian wanted the same. Can you test it and see if it works fine for you? plus I'vent test this on any windows box? Checkout, build and run

fan fanline

We can refactor it a little bit if this will replace fansh.

Edit: Updated more info

Xan Sat 24 Mar 2012

I want to test it but I receive this error:

xan@gerret:~/proves/fantom-proves/fanline/fanline$ fan build.fan 
compile [fanline]
  Compile [fanline]
    FindSourceFiles [2 files]
    WritePod [file:/home/xan/bin/fantom/fantom/lib/fan/fanline.pod]
  javaNative [fanline]
ERR: Invalid configDir URI for 'jdkHome': /C:/Program Files/Java/jdk1.6.0_21/
  sys::Err
ERR: Must config build prop 'jdkHome'
BUILD FAILED [270ms]!

What can I do?

kaushik Sat 24 Mar 2012

Since it includes native you need to set etc/build/config.props to correct jdk path. Alternatively just download the pod from here

Xan Sat 24 Mar 2012

Thanks. But what how can I set to linux? There is no line for that! How can I know where is my jdkHome in linux?

Xan Sat 24 Mar 2012

In ubuntu 11.10 the jdkhome is

jdkHome=/usr/lib/jvm/java-6-openjdk/

brian, can you put this line in etc/build/config.prop? with

//GNU/Linux setup

With this, I could compile it:

$ fan build.fan 
compile [fanline]
  Compile [fanline]
    FindSourceFiles [2 files]
     WritePod [file:/home/xan/bin/fantom/fantom/lib/fan/fanline.pod]
  javaNative [fanline]
    Exec [/usr/lib/jvm/java-6-openjdk/bin/java -cp /home/xan/bin/fantom/fantom /lib/java/sys.jar -Dfan.home=/home/xan/bin/fantom/fantom fanx.tools.Jstub -d  /home/xan/proves/fantom-proves/fanline/fanline/temp-java fanline]
     Java Stub [fanline]
     CompileJava
    Exec [/usr/lib/jvm/java-6-openjdk/bin/jar -xf /home/xan/proves/fantom-proves/fanline/fanline/temp-java/fanline.jar]
    Delete [file:/home/xan/proves/fantom-proves/fanline/fanline/temp-java/fanline.jar]
    Delete [file:/home/xan/proves/fantom-proves/fanline/fanline/temp-java/meta-inf/]
    Exec [/usr/lib/jvm/java-6-openjdk/bin/jar -fu /home/xan/bin/fantom/fantom/lib/fan/fanline.pod -C /home/xan/proves/fantom-proves/fanline/fanline/temp-java .]
    Delete [file:/home/xan/proves/fantom-proves/fanline/fanline/temp-java/]
Exec [/usr/lib/jvm/java-6-openjdk/bin/jar -xf /home/xan/proves/fantom-proves/fanline/fanline/jars/jline.jar]
Exec [/usr/lib/jvm/java-6-openjdk/bin/jar -xf /home/xan/bin/fantom/fantom/lib/fan/fanline.pod]
Exec [/usr/lib/jvm/java-6-openjdk/bin/jar -fu /home/xan/bin/fantom/fantom/lib/fan/fanline.pod -C /home/xan/proves/fantom-proves/fanline/fanline/temp-java .]
Delete [file:/home/xan/proves/fantom-proves/fanline/fanline/temp-java/]
BUILD SUCCESS [5825ms]!

Thanks,

Xan Sat 24 Mar 2012

And yes, it works propoerly.

I use Ubuntu 11.10 in eeepc

kaushik Sat 24 Mar 2012

cool. Do you have access to a windows box too? I am just figuring out if this can be a drop in replacement for fansh.

Xan Sat 24 Mar 2012

Not, I don't have windows. I leave long time ago. Sorry. Cool if this is a replacement for fansh.

KevinKelley Sat 24 Mar 2012

Without actually trying to figure it out... just grabbed the pod and tried to fire it up and got this

C:\Users\Kevin
>fan fanline
java.lang.NoClassDefFoundError: Could not initialize class org.fusesource.jansi.
internal.Kernel32
        at org.fusesource.jansi.internal.WindowsSupport.getConsoleMode(WindowsSu
pport.java:50)
        at jline.WindowsTerminal.getConsoleMode(WindowsTerminal.java:176)
        at jline.WindowsTerminal.init(WindowsTerminal.java:80)
        at jline.TerminalFactory.create(TerminalFactory.java:93)
        at jline.TerminalFactory.get(TerminalFactory.java:151)
        at jline.console.ConsoleReader.<init>(ConsoleReader.java:162)
        at jline.console.ConsoleReader.<init>(ConsoleReader.java:137)
        at fan.fanline.CommandLinePeer.start(CommandLinePeer.java:22)
        at fan.fanline.CommandLine.start(CommandLine.fan)
        at fan.fanline.CommandLine.run(CommandLine.fan:12)
        at fan.fanline.Main.main(Main.fan:3)
...

cloning, now, from hg.

Login or Signup to reply.