incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject git commit: Start to adding floating header.
Date Fri, 27 Jun 2014 12:36:42 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/apache-blur-0.2 b2e2952d8 -> f935941c4


Start to adding floating header.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/f935941c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/f935941c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/f935941c

Branch: refs/heads/apache-blur-0.2
Commit: f935941c472c713c624572025f294725bc117195
Parents: b2e2952
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Fri Jun 27 08:36:17 2014 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Fri Jun 27 08:36:17 2014 -0400

----------------------------------------------------------------------
 .../org/apache/blur/shell/QueryCommand.java     |   6 +-
 .../org/apache/blur/shell/TableDisplay.java     | 110 ++++++++++++++++---
 2 files changed, 98 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/f935941c/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
index aa519af..f19e4df 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/QueryCommand.java
@@ -106,8 +106,8 @@ public class QueryCommand extends Command implements TableFirstArgCommand
{
     String prompt = reader.getPrompt();
     reader.setPrompt("");
     final TableDisplay tableDisplay = new TableDisplay(reader);
-    tableDisplay.setDescription(blurResults.getTotalResults() + " results found in [" + timeInNanos
/ 1000000.0
-        + " ms].");
+    tableDisplay.setDescription(white(blurResults.getTotalResults() + " results found in
[" + timeInNanos / 1000000.0
+        + " ms]."));
     tableDisplay.setSeperator(" ");
     try {
 
@@ -293,7 +293,6 @@ public class QueryCommand extends Command implements TableFirstArgCommand
{
     int c = 2;
     List<String> orderedColumns = getOrderColumnValues(record, columnOrder);
     String family = record.getFamily();
-    tableDisplay.set(1, line.get(), white(getTruncatedVersion(record.getRecordId())));
     if (!family.equals(currentFamily)) {
       List<String> list = columnOrder.get(family);
       for (int i = 0; i < list.size(); i++) {
@@ -301,6 +300,7 @@ public class QueryCommand extends Command implements TableFirstArgCommand
{
       }
       line.incrementAndGet();
     }
+    tableDisplay.set(1, line.get(), white(getTruncatedVersion(record.getRecordId())));
     for (String oc : orderedColumns) {
       if (oc != null) {
         tableDisplay.set(c, line.get(), white(getTruncatedVersion(oc)));

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/f935941c/blur-shell/src/main/java/org/apache/blur/shell/TableDisplay.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/TableDisplay.java b/blur-shell/src/main/java/org/apache/blur/shell/TableDisplay.java
index 22b30eb..56a4b4f 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/TableDisplay.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/TableDisplay.java
@@ -127,6 +127,8 @@ public class TableDisplay implements Closeable {
   private final Map<Integer, Runnable> _keyHookMap = new ConcurrentHashMap<Integer,
Runnable>();
   private final AtomicBoolean _stopReadingInput = new AtomicBoolean(false);
   private String _description = "";
+  private volatile long _lastPaint = 0;
+  private volatile boolean _dirty = true;
 
   public void setDescription(String description) {
     _description = description;
@@ -143,16 +145,29 @@ public class TableDisplay implements Closeable {
       @Override
       public void run() {
         while (_running.get()) {
+          long now = System.currentTimeMillis();
           synchronized (_canvas) {
-            try {
-              render(_canvas);
-            } catch (IOException e) {
-              e.printStackTrace();
+            if (_lastPaint + 1000 < now) {
+              try {
+                render(_canvas);
+              } catch (IOException e) {
+                e.printStackTrace();
+              }
+              _lastPaint = System.currentTimeMillis();
+              _dirty = false;
             }
-            try {
-              _canvas.wait();
-            } catch (InterruptedException e) {
-              e.printStackTrace();
+            if (_dirty) {
+              try {
+                _canvas.wait(1000);
+              } catch (InterruptedException e) {
+                e.printStackTrace();
+              }
+            } else {
+              try {
+                _canvas.wait();
+              } catch (InterruptedException e) {
+                e.printStackTrace();
+              }
             }
           }
         }
@@ -187,10 +202,18 @@ public class TableDisplay implements Closeable {
                 case 66:
                   // down
                   _canvas.moveDown();
+                case 53:
+                  // up
+                  _canvas.pageUp();
+                  break;
+                case 54:
+                  // down
+                  _canvas.pageDown();
                   break;
                 default:
                   break;
                 }
+                _lastPaint = 0;
               }
             } else {
               Runnable runnable = _keyHookMap.get(read);
@@ -212,24 +235,25 @@ public class TableDisplay implements Closeable {
 
   private void render(Canvas canvas) throws IOException {
     canvas.reset();
-    canvas.append(_description);
-    canvas.endLine();
+    canvas.resetHeader();
+    canvas.appendHeader(_description);
+    canvas.endHeader();
     buildHeaderOutput(canvas);
     buildTableOutput(canvas);
     canvas.write();
   }
 
   private void buildHeaderOutput(Canvas canvas) {
-    canvas.startLine();
+    canvas.startHeader();
     for (int x = 0; x < _maxX; x++) {
       if (x != 0) {
-        canvas.append(_seperator);
+        canvas.appendHeader(_seperator);
       }
       Object value = _header.get(x);
       int widthForColumn = getWidthForColumn(x);
-      buffer(canvas, getString(value), widthForColumn);
+      bufferHeader(canvas, getString(value), widthForColumn);
     }
-    canvas.endLine();
+    canvas.endHeader();
   }
 
   private void buildTableOutput(Canvas canvas) {
@@ -256,6 +280,15 @@ public class TableDisplay implements Closeable {
     return width;
   }
 
+  private void bufferHeader(Canvas canvas, String value, int width) {
+    canvas.appendHeader(value);
+    width -= getVisibleLength(value);
+    while (width > 0) {
+      canvas.appendHeader(' ');
+      width--;
+    }
+  }
+  
   private void buffer(Canvas canvas, String value, int width) {
     canvas.append(value);
     width -= getVisibleLength(value);
@@ -286,6 +319,7 @@ public class TableDisplay implements Closeable {
   private void paint() {
     synchronized (_canvas) {
       _canvas.notify();
+      _dirty = true;
     }
   }
 
@@ -521,6 +555,8 @@ public class TableDisplay implements Closeable {
 
     private final StringBuilder _screenBuilder = new StringBuilder();
     private final LineBuilder _lineBuilder = new LineBuilder();
+    private final StringBuilder _headerScreenBuilder = new StringBuilder();
+    private final LineBuilder _headerLineBuilder = new LineBuilder();
     private final ConsoleReader _reader;
     private int _height;
     private int _width;
@@ -528,11 +564,17 @@ public class TableDisplay implements Closeable {
     private volatile int _posX = 0;
     private volatile int _posY = 0;
     private int _leftRightMoveSize;
+    private int _headerLine;
 
     public Canvas(ConsoleReader reader) {
       _reader = reader;
     }
 
+    public void resetHeader() {
+      _headerLine = 0;
+      _headerScreenBuilder.setLength(0);
+    }
+
     public void reset() {
       _line = 0;
       _screenBuilder.setLength(0);
@@ -545,7 +587,7 @@ public class TableDisplay implements Closeable {
     public void endLine() {
       _lineBuilder.close();
       int pos = _line - _posY;
-      if (pos >= 0 && pos < _height) {
+      if (pos >= 0 && pos < (_height - _headerLine)) {
         int end = _posX + _width;
         int s = _posX;
         int e = Math.min(_lineBuilder.visibleLength(), end);
@@ -558,10 +600,35 @@ public class TableDisplay implements Closeable {
       _lineBuilder.reset();
     }
 
+    public void endHeader() {
+      _headerLineBuilder.close();
+      int end = _posX + _width;
+      int s = _posX;
+      int e = Math.min(_headerLineBuilder.visibleLength(), end);
+      if (e > s) {
+        _headerScreenBuilder.append(_headerLineBuilder.substring(s, e));
+      }
+      _headerScreenBuilder.append('\n');
+      _headerLineBuilder.reset();
+      _headerLine++;
+    }
+
     public void startLine() {
 
     }
 
+    public void startHeader() {
+
+    }
+
+    public void appendHeader(char c) {
+      _headerLineBuilder.append(c);
+    }
+
+    public void appendHeader(String s) {
+      _headerLineBuilder.append(s);
+    }
+
     public void append(char c) {
       _lineBuilder.append(c);
     }
@@ -573,6 +640,7 @@ public class TableDisplay implements Closeable {
     public void write() throws IOException {
       _reader.clearScreen();
       Writer writer = _reader.getOutput();
+      writer.write(_headerScreenBuilder.toString());
       writer.write(_screenBuilder.toString());
       writer.flush();
     }
@@ -597,6 +665,18 @@ public class TableDisplay implements Closeable {
       _posY++;
     }
 
+    public void pageUp() {
+      if (_posY < _height) {
+        _posY = 0;
+      } else {
+        _posY -= _height;
+      }
+    }
+
+    public void pageDown() {
+      _posY += _height;
+    }
+
   }
 
   public void setStopReadingInput(boolean b) {


Mime
View raw message