Skip to content

linux-china/xterm-demo

Repository files navigation

Xterm.js demo with Spring Boot RSocket

Build Status

A web terminal with following tech stack:

  • Xterm.js to render terminal in browser
  • Input commands to be executed on the backend(Spring Boot + RSocket)
  • Spring Shell command model to write your commands
  • RSocket protocol: communication between browser and backend
  • xterm-addon-rsocket
  • Web Components for Xterm

If you want to use Xterm.js in your Spring Boot app, please use https://github.com/linux-china/xtermjs-spring-boot-starter

How to run?

$ mvn compile spring-boot:run

Then visit http://localhost:8080/index.html and screenshot alike following:

Xterm Screenshot

How to write my command?

You just need to write standard ShellComponent of Spring Shell, and example as following:

@ShellComponent
public class MyCommands {

    @ShellMethod("Add two integers together.")
    public int add(int a, int b) {
        return a + b;
    }

    @ShellMethod("Minus two integers together.")
    public int minus(int a, int b) {
        return a - b;
    }
}

Attention: You can choose Picocli to build commands also https://github.com/remkop/picocli/tree/master/picocli-spring-boot-starter

Use Cases

  • mysql/redis-cli CLI in browser
  • App Info Viewer: configuration, refresh etc
  • Metrics Query
  • JVM info: thread, heap etc
  • Call functions on FaaS platform`

References