[37316] trunk/base/src

raimue at macports.org raimue at macports.org
Mon Jun 2 16:37:44 PDT 2008


Revision: 37316
          http://trac.macosforge.org/projects/macports/changeset/37316
Author:   raimue at macports.org
Date:     2008-06-02 16:37:43 -0700 (Mon, 02 Jun 2008)

Log Message:
-----------
port/port.tcl, macports1.0/macports.tcl:
Use current terminal size instead of a hardcoded width. This uses the COLUMNS
environment variable which therefore should be preserved by the env cleanup in
macports.tcl. See #15488.

Modified Paths:
--------------
    trunk/base/src/macports1.0/macports.tcl
    trunk/base/src/port/port.tcl

Modified: trunk/base/src/macports1.0/macports.tcl
===================================================================
--- trunk/base/src/macports1.0/macports.tcl	2008-06-02 22:45:18 UTC (rev 37315)
+++ trunk/base/src/macports1.0/macports.tcl	2008-06-02 23:37:43 UTC (rev 37316)
@@ -658,6 +658,7 @@
         PATCH_SITE_LOCAL PATH PORTSRC RSYNC_PROXY TMP TMPDIR
         USER GROUP
         http_proxy HTTPS_PROXY FTP_PROXY ALL_PROXY NO_PROXY
+        COLUMNS LINES
     }
     if {[info exists extra_env]} {
         set keepenvkeys [concat ${keepenvkeys} ${extra_env}]

Modified: trunk/base/src/port/port.tcl
===================================================================
--- trunk/base/src/port/port.tcl	2008-06-02 22:45:18 UTC (rev 37315)
+++ trunk/base/src/port/port.tcl	2008-06-02 23:37:43 UTC (rev 37316)
@@ -397,15 +397,39 @@
 }
 
 ##
+# Makes sure we get the current terminal size
+proc set_term_size {} {
+    global env
+
+    if {![info exists env(COLUMNS)] || ![info exists env(LINES)]} {
+        if {![catch {exec stty size} err]} {
+            regexp {(\d+) (\d+)} $err -> rows cols
+            set env(COLUMNS) $cols
+            set env(LINES) $rows
+        } else {
+            puts stderr "Warning: Unable to get terminal size, using 80x24!"
+            set cols 80
+            set rows 24
+        }
+    }
+}
+
+##
 # Wraps a multi-line string at specified textwidth
 #
 # @see wrapline
 #
 # @param string input string
-# @param maxlen text width (indent length not counted)
+# @param maxlen text width (0 defaults to current terminal width)
 # @param indent prepend to every line
 # @return wrapped string
 proc wrap {string maxlen {indent ""} {indentfirstline 1}} {
+    global env
+
+    if {$maxlen == 0} {
+        set maxlen $env(COLUMNS)
+    }
+
     set splitstring {}
     foreach line [split $string "\n"] {
         lappend splitstring [wrapline $line $maxlen $indent $indentfirstline]
@@ -419,10 +443,16 @@
 # @see wrap
 #
 # @param line input line
-# @param maxlen text width (indent length not counted)
+# @param maxlen text width (0 defaults to current terminal width)
 # @param indent prepend to every line
 # @return wrapped string
 proc wrapline {line maxlen {indent ""} {indentfirstline 1}} {
+    global env
+
+    if {$maxlen == 0} {
+        set maxlen $env(COLUMNS)
+    }
+
     set string [split $line " "]
     if {$indentfirstline == 0} {
         set newline ""
@@ -1183,7 +1213,7 @@
 
         set ret "Usage: "
         set len [string length $action]
-        append ret [wrap "$action$cmds$args" 80 [string repeat " " [expr 8 + $len]] 0]
+        append ret [wrap "$action$cmds$args" 0 [string repeat " " [expr 8 + $len]] 0]
         append ret "\n"
 
         return $ret
@@ -1410,14 +1440,14 @@
                     set joiner ", "
                 }
                 puts -nonewline "Variants:    "
-                puts [wrap $vars 80 [string repeat " " 13] 0]
+                puts [wrap $vars 0 [string repeat " " 13] 0]
             }
             puts ""
             if {[info exists portinfo(long_description)]} {
-                puts [wrap [join $portinfo(long_description)] 80]
+                puts [wrap [join $portinfo(long_description)] 0]
             } else {
                 if {[info exists portinfo(description)]} {
-                    puts [wrap [join $portinfo(description)] 80]
+                    puts [wrap [join $portinfo(description)] 0]
                 }
             }
             if {[info exists portinfo(homepage)]} {
@@ -2100,7 +2130,7 @@
                         puts -nonewline " ([join $portinfo(categories) ", "])"
                     }
                     puts ""
-                    puts [wrap [join $portinfo(description)] 80 [string repeat " " 4]]
+                    puts [wrap [join $portinfo(description)] 0 [string repeat " " 4]]
                 }
             }
 
@@ -3050,6 +3080,10 @@
 # Global options private to this script
 array set private_options {}
 
+# Make sure we get the size of the terminal
+# We do this here to save it in the boot_env, in case we determined it manually
+set_term_size
+
 # Save off a copy of the environment before mportinit monkeys with it
 global env boot_env
 array set boot_env [array get env]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080602/2a5bf89a/attachment-0001.htm 


More information about the macports-changes mailing list