From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15025 invoked by alias); 2 Mar 2008 00:17:15 -0000 Received: (qmail 15017 invoked by uid 22791); 2 Mar 2008 00:17:14 -0000 X-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_34,J_CHICKENPOX_44,J_CHICKENPOX_47,J_CHICKENPOX_53,J_CHICKENPOX_63,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 02 Mar 2008 00:16:57 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m220GsK6020093; Sat, 1 Mar 2008 19:16:54 -0500 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m220Grsv026382; Sat, 1 Mar 2008 19:16:53 -0500 Received: from opsy.redhat.com (vpn-14-173.rdu.redhat.com [10.11.14.173]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m220GqLL014499; Sat, 1 Mar 2008 19:16:53 -0500 Received: by opsy.redhat.com (Postfix, from userid 500) id 5F3663780C7; Sat, 1 Mar 2008 16:26:36 -0700 (MST) To: Mark Wielaard Cc: Frysk List Subject: Re: Patch: word-wrapping for 'help' output References: <1204409018.3279.56.camel@localhost.localdomain> From: Tom Tromey Reply-To: Tom Tromey X-Attribution: Tom Date: Sun, 02 Mar 2008 00:17:00 -0000 In-Reply-To: <1204409018.3279.56.camel@localhost.localdomain> (Mark Wielaard's message of "Sat\, 01 Mar 2008 23\:03\:38 +0100") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.990 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 X-IsSubscribed: yes Mailing-List: contact frysk-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-owner@sourceware.org X-SW-Source: 2008-q1/txt/msg00101.txt.bz2 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 * CLI.java (getWordWrapWriter): Document. b/frysk-core/frysk/util/ChangeLog: 2008-03-01 Tom Tromey * 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));