Author: roy
Date: 2010-01-24 12:07:18 +0100 (Sun, 24 Jan 2010)
New Revision: 454
Added:
src/test/java/nl/improved/sqlclient/charva/
src/test/java/nl/improved/sqlclient/charva/CharvaSQLShellWindowTest.java
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
fix pageup/down include some lines of previous screen
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2010-01-20 19:40:27 UTC (rev 453)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2010-01-24 11:07:18 UTC (rev 454)
@@ -309,17 +309,25 @@
}
private String trim(StringBuilder text, int pageUpCount) {
+ return trim(text, pageUpCount, getScreenHeight());
+
+ }
+
+ public static String trim(StringBuilder text, int pageUpCount, int maxHeight) {
String strText = text.toString();
if (strText.indexOf('\n') < 0) {
return strText;
}
- int maxHeight = getScreenHeight();
String[] lines = strText.split("\n");
if (lines.length <= maxHeight) {
return strText;
}
StringBuilder newString = new StringBuilder();
- int offset = Math.max(0, lines.length - ((pageUpCount +1) * maxHeight-3)); // include some extra lines in history
+ int offset = lines.length - ((pageUpCount +1) * maxHeight);
+ if (pageUpCount > 0) {
+ offset +=pageUpCount;
+ }
+ offset = Math.max(0, offset);
boolean endsWithReturn = strText.endsWith("\n");
for (int i = 0; i < maxHeight; i++) {
newString.append(lines[i+offset]);
Added: src/test/java/nl/improved/sqlclient/charva/CharvaSQLShellWindowTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/charva/CharvaSQLShellWindowTest.java 2010-01-20 19:40:27 UTC (rev 453)
+++ src/test/java/nl/improved/sqlclient/charva/CharvaSQLShellWindowTest.java 2010-01-24 11:07:18 UTC (rev 454)
@@ -0,0 +1,66 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package nl.improved.sqlclient.charva;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author roy
+ */
+public class CharvaSQLShellWindowTest extends TestCase {
+
+ public CharvaSQLShellWindowTest(String testName) {
+ super(testName);
+ }
+
+
+ /**
+ * Test of trim method, of class CharvaSQLShellWindow.
+ */
+ public void testTrim() {
+ StringBuilder buf = new StringBuilder();
+ for (int i = 0; i < 1000; i++) {
+ buf.append(Integer.toString(i));
+ buf.append('\n');
+ }
+ int maxHeight = 3;
+
+ int pageUpCount = 0;
+ String expResult = "997\n998\n999\n";
+ String result = CharvaSQLShellWindow.trim(buf, pageUpCount, maxHeight);
+ assertEquals(expResult, result);
+
+ pageUpCount = 1;
+ expResult = "995\n996\n997\n";
+ result = CharvaSQLShellWindow.trim(buf, pageUpCount, maxHeight);
+ assertEquals(expResult, result);
+
+ pageUpCount = 2;
+ expResult = "993\n994\n995\n";
+ result = CharvaSQLShellWindow.trim(buf, pageUpCount, maxHeight);
+ assertEquals(expResult, result);
+
+
+ pageUpCount = 0;
+ maxHeight=10;
+ expResult = "990\n991\n992\n993\n994\n995\n996\n997\n998\n999\n";
+ result = CharvaSQLShellWindow.trim(buf, pageUpCount, maxHeight);
+ assertEquals(expResult, result);
+
+ pageUpCount = 1;
+ maxHeight=10;
+ expResult = "981\n982\n983\n984\n985\n986\n987\n988\n989\n990\n";
+ result = CharvaSQLShellWindow.trim(buf, pageUpCount, maxHeight);
+ assertEquals(expResult, result);
+
+ pageUpCount = 2;
+ maxHeight=10;
+ expResult = "972\n973\n974\n975\n976\n977\n978\n979\n980\n981\n";
+ result = CharvaSQLShellWindow.trim(buf, pageUpCount, maxHeight);
+ assertEquals(expResult, result);
+ }
+}
|