예제 #1
0
파일: Globals.java 프로젝트: LevittS/jsqsh
  @Override
  public int execute(Session session, SqshOptions options) throws Exception {

    ConnectionContext conn = session.getConnectionContext();

    if (conn == null) {

      session.err.println("No connection established");
      return 1;
    }

    List<String> vars = conn.getGlobals();
    Collections.sort(vars);

    ColumnDescription[] columns = new ColumnDescription[1];
    columns[0] = new ColumnDescription("Global", -1);
    Renderer renderer = session.getRendererManager().getCommandRenderer(session);
    renderer.header(columns);

    for (String var : vars) {

      String row[] = new String[1];

      row[0] = var;
      renderer.row(row);
    }

    renderer.flush();
    return 0;
  }
예제 #2
0
  /** {@inheritDoc} */
  public void header(ColumnDescription[] columns) {

    super.header(columns);
    int totalWidth = 0;

    /*
     * Print the column names.
     */
    for (int i = 0; i < columns.length; i++) {

      /*
       * isql caps the display width of the column header at 512.
       */
      if (columns[i].getWidth() > 512) columns[i].setWidth(512);

      if (i > 0 && (totalWidth + columns[i].getWidth() + 1) > screenWidth) {

        session.out.println();
        session.out.print(" \t");
        totalWidth = 9;
      } else {

        session.out.print(' ');
        ++totalWidth;
      }

      printColumnName(columns[i], columns[i].getName());
      totalWidth += columns[i].getWidth();
    }
    session.out.println();

    /*
     * Now our dashes.
     */
    for (int i = 0; i < columns.length; i++) {

      if (i > 0 && (totalWidth + columns[i].getWidth() + 1) > screenWidth) {

        session.out.println();
        session.out.print(" \t");
        totalWidth = 9;
      } else {

        session.out.print(' ');
        ++totalWidth;
      }

      dashes(columns[i].getWidth());

      totalWidth += columns[i].getWidth();
    }

    session.out.println();
  }