public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Allign all help command option descriptions.
@ 2008-03-02 12:59 mark
  0 siblings, 0 replies; only message in thread
From: mark @ 2008-03-02 12:59 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  ac50d5b81a0d2c34d901b21d0a7323b1b7de5435 (commit)
       via  935231801cf3eac24845eee44a9a857c6fe5669c (commit)
       via  df357e29a4d91b4f4b53554c8394de51a1d4f5da (commit)
      from  d2b92ecdd4127ab44756d0c3745bbd49a996cdac (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit ac50d5b81a0d2c34d901b21d0a7323b1b7de5435
Author: Mark Wielaard <mwielaard@redhat.com>
Date:   Sun Mar 2 13:58:01 2008 +0100

    Allign all help command option descriptions.
    
    frysk-core/frysk/hpd/ChangeLog
    2008-03-02  Tom Tromey  <tromey@redhat.com>
    
           * ParameterizedCommand.java (help): Align all option
           descriptions.

commit 935231801cf3eac24845eee44a9a857c6fe5669c
Author: Mark Wielaard <mwielaard@redhat.com>
Date:   Sun Mar 2 13:33:30 2008 +0100

    Add WordWrapWriter documentation.
    
    frysk-core/frysk/hpd/ChangeLog:
    2008-03-01  Tom Tromey  <tromey@redhat.com>
    
            * CLI.java (getWordWrapWriter): Document.
    
    frysk-core/frysk/util/ChangeLog:
    2008-03-01  Tom Tromey  <tromey@redhat.com>
    
            * WordWrapWriter.java: Document.

commit df357e29a4d91b4f4b53554c8394de51a1d4f5da
Author: Mark Wielaard <mwielaard@redhat.com>
Date:   Sun Mar 2 13:29:37 2008 +0100

    Add help word wrapping.
    
    frysk-core/frysk/hpd/ChangeLog:
    2008-03-02  Tom Tromey  <tromey@redhat.com>
    
            * ParameterizedCommand.java (help): Use getWordWrapWriter.  Set
            indent for wrapping.
            * NoOptsCommand.java (help): Use getWordWrapWriter.
            * MultiLevelCommand.java (help): use getWordWrapWriter.  Set
            indent for wrapping.
            * Command.java (help): Use getWordWrapWriter.
            * CLI.java (getWordWrapWriter): New method.
    
    frysk-core/frysk/util/ChangeLog:
    2008-03-02  Tom Tromey  <tromey@redhat.com>
    
            * WordWrapWriter.java: New file.

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/hpd/CLI.java                  |    8 +
 frysk-core/frysk/hpd/ChangeLog                 |   19 ++
 frysk-core/frysk/hpd/Command.java              |   14 +-
 frysk-core/frysk/hpd/MultiLevelCommand.java    |   12 +-
 frysk-core/frysk/hpd/NoOptsCommand.java        |   11 +-
 frysk-core/frysk/hpd/ParameterizedCommand.java |   33 +++-
 frysk-core/frysk/util/ChangeLog                |    8 +
 frysk-core/frysk/util/WordWrapWriter.java      |  211 ++++++++++++++++++++++++
 8 files changed, 292 insertions(+), 24 deletions(-)
 create mode 100644 frysk-core/frysk/util/WordWrapWriter.java

First 500 lines of diff:
diff --git a/frysk-core/frysk/hpd/CLI.java b/frysk-core/frysk/hpd/CLI.java
index 35bc9e5..f8f16c8 100644
--- a/frysk-core/frysk/hpd/CLI.java
+++ b/frysk-core/frysk/hpd/CLI.java
@@ -61,6 +61,7 @@ import frysk.rt.ProcTaskIDManager;
 import frysk.stepping.SteppingEngine;
 import frysk.stepping.TaskStepEngine;
 import frysk.util.CountDownLatch;
+import frysk.util.WordWrapWriter;
 import frysk.expr.Expression;
 import frysk.expr.ScratchSymTab;
 import frysk.expr.ExprSymTab;
@@ -181,6 +182,13 @@ public class CLI {
             idManager.manageProc(proc, this.taskID);
     }
 
+    /**
+     * Return a WordWrapWriter which wraps this CLI's output writer.
+     */
+    WordWrapWriter getWordWrapWriter() {
+	return new WordWrapWriter(outWriter);
+    }
+
     final PrintWriter outWriter;
     private Preprocessor prepro;
     private String prompt; // string to represent prompt, will be moved
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index 5c3dda7..5d27647 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,3 +1,22 @@
+2008-03-02  Tom Tromey  <tromey@redhat.com>
+
+	* ParameterizedCommand.java (help): Align all option
+	descriptions.
+
+2008-03-02  Tom Tromey  <tromey@redhat.com>
+
+	* CLI.java (getWordWrapWriter): Document.
+
+2008-03-02  Tom Tromey  <tromey@redhat.com>
+
+	* ParameterizedCommand.java (help): Use getWordWrapWriter.  Set
+	indent for wrapping.
+	* NoOptsCommand.java (help): Use getWordWrapWriter.
+	* MultiLevelCommand.java (help): use getWordWrapWriter.  Set
+	indent for wrapping.
+	* Command.java (help): Use getWordWrapWriter.
+	* CLI.java (getWordWrapWriter): New method.
+
 2008-03-01  Tom Tromey  <tromey@redhat.com>
 
 	* RunCommand.java (RunCommand): Fix typo.
diff --git a/frysk-core/frysk/hpd/Command.java b/frysk-core/frysk/hpd/Command.java
index ecbb374..3060b9a 100644
--- a/frysk-core/frysk/hpd/Command.java
+++ b/frysk-core/frysk/hpd/Command.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2007, Red Hat Inc.
+// Copyright 2007, 2008, Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -40,6 +40,7 @@
 package frysk.hpd;
 
 import java.util.List;
+import java.io.PrintWriter;
 
 /**
  * A handler class for the CLI that supplies its own help messages.
@@ -72,11 +73,12 @@ public abstract class Command {
      * command.
      */
     void help(CLI cli, Input buffer) {
-	cli.outWriter.print("Usage: ");
-	cli.outWriter.print(syntax);
-	cli.outWriter.println();
-	cli.outWriter.print(full);
-	cli.outWriter.println();
+	PrintWriter out = cli.getWordWrapWriter();
+	out.print("Usage: ");
+	out.print(syntax);
+	out.println();
+	out.print(full);
+	out.println();
     }
 
     /**
diff --git a/frysk-core/frysk/hpd/MultiLevelCommand.java b/frysk-core/frysk/hpd/MultiLevelCommand.java
index 266d5ef..ac51455 100644
--- a/frysk-core/frysk/hpd/MultiLevelCommand.java
+++ b/frysk-core/frysk/hpd/MultiLevelCommand.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2007, Red Hat Inc.
+// Copyright 2007, 2008, Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -45,6 +45,7 @@ import java.util.HashMap;
 import java.util.TreeMap;
 import java.util.Iterator;
 import java.util.List;
+import frysk.util.WordWrapWriter;
 
 /**
  * A handler class for the CLI that supplies its own help messages.
@@ -115,14 +116,17 @@ public abstract class MultiLevelCommand extends Command {
      */
     void help(CLI cli, Input input) {
 	if (input.size() == 0) {
+	    WordWrapWriter out = cli.getWordWrapWriter();
 	    for (Iterator i = subCommands.entrySet().iterator();
 		 i.hasNext(); ) {
 		Map.Entry entry = (Map.Entry)(i.next());
 		String name = (String)entry.getKey();
 		Command command = (Command)entry.getValue();
-		cli.outWriter.print(name);
-		cli.outWriter.print(" - ");
-		cli.outWriter.println(command.description());
+		out.print(name);
+		out.print(" - ");
+		out.setWrapIndentFromColumn();
+		out.println(command.description());
+		out.setWrapIndent(0);
 	    }
 	} else {
 	    lookup(input.parameter(0)).help(cli, input.accept());
diff --git a/frysk-core/frysk/hpd/NoOptsCommand.java b/frysk-core/frysk/hpd/NoOptsCommand.java
index 7edc566..b37ce14 100644
--- a/frysk-core/frysk/hpd/NoOptsCommand.java
+++ b/frysk-core/frysk/hpd/NoOptsCommand.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2007, Red Hat Inc.
+// Copyright 2007, 2008, Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -39,6 +39,8 @@
 
 package frysk.hpd;
 
+import java.io.PrintWriter;
+
 /**
  * Handle commands that should not interpret options.
  */
@@ -72,8 +74,9 @@ public abstract class NoOptsCommand extends Command {
     abstract void interpretCommand(CLI cli, Input input);
     
     void help(CLI cli, Input input) {
-	cli.outWriter.print(syntax);
-	cli.outWriter.println();
-	cli.outWriter.println(full);
+	PrintWriter out = cli.getWordWrapWriter();
+	out.print(syntax);
+	out.println();
+	out.println(full);
     }
 }
\ No newline at end of file
diff --git a/frysk-core/frysk/hpd/ParameterizedCommand.java b/frysk-core/frysk/hpd/ParameterizedCommand.java
index 35ec6a6..d13a4ec 100644
--- a/frysk-core/frysk/hpd/ParameterizedCommand.java
+++ b/frysk-core/frysk/hpd/ParameterizedCommand.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2007, Red Hat Inc.
+// Copyright 2007, 2008, Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -43,6 +43,7 @@ import java.util.TreeMap;
 import java.util.Iterator;
 import java.util.SortedMap;
 import java.util.List;
+import frysk.util.WordWrapWriter;
 
 abstract class ParameterizedCommand extends Command {
     private final SortedMap longOptions = new TreeMap();
@@ -147,22 +148,34 @@ abstract class ParameterizedCommand extends Command {
     }
 
     void help(CLI cli, Input input) {
-	cli.outWriter.print(syntax);
+	WordWrapWriter out = cli.getWordWrapWriter();
+	out.print(syntax);
 	if (longOptions.size() > 0) {
-	    cli.outWriter.println(" -option ...; where options are:");
+	    out.println(" -option ...; where options are:");
+	    int maxLen = 0;
 	    for (Iterator i = longOptions.values().iterator();
 		 i.hasNext(); ) {
 		CommandOption option = (CommandOption)i.next();
-		cli.outWriter.print("  -");
-		cli.outWriter.print(option.longName);
-		cli.outWriter.print("\t");
-		cli.outWriter.print(option.description);
-		cli.outWriter.println();
+		maxLen = Math.max(maxLen, option.longName.length());
 	    }
+	    // 3 for the "  -", 5 for the gap.
+	    maxLen += 3 + 5;
+	    out.setWrapIndent(maxLen);
+	    for (Iterator i = longOptions.values().iterator();
+		 i.hasNext(); ) {
+		CommandOption option = (CommandOption)i.next();
+		out.print("  -");
+		out.print(option.longName);
+		for (int j = 3 + option.longName.length(); j < maxLen; ++j)
+		    out.print(" ");
+		out.print(option.description);
+		out.println();
+	    }
+	    out.setWrapIndent(0);
 	} else {
-	    cli.outWriter.println();
+	    out.println();
 	}
-	cli.outWriter.println(full);
+	out.println(full);
     }
 
     /**
diff --git a/frysk-core/frysk/util/ChangeLog b/frysk-core/frysk/util/ChangeLog
index a0e9e7b..9586367 100644
--- a/frysk-core/frysk/util/ChangeLog
+++ b/frysk-core/frysk/util/ChangeLog
@@ -1,3 +1,11 @@
+2008-03-02  Tom Tromey  <tromey@redhat.com>
+
+	* WordWrapWriter.java: Document.
+
+2008-03-02  Tom Tromey  <tromey@redhat.com>
+
+	* WordWrapWriter.java: New file.
+
 2008-02-29  Tom Tromey  <tromey@redhat.com>
 
 	* FlowControlWriter.java (outStream): Remove.
diff --git a/frysk-core/frysk/util/WordWrapWriter.java b/frysk-core/frysk/util/WordWrapWriter.java
new file mode 100644
index 0000000..e8da436
--- /dev/null
+++ b/frysk-core/frysk/util/WordWrapWriter.java
@@ -0,0 +1,211 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2008 Red Hat Inc.
+//
+// FRYSK is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+
+package frysk.util;
+
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.util.Locale;
+import java.text.BreakIterator;
+import java.text.StringCharacterIterator;
+
+/**
+ * This class is a PrintWriter which word-wraps the output.  It
+ * provides settings which control over the number of columns and
+ * indentation of wrapped lines.
+ */
+public class WordWrapWriter extends PrintWriter {
+    // Number of columns available.
+    private int columns;
+
+    // Amount of indentation to use on wrapped line.
+    private int wrapIndent;
+
+    // The break iterator, used to find the next line-break
+    // opportunity.
+    private BreakIterator iter;
+
+    // The current column.
+    private int column;
+
+    /**
+     * Create a new WordWrapWriter, specifying all parameters.
+     * @param outStream the output writer to wrap
+     * @param columns the number of columns to allow before wrapping
+     * @param wrapIndent the number of columns to indent after wrapping
+     * @param locale the locale to use for determining word breaks
+     */
+    public WordWrapWriter(Writer outStream, int columns, int wrapIndent, Locale locale) {
+	// Always enable auto-flush.
+	super(outStream, true);
+	this.columns = columns;
+	this.wrapIndent = wrapIndent;
+	this.iter = BreakIterator.getWordInstance(locale);
+    }
+
+    /**
+     * Create a new WordWrapWriter, specifying just the number of columns.
+     * By default there will be no indentation after a wrap, and the
+     * default locale will be used.
+     * @param outStream the output writer to wrap
+     * @param columns the number of columns to allow before wrapping
+     */
+    public WordWrapWriter(Writer outStream, int columns) {
+	this(outStream, columns, 0, Locale.getDefault());
+    }
+
+    /**
+     * Create a new WordWrapWriter using the defaults.  Wrapping will
+     * happen at column 72.  By default there will be no indentation
+     * after a wrap, and the default locale will be used.
+     * @param outStream the output writer to wrap
+     */
+    public WordWrapWriter(Writer outStream) {
+	this(outStream, 72, 0, Locale.getDefault());
+    }
+
+    /**
+     * Set the number of columns of output.  The writer will try to
+     * break a line before a word that would go past this column.
+     * @param columns the number of columns to allow before wrapping
+     */
+    public void setColumns(int columns) {
+	this.columns = columns;
+    }
+
+    /**
+     * Set the amount of indentation after wrapping.  This can be used
+     * to line up some text if it wraps past the end of the line.
+     * Indentation is accomplished by emitting spaces.  Tabs in the
+     * output are considered to move to the next column that is a
+     * multiple of 8 ("unix style").  An argument of 0 means that no
+     * indentation will be applied after wrapping.
+     * @param wrapIndent the number of columns to indent after wrapping
+     */
+    public void setWrapIndent(int wrapIndent) {
+	this.wrapIndent = wrapIndent;
+    }
+
+    /**
+     * Like setWrapIndent(int), but sets the indentation column based
+     * on the current column known to this writer.  This can be useful
+     * for aligning text when the precise formatting is not known --
+     * you can emit a prefix for a line, mark the indentation level,
+     * and then emit the remainder of the text, which will all line up
+     * at the marked position.
+     */
+    public void setWrapIndentFromColumn() {
+	this.wrapIndent = this.column;
+    }
+
+    // All PrintWriter output methods (in particular the print
+    // methods) eventually delegate to a write() method.  We override
+    // just the necessary ones to have everything work properly.
+    public void write(char[] buf, int offset, int len) {
+	// A bit inefficient but we don't care much.
+	write(new String(buf, offset, len));
+    }
+
+    public void write(int b) {
+	write(String.valueOf((char) b));
+    }
+
+    // Update 'column' assuming STR is printed.  We use a helper
+    // function here to properly handle tabs.
+    private void updateColumn(String str) {
+	int len = str.length();
+	for (int i = 0; i < len; ++i) {
+	    if (str.charAt(i) == '\t') {
+		column = 8 * ((column + 8) / 8);
+	    } else {
+		++column;
+	    }
+	}
+    }
+
+    public void write(String str, int offset, int len) {
+	int term = offset + len;
+	while (offset < term) {
+	    // Find the next newline, if there is one.
+	    int nlIndex = str.indexOf('\n', offset);
+	    if (nlIndex >= term)
+		nlIndex = -1;
+	    // Only operate on the current line.  If we don't see a
+	    // \n, operate on all the remaining text.
+	    int subLen = (nlIndex < 0) ? len : (nlIndex - offset + 1);
+	    iter.setText(new StringCharacterIterator(str, offset,
+						     offset + subLen, offset));
+	    int start = iter.first();
+	    int end = iter.next();
+	    boolean first = column == 0;
+	    while (end != BreakIterator.DONE) {
+		String word = str.substring(start, end);
+		updateColumn(word);
+		if (!first && column >= columns) {
+		    super.write('\n');
+		    for (int i = 0; i < wrapIndent; ++i)
+			super.write(' ');
+		    column = wrapIndent;
+		    // The first word on a line should not start with
+		    // a space.  We use '<=' to work like String.trim,
+		    // and to eliminate tabs as well.
+		    int j = 0;
+		    while (j < word.length() && word.charAt(j) <= ' ')
+			++j;
+		    if (j > 0)
+			word = word.substring(j);
+		    updateColumn(word);
+		}
+		first = false;
+		// Avoid recursion here...
+		super.write(word, 0, word.length());
+		start = end;
+		end = iter.next();
+	    }
+
+	    if (nlIndex >= 0) {
+		// We already wrote the \n.
+		column = 0;
+	    }
+
+	    offset += subLen;
+	    len -= subLen;
+	}
+    }
+}


hooks/post-receive
--
frysk system monitor/debugger


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-03-02 12:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-02 12:59 [SCM] master: Allign all help command option descriptions mark

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).