From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22358 invoked by alias); 2 Mar 2008 00:42:33 -0000 Received: (qmail 22347 invoked by uid 22791); 2 Mar 2008 00:42:32 -0000 X-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_34,J_CHICKENPOX_36,J_CHICKENPOX_44,J_CHICKENPOX_46,J_CHICKENPOX_48,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:42:12 +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 m220g9Ar028273; Sat, 1 Mar 2008 19:42:09 -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 m220g84p032475; Sat, 1 Mar 2008 19:42:08 -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 m220g8AK017745; Sat, 1 Mar 2008 19:42:08 -0500 Received: by opsy.redhat.com (Postfix, from userid 500) id 65B543780C7; Sat, 1 Mar 2008 16:51:51 -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:42: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/msg00102.txt.bz2 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. Here's a patch to do it -- but *don't* check this in. getTerminalWidth seems to return something bogus, because everything started wrapping at column 20. I didn't look into this any more deeply. Tom b/frysk-core/frysk/bindir/ChangeLog: 2008-03-01 Tom Tromey * fhpd.java (CommandLine): Pass terminal to CLI constructor. b/frysk-core/frysk/hpd/ChangeLog: 2008-03-01 Tom Tromey * CLI.java (terminal): New field. (CLI): Add 'terminal' argument. (CLI(String,ObservingTerminal,Writer)): New constructor. (getWordWrapWriter): Compute number of columns. diff --git a/frysk-core/frysk/bindir/fhpd.java b/frysk-core/frysk/bindir/fhpd.java index efc8520..69be24c 100644 --- a/frysk-core/frysk/bindir/fhpd.java +++ b/frysk-core/frysk/bindir/fhpd.java @@ -106,7 +106,7 @@ public class fhpd { FlowControlWriter writer = new FlowControlWriter(printWriter); terminal.getObservable() .addObserver(new TerminalObserver(writer)); - cli = new CLI("(fhpd) ", writer); + cli = new CLI("(fhpd) ", terminal, writer); reader = new ConsoleReader (new FileInputStream(java.io.FileDescriptor.in), printWriter, diff --git a/frysk-core/frysk/hpd/CLI.java b/frysk-core/frysk/hpd/CLI.java index f8f16c8..08e8ed6 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.ObservingTerminal; import frysk.util.WordWrapWriter; import frysk.expr.Expression; import frysk.expr.ScratchSymTab; @@ -186,10 +187,17 @@ public class CLI { * Return a WordWrapWriter which wraps this CLI's output writer. */ WordWrapWriter getWordWrapWriter() { - return new WordWrapWriter(outWriter); + // If there is no terminal, use the standard. + int cols = terminal == null ? 80 : terminal.getTerminalWidth(); + // Subtract a bit so that the words don't run right up to the + // terminal's edge. But, if the user makes a very silly + // terminal size, just pick something a bit less weird. + cols = Math.max(20, cols - 8); + return new WordWrapWriter(outWriter, cols); } final PrintWriter outWriter; + final ObservingTerminal terminal; private Preprocessor prepro; private String prompt; // string to represent prompt, will be moved private final Command topLevelCommand = new TopLevelCommand(); @@ -226,11 +234,13 @@ public class CLI { /** * Constructor * @param prompt String initially to be used as the prompt + * @param terminal the terminal to which we are connected * @param out PrintWriter for output * @param steppingEngine existing SteppingEngine */ - public CLI(String prompt, Writer outWriter, SteppingEngine steppingEngine) { + public CLI(String prompt, ObservingTerminal terminal, Writer outWriter, SteppingEngine steppingEngine) { this.prompt = prompt; + this.terminal = terminal; this.outWriter = new PrintWriter(outWriter); this.steppingEngine = steppingEngine; idManager = ProcTaskIDManager.getSingleton(); @@ -262,10 +272,20 @@ public class CLI { /** * Constructor that creates a new steppingEngine * @param prompt String initially to be used as the prompt + * @param terminal the terminal to which we are connected + * @param out PrintWriter for output. + */ + public CLI(String prompt, ObservingTerminal terminal, Writer outWriter) { + this(prompt, terminal, outWriter, new SteppingEngine()); + } + + /** + * Constructor that creates a new steppingEngine + * @param prompt String initially to be used as the prompt * @param out PrintWriter for output. */ public CLI(String prompt, Writer outWriter) { - this(prompt, outWriter, new SteppingEngine()); + this(prompt, null, outWriter, new SteppingEngine()); } public String getPrompt() {