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.client.io.*; import com.neurokernel.client.system.*; /** * This application must be run from NeuroKernel terminal */ public class TerminalExample extends NApplication { NLabel label; @Override public void main(int argc, String[] argv) { getSystem().getTerminal(new NTerminalListener() { @Override public void onData(ITerminal 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")) { stdio.close(); } else { label.setText(input); //also sets the label text stdio.writeString("Press any key to continue...", NSystemConstants.TERMINAL_WAIT_KEY_INPUT); } } } }); NFrame mainFrame=getMainFrame(); label=new NLabel(mainFrame); mainFrame.setTitle("Terminal Example"); mainFrame.setBounds(20,20,300,300); mainFrame.setVisible(true); } }
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; @Override public void main(int argc, String[] argv) { final NFrame mainFrame = getMainFrame(); new NButton(mainFrame,"Print").addListener(new NActionListener() { @Override public void onAction(NEvent e) { getConsole().print("Hello "+(currentState++)); } }); mainFrame.setTitle("History Interface"); mainFrame.setBounds(20,20,200,200); mainFrame.setVisible(true); } }