Skip to content

Write SSH based apps, for that loving terminal feel

Notifications You must be signed in to change notification settings

theminecoder/LanternaSSH

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

LanternaSSH

A wrapper around Lanterna to help with creating ssh based apps.

Usage

package test;

import com.googlecode.lanterna.gui2.*;
import com.googlecode.lanterna.screen.Screen;
import com.googlecode.lanterna.screen.TerminalScreen;
import me.theminecoder.util.lanternassh.LanternaSSHAppWrapper;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.auth.password.AcceptAllPasswordAuthenticator;

import java.io.File;
import java.io.IOException;

public class App extends LanternaSSHApp {
    
    public static void main(String[] args){
      SshServer server = SshServer.setUpDefaultServer();
      server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser")));
      server.setPasswordAuthenticator(new AcceptAllPasswordAuthenticator());
      server.setCommandFactory(() -> new LanternaSSHAppWrapper(App::new));
      server.setPort(4022);
      server.start();
      
      while(true) {
          // Keep thread alive
      }
    }
    
    public void run() throws IOException {
        //Setup Screen
        Screen screen = new TerminalScreen(getTerminal());
        screen.startScreen();
        
        // Create panel to hold components
        Panel panel = new Panel();
        panel.setLayoutManager(new GridLayout(2));
        
        panel.addComponent(new Label("Forename"));
        panel.addComponent(new TextBox());
        
        panel.addComponent(new Label("Surname"));
        panel.addComponent(new TextBox());
        
        panel.addComponent(new EmptySpace(new TerminalSize(0,0))); // Empty space underneath labels
        panel.addComponent(new Button("Submit"));
        
        // Create window to hold the panel
        BasicWindow window = new BasicWindow();
        window.setComponent(panel);

        // Create gui and start gui
        MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));
        gui.addWindowAndWait(window);
    }
    
}

About

Write SSH based apps, for that loving terminal feel

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages