package com.zaranux.os.client.programs;
import com.zaranux.client.api.AsyncCallback;
import com.zaranux.client.java.io.FileDescriptor;
import com.zaranux.client.java.io.FileInputStream;
import com.zaranux.client.java.io.FileOutputStream;
import com.zaranux.client.java.io.InputStream;
import com.zaranux.client.java.io.PrintStream;
import com.zaranux.client.java.io.BufferedOutputStream;
import com.zaranux.client.java.nio.ByteBuffer;
import com.zaranux.os.client.core.Program;
import com.zaranux.os.client.zterminal.TerminalEditor;
public class Terminal extends Program {
private TerminalEditor terminalEditor;
public final InputStream in ;
public final PrintStream out ;
public final PrintStream err ;
private final ByteBuffer inBuffer = new ByteBuffer(new AsyncCallback<String>()
{
public void onSuccess(String s)
{
output(s);
}
public void onFailure(Throwable t)
{
}
});
private final ByteBuffer outBuffer = new ByteBuffer(new AsyncCallback<String>()
{
public void onSuccess(String s)
{
output(s);
}
public void onFailure(Throwable t)
{
}
});
private final ByteBuffer errBuffer = new ByteBuffer(new AsyncCallback<String>()
{
public void onSuccess(String s)
{
output(s);
}
public void onFailure(Throwable t)
{
}
});
// public Widget getWidget()
// {
// return terminalEditor.getWidget();
// }
public Terminal()
{
FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
fdIn.setInputBuffer(inBuffer);
in = fdIn; //new BufferedInputStream(fdIn);
FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
fdOut.setOutputBuffer(outBuffer);
//out = new PrintStream(new BufferedOutputStream(fdOut, 128), true);
out = new PrintStream(fdOut, true);
FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
fdErr.setErrorBuffer(errBuffer);
err = new PrintStream(new BufferedOutputStream(fdErr, 128), true);
}
public void main(String[] args)
{
shell cp;
cp = (shell) getChildProgram("com.zaranux.client.programs.shell");
if(cp == null)
{
cp = new shell();
run(cp);
}
cp.setIO(in, out);
terminalEditor = new TerminalEditor(inBuffer,cp);
setWidget(terminalEditor.getWidget(),580,350);
}
public void output(String s)
{
terminalEditor.dumpToTerminal(s);
}
}