package background;

import javax.swing.JTextArea;

public class IOManager {
	
	public JTextArea input;
	public JTextArea output;
	public JTextArea error;
	
	public int inputIndex;
	
	public IOManager() {
	}
	
	public void  setAreas(JTextArea in, JTextArea out, JTextArea err) {
		input = in;
		output = out;
		error = err;
	}
	
	public void reset() {
		inputIndex = 0;
		output.setText("");
		error.setText("");
	}
	
	public String getNextInput() {
		String result = "";
		
		String part = "";
		String text = input.getText().replace("\r", " ");		
		text = text.replace("\n", " ");
		text = text.replace("  ", " ");
		while ((inputIndex < text.length()) && !part.equals(" ")) {
			part = Character.toString(text.charAt(inputIndex));
			result += part;
			inputIndex++;
		}		
		return result.trim();
	}

	public void addOutput(String s) {
		output.append(s);
	}

	public void addError(String s) {		
		error.append(s + "\r\n");
	}
	
}
