package com.thomasnyberg.mindset;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Mindset extends Activity {
  Terminal term;

  private class Terminal {
    private TextView window;
    private int maxLines = 30; /*Hardcoded value is bad. Works for my phone.*/
    private String[] buffer = new String[maxLines];

    Terminal(TextView win) {
      window = win;
    }

    public void fillLines() {
      for (int i = 0; i < maxLines; i++) {
        buffer[i] = "Line " + Integer.toString(i + 1);
      }
      writeBuffer();
    }

    private void writeBuffer() {
      String text = "";
      for (int i = 0; i < maxLines; i++) {
        text += buffer[i] + "\n";
      }
      window.setText(text);
    }
  }
    

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    term = new Terminal((TextView) findViewById(R.id.mainWindow));
  }

  @Override
  protected void onStart() {
    super.onStart();
    term.fillLines();
  }

  @Override
  protected void onResume() {
    super.onResume();
  }
}

@@ -234,41 +234,16 @@
 ow;%0A
- 
+%0A
    
-private int maxLines = 30;
  /*
+ 
 Hard
@@ -264,11 +264,15 @@
  bad
-. W
+, but w
 orks
@@ -289,11 +289,76 @@
 one.
+ 
 */%0A
+    private final int maxLines = 30;%0A%0A    private int nextLine;%0A
     
@@ -463,166 +463,590 @@
     
-%7D%0A%0A    public void fillLines() %7B%0A      for (int i = 0; i %3C maxLines; i++) %7B%0A        buffer%5Bi%5D = %22Line %22 + Integer.toString(i + 1);%0A      %7D%0A      writeBuffer()
+  initBuffer();%0A    %7D%0A%0A    private void initBuffer() %7B%0A      nextLine = 0;%0A%0A      for (int i = 0; i %3C maxLines; i++) %7B%0A        buffer%5Bi%5D = %22%5Cn%22;%0A      %7D%0A      writeBuffer();%0A    %7D%0A%0A    public void writeLine(String text) %7B%0A      if (nextLine %3C maxLines) %7B%0A        buffer%5BnextLine%5D = text;%0A        nextLine++;%0A      %7D else %7B%0A        bufferShift();%0A        buffer%5BmaxLines - 1%5D = text;%0A      %7D%0A      %0A      writeBuffer();%0A    %7D%0A%0A    private void bufferShift() %7B%0A      for (int i = 0; i + 1 %3C maxLines; i++) %7B%0A        buffer%5Bi%5D = buffer%5Bi + 1%5D;%0A      %7D%0A      buffer%5BmaxLines - 1%5D = %22%5Cn%22
 ;%0A  
@@ -1517,25 +1517,101 @@
     
-term.fillLines();
+for (int i = 0; i %3C 31; i++) %7B%0A      term.writeLine(%22Line %22 + Integer.toString(i + 1));%0A    %7D
 %0A  %7D

Implement basic line Terminal