public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Mark Wielaard <mark@klomp.org>
Cc: Frysk List <frysk@sourceware.org>
Subject: Re: Patch: word-wrapping for 'help' output
Date: Sun, 02 Mar 2008 00:17:00 -0000	[thread overview]
Message-ID: <m3d4qef2kz.fsf@fleche.redhat.com> (raw)
In-Reply-To: <1204409018.3279.56.camel@localhost.localdomain> (Mark Wielaard's message of "Sat\, 01 Mar 2008 23\:03\:38 +0100")

Mark> This could use a method description.

You'll forgive me for assuming that the frysk style was not to write
javadoc.

Here's an add-on patch that adds javadoc.  Let me know what you think.
I guess I should learn git enough to supply consolidated patches.

Mark> The CLI doesn't have the PtyTerminal (created in fhpd.java).
Mark> It might make sense to pass that to the CLI so it can use
Mark> getTerminalWidth() here when constructing the WordWrapWriter.

I will look at this shortly.

Tom

b/frysk-core/frysk/hpd/ChangeLog:
2008-03-01  Tom Tromey  <tromey@redhat.com>

	* CLI.java (getWordWrapWriter): Document.

b/frysk-core/frysk/util/ChangeLog:
2008-03-01  Tom Tromey  <tromey@redhat.com>

	* WordWrapWriter.java: Document.

diff --git a/frysk-core/frysk/hpd/CLI.java b/frysk-core/frysk/hpd/CLI.java
index 67b3788..f8f16c8 100644
--- a/frysk-core/frysk/hpd/CLI.java
+++ b/frysk-core/frysk/hpd/CLI.java
@@ -182,6 +182,9 @@ public class CLI {
             idManager.manageProc(proc, this.taskID);
     }
 
+    /**
+     * Return a WordWrapWriter which wraps this CLI's output writer.
+     */
     WordWrapWriter getWordWrapWriter() {
 	return new WordWrapWriter(outWriter);
     }
diff --git a/frysk-core/frysk/util/WordWrapWriter.java b/frysk-core/frysk/util/WordWrapWriter.java
index 5aa8527..e8da436 100644
--- a/frysk-core/frysk/util/WordWrapWriter.java
+++ b/frysk-core/frysk/util/WordWrapWriter.java
@@ -64,6 +64,13 @@ public class WordWrapWriter extends PrintWriter {
     // 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);
@@ -72,26 +79,64 @@ public class WordWrapWriter extends PrintWriter {
 	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));

  reply	other threads:[~2008-03-02  0:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-29 21:18 Tom Tromey
2008-03-01 22:04 ` Mark Wielaard
2008-03-02  0:17   ` Tom Tromey [this message]
2008-03-02 12:34     ` Mark Wielaard
2008-03-02  0:42   ` Tom Tromey
2008-03-02 12:48     ` Mark Wielaard
2008-03-02 16:10       ` Tom Tromey
2008-03-02 22:05         ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3d4qef2kz.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=frysk@sourceware.org \
    --cc=mark@klomp.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).