Terminal IO

NeuroKernel has a console based terminal IO for an application which could be easier for some use cases. Terminal IO supports styling, linking and images. Any application can request terminal IO. In order to use terminal IO for an application, the terminal console application must be run which comes in the default package. This application when run is given a system pipe so that applications run from the terminal can use the terminal console to print data or receive commands.

1. ITerminal Interface

The terminal access request is made with getTerminal method which returns an ITerminal interface object, and ITerminalListener is used to manage the input and output operations. Application must be executed from the terminal command line in order to have terminal functionality. ITerminal interface object is also passed to the listener methods for more convenient way of interaction.

import com.neurokernel.client.*;
import com.neurokernel.system.io.*;
import com.neurokernel.system.*;
 * This application must be run from NeuroKernel terminal
public class TerminalExample extends NApplication {
    public void main(int argc, String[] argv) {
       NLabel label=new NLabel(getMainFrame());
       getTerminal(stdio -> {
            String input=stdio.readString();
            if (input == null && stdio.getKeyCode() == 0) {
                stdio.writeString("Hello Console!");
                stdio.setPrompt("password:", true);
            } else if (stdio.getKeyCode() > 0) {
                stdio.setPrompt("Command> ");
            } else {
                stdio.writeString("You have entered: " + input);
                if (input.equals("close")) {
                } else {
                   label.setText(input); //also sets the label text
                   stdio.writeString("Press any key to continue...", 
       setVisible("Terminal Example",20,20,300,300);

2. System Console

Modern web browsers have a console for information tracing purposes from the running scripts. NeuroKernel can utilize this console feature with a IConsole system interface. C like text formatting can be achieved with printf method which is also available from NTools utility class for any kind of string formatting purpose; however, it does not have all the functionality of the C language supplied version of the formatting.

import com.neurokernel.client.*;
import com.neurokernel.client.adapter.*;
public class HistoryExample extends NApplication {
      private int currentState;
      public void main(int argc, String[] argv) {
          NFrame mainFrame = getMainFrame();
          new NButton(mainFrame,"Print").addListener((IActionListener) (e) ->
                getConsole().print("Hello "+(currentState++)));
          mainFrame.setVisible("History Interface");