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:42:00 -0000	[thread overview]
Message-ID: <m37igmf1ew.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> 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  <tromey@redhat.com>

	* fhpd.java (CommandLine): Pass terminal to CLI constructor.

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

	* 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() {

  parent reply	other threads:[~2008-03-02  0:42 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
2008-03-02 12:34     ` Mark Wielaard
2008-03-02  0:42   ` Tom Tromey [this message]
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=m37igmf1ew.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).