Package org.crsh.text

Examples of org.crsh.text.LineReader


          public int getMinHeight(int width) {
            throw new UnsupportedOperationException();
          }
          @Override
          public LineReader reader(final int width) {
            return new LineReader() {

              boolean done = false;

              public boolean hasLine() {
                return !done;
View Full Code Here


  // in relation to widths array that can contain (should?) 0 value
  LineReader renderer(final int[] widths, int height) {
    final LineReader[] readers = new LineReader[widths.length];
    for (int i = 0;i < readers.length;i++) {
      LineRenderer renderer = cols.get(i);
      LineReader reader = renderer.reader(widths[i] - leftCellPadding - rightCellPadding, height);
      readers[i] = reader;
    }

    //
    return new LineReader() {

      /** . */
      private boolean done = false;

      public boolean hasLine() {
        return !done;
      }

      public void renderLine(RenderAppendable to) {
        if (!hasLine()) {
          throw new IllegalStateException();
        }

        //
        if (style != null) {
          to.enterStyle(style);
        }

        //
        for (int i = 0;i < readers.length;i++) {
          LineReader reader = readers[i];

          //
          if (i > 0) {
            if (separator != null) {
              to.styleOff();
              to.append(separator.vertical);
              to.styleOn();
            }
          }
          if (reader != null && reader.hasLine()) {
            // Left padding
            if (leftCellPadding > 0) {
              for (int j = 0;j < leftCellPadding;j++) {
                to.append(' ');
              }
            }
            reader.renderLine(to);
            // Right padding
            if (rightCellPadding > 0) {
              for (int j = 0;j < rightCellPadding;j++) {
                to.append(' ');
              }
            }
          } else {
            readers[i] = null;
            for (int j = widths[i];j > 0;j--) {
              to.append(' ');
            }
          }
        }

        //
        if (style != null) {
          to.leaveStyle();
        }


        // Update status
        done = true;
        for (LineReader reader : readers) {
          if (reader != null) {
            if (reader.hasLine()) {
              done = false;
              break;
            }
          }
        }
View Full Code Here

    return reader(width, 2);
  }

  @Override
  public LineReader reader(final int width, final int height) {
    return new LineReader() {

      /** . */
      private int index = 0;

      public boolean hasLine() {
View Full Code Here

  public void render(RenderAppendable to) {
    LineRenderer renderer = renderer();

    // For now height - 1 because of the char that goes to the line in some impl
    LineReader reader = renderer.reader(to.getWidth(), to.getHeight() - 1);
    if (reader != null) {
      while (reader.hasLine()) {
        reader.renderLine(to);
        to.append('\n');
      }
    }
  }
View Full Code Here

        heights = new int[tail.getSize()];
        Arrays.fill(heights, -1);
      }

      //
      return new LineReader() {

        /** . */
        TableRowReader rHead = null;

        /** . */
 
View Full Code Here

    for (LineRenderer child : children) {
      readers.addLast(child.reader(width - 2));
    }

    //
    return new LineReader() {

      /** . */
      LineReader value = TreeLineRenderer.this.value != null ? TreeLineRenderer.this.value.reader(width) : null;

      /** . */
      boolean node = true;

      public boolean hasLine() {
        if (value != null) {
          if (value.hasLine()) {
            return true;
          } else {
            value = null;
          }
        }
        while (readers.size() > 0) {
          if (readers.peekFirst().hasLine()) {
            return true;
          } else {
            readers.removeFirst();
            node = true;
          }
        }
        return false;
      }

      public void renderLine(RenderAppendable to) {
        if (value != null) {
          if (value.hasLine()) {
            value.renderLine(to);
          } else {
            value = null;
          }
        }
        if (value == null) {
          while (readers.size() > 0) {
            LineReader first = readers.peekFirst();
            if (first.hasLine()) {
              if (node) {
                to.append("+-");
                node = false;
              } else {
                Iterator<LineReader> i = readers.descendingIterator();
                boolean rest = false;
                while (i.hasNext()) {
                  LineReader renderer = i.next();
                  if (i.hasNext()) {
                    if (renderer.hasLine()) {
                      rest = true;
                      break;
                    }
                  }
                }
View Full Code Here

    }
    return result;
  }

  public List<String> render(Element element, int width) {
    LineReader renderer = element.renderer().reader(width);
    return render(renderer, width);
  }
View Full Code Here

    LineReader renderer = element.renderer().reader(width);
    return render(renderer, width);
  }

  public void assertRender(Element element, int width, int height, String... expected) {
    LineReader renderer = element.renderer().reader(width, height);
    assertNotNull("Was expecting a renderer", renderer);
    assertRender(renderer, width, expected);
  }
View Full Code Here

    assertNotNull("Was expecting a renderer", renderer);
    assertRender(renderer, width, expected);
  }

  public void assertRender(Element element, int width, String... expected) {
    LineReader renderer = element.renderer().reader(width);
    assertNotNull("Was expecting a renderer", renderer);
    assertRender(renderer, width, expected);
  }
View Full Code Here

    assertNotNull("Was expecting a renderer", renderer);
    assertRender(renderer, width, expected);
  }

  public void assertNoRender(Element element, int width) {
    LineReader renderer = element.renderer().reader(width);
    assertNull(renderer);
  }
View Full Code Here

TOP

Related Classes of org.crsh.text.LineReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.