public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: tromey@redhat.com
Cc: Frysk List <frysk@sourceware.org>
Subject: Re: Patch: word-wrapping for 'help' output
Date: Sat, 01 Mar 2008 22:04:00 -0000	[thread overview]
Message-ID: <1204409018.3279.56.camel@localhost.localdomain> (raw)
In-Reply-To: <m34pbrjynl.fsf@fleche.redhat.com>

Hi Tom,

On Fri, 2008-02-29 at 13:27 -0700, Tom Tromey wrote:
> This patch implements word-wrapping for frysk 'help' output.

Wow, this is really useful!

> frysk-core/frysk/hpd/ChangeLog:
> 2008-02-29  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-02-29  Tom Tromey  <tromey@redhat.com>
> 
> 	* WordWrapWriter.java: New file.

Some very minor questions and suggestions. It is pretty good. Also I saw
no test regressions. Nice work.

> diff --git a/frysk-core/frysk/hpd/CLI.java b/frysk-core/frysk/hpd/CLI.java
> index 35bc9e5..67b3788 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,10 @@ public class CLI {
>              idManager.manageProc(proc, this.taskID);
>      }
>  
> +    WordWrapWriter getWordWrapWriter() {
> +	return new WordWrapWriter(outWriter);
> +    }

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

> +/**
> + * 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.
> + */

An example would be nice.

> +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;
> +
> +    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);
> +    }
> +
> +    public WordWrapWriter(Writer outStream, int columns) {
> +	this(outStream, columns, 0, Locale.getDefault());
> +    }
> +
> +    public WordWrapWriter(Writer outStream) {
> +	this(outStream, 72, 0, Locale.getDefault());
> +    }

The defaults should really be documented.

> +    public void setWrapIndentFromColumn() {
> +	this.wrapIndent = this.column;
> +    }

This could really use a comment. It took me a while to realize why it is
useful.

> +    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));
> +    }

A comment about which write methods there are in a PrintWriter would
have helped. I actually had to double check to see if you overrode them
all and whether the print() methods all delegate to the write() methods.

Thanks,

Mark

  reply	other threads:[~2008-03-01 22:04 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 [this message]
2008-03-02  0:17   ` Tom Tromey
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=1204409018.3279.56.camel@localhost.localdomain \
    --to=mark@klomp.org \
    --cc=frysk@sourceware.org \
    --cc=tromey@redhat.com \
    /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).