Spring Roo
  1. Spring Roo
  2. ROO-350

Color shell support for Windows users

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: None
    • Fix Version/s: 1.0.0.RC3
    • Component/s: @ ROO SHELL
    • Labels:
      None
    • Environment:
      Windows

      Description

      I've added support for colors in a Windows command prompt using a third party library called Jansi (http://jansi.fusesource.org). This library (APL-licensed) can wrap an OutputStream to parse ANSI escape codes and translates them to Windows native calls. It uses another library to make the native calls, called JNA (https://jna.dev.java.net) which is LGPL-licensed.

      I've attached a patch against trunk that uses Jansi on Windows if it's available: since it's trivial to use this without adding compile- nor runtime-time dependencies I've done so. Just by adding jansi-1.0.jar and jna.jar to your roo lib-dir you get coloring.

      I noticed that the colors are quite dark: this is not a problem with light backgrounds, but I found it a bit hard to read on black backgrounds. I've therefore also added support for using bright foreground colors to Roo: just add a system property currently called 'roo.bright' (feel free to rename it or change it to a proper cmd line param) and set it to 'true' to get brighter colors. This is not Windows-specific, it uses regular ANSI codes. See the patch for details. You could consider setting it to true by default in roo.bat for Windows users, although the bright green on my WinXP SP3 machine is almost white in cmd.exe (but not in command.com for some weird reason).

      Only slight downside is that colors on Windows are not restored after quitting the shell. Shouldn't even be noticeable for most users, but I have created a fix for this as well. Unfortunately that requires a small patch to the Jansi library: I'll see if I can get the author to publish a new version. It's done by closing the wrapped OutputStream, so the Roo code works the same with or without the fix present in the ansi jar.

      I'll leave it up to you to decide if you want to/can ship with the jansi and jna jars by default (esp. given the LGPL-license of jna), or if you just want to provide instructions on how to add these for users. Since the code compiles and runs without jansi, they just have to put the jars in the lib-dir.

      1. roo-colors.patch
        7 kB
        Joris Kuipers
      2. WindowsTerminal.java
        17 kB
        Joris Kuipers
      1. scren_shot.png
        46 kB

        Issue Links

          Activity

          Hide
          Joris Kuipers added a comment -

          Since I don't have time to actively participate in the JLine project and my patch is a trivial one (it's not like they can't commit it themselves), I propose that we simply put my patched version in our EBR instead of the regular build for now, using a version qualifier to show that this concerns a patched version. I went through the JLine user list, and I don't think that they're planning a new release anytime soon, so even if I could get my patch in there it still wouldn't provide us with a usable artifact provided by the JLine team.
          The jar I attached to this issue can be used as-is for that, apart from the fact that I didn't update the MANIFEST.MF to reflect a new version qualifier that we might want to introduce.

          Show
          Joris Kuipers added a comment - Since I don't have time to actively participate in the JLine project and my patch is a trivial one (it's not like they can't commit it themselves), I propose that we simply put my patched version in our EBR instead of the regular build for now, using a version qualifier to show that this concerns a patched version. I went through the JLine user list, and I don't think that they're planning a new release anytime soon, so even if I could get my patch in there it still wouldn't provide us with a usable artifact provided by the JLine team. The jar I attached to this issue can be used as-is for that, apart from the fact that I didn't update the MANIFEST.MF to reflect a new version qualifier that we might want to introduce.
          Hide
          Ben Alex added a comment -

          No problem. I've added https://issuetracker.springsource.com/browse/EBR-539 to get the current patched JLine into EBR.

          Show
          Ben Alex added a comment - No problem. I've added https://issuetracker.springsource.com/browse/EBR-539 to get the current patched JLine into EBR.
          Hide
          Joris Kuipers added a comment -

          I've opened another issue against Jansi that will ensure that consoles using non-default foreground and background colors will work properly as well:
          http://fusesource.com/issues/browse/JANSI-5
          I might make a patched Jansi version available in my plugin zip.

          Show
          Joris Kuipers added a comment - I've opened another issue against Jansi that will ensure that consoles using non-default foreground and background colors will work properly as well: http://fusesource.com/issues/browse/JANSI-5 I might make a patched Jansi version available in my plugin zip.
          Hide
          Joris Kuipers added a comment -

          Roo now uses a private external repository that contains a patched jline version that allows the WindowsTerminal class to be subclassed for ANSI support. I've also changed my plugin to use a Jansi 1.1-SNAPSHOT version that includes my JANSI-4 and JANSI-5 patches that have both been committed by the Jansi team.
          That pretty much completes the support for colors in the Windows shell! When a Jansi-1.1 final release becomes available I'll switch to that.

          Show
          Joris Kuipers added a comment - Roo now uses a private external repository that contains a patched jline version that allows the WindowsTerminal class to be subclassed for ANSI support. I've also changed my plugin to use a Jansi 1.1-SNAPSHOT version that includes my JANSI-4 and JANSI-5 patches that have both been committed by the Jansi team. That pretty much completes the support for colors in the Windows shell! When a Jansi-1.1 final release becomes available I'll switch to that.
          Hide
          Joris Kuipers added a comment -

          Roo now ships with EBR bundle versions of Jansi 1.1 and JNA 3.2.3 for native Windows color support that no longer requires an addon to be installed (since SVN Rev 506).

          Show
          Joris Kuipers added a comment - Roo now ships with EBR bundle versions of Jansi 1.1 and JNA 3.2.3 for native Windows color support that no longer requires an addon to be installed (since SVN Rev 506).

            People

            • Assignee:
              Joris Kuipers
              Reporter:
              Joris Kuipers
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: