From 1839df43af23741a0fee8677605a50cff92348a9 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 20 Nov 2014 14:47:20 -0500 Subject: [PATCH] Use fixed-with cut lines. Trying to get the terminal width fails under Emacs. Regression test passes. --- src | 26 +++++++----------- srctest | 82 ++++++++++++++++++++++++++++----------------------------- 2 files changed, 50 insertions(+), 58 deletions(-) diff --git a/src b/src index 68a4b98..522499d 100755 --- a/src +++ b/src @@ -58,14 +58,6 @@ import sys, os, subprocess, time, calendar, stat, glob, shutil, hashlib version="0.10" -def screenwidth(): - "Return the current width of the terminal window." - if pseudotime: - return 79 - else: - with popen_or_die(b'stty size', b"rb") as tp: - return int(tp.read().split()[1]) - def rfc3339(t): "RFC3339 string from Unix time." return time.strftime(b"%Y-%m-%dT%H:%M:%SZ", time.gmtime(t)) @@ -89,6 +81,10 @@ pseudotime = False # option -T: artificial clock for regression testing # Repo directory repodir = ".src" +# How to size cut lines. We used to do this dynamically from the screen size, +# but that fails under Emacs +WIDTH = 72 + def stamp(arg): "Name the stamp file used to track revisions." if os.sep not in arg: @@ -1129,13 +1125,11 @@ def list_method(*args): custom = args[0][2:] args.pop(0) ctx = CommandContext("list", args, default_to="branch_reversed") - if custom is None: - width = screenwidth() for arg in ctx.args: if ignore(arg) or not registered(arg): continue if custom is None: - sys.stdout.write("= %s %s\n" % (arg, ((width - len(arg) - 5) * "="))) + sys.stdout.write("= %s %s\n" % (arg, ((WIDTH - len(arg) - 3) * "="))) for item in ctx.resolve(History(arg), backwards=True): # Must allow enough room for revno and date if item.selected(): @@ -1144,7 +1138,7 @@ def list_method(*args): mark = "-" summary = item.log.split('\n')[0] if custom is None: - summary = summary[:width - 34] + summary = summary[:WIDTH - 34] sys.stdout.write("%-4d %s %s %s\n" \ % (item.revno, mark, item.date, summary)) else: @@ -1153,14 +1147,13 @@ def list_method(*args): def log_method(*args): "Report revision logs" ctx = CommandContext("log", args, default_to="branch_reversed") - width = screenwidth() for arg in ctx.args: if ignore(arg) or not registered(arg): continue - sys.stdout.write("= %s %s\n" % (arg, ((width - len(arg) - 5) * "="))) + sys.stdout.write("= %s %s\n" % (arg, ((WIDTH - len(arg) - 3) * "="))) for item in ctx.resolve(History(arg), backwards=True): sys.stdout.write("%-4d | %s\n%s" % (item.revno,item.date,item.log)) - sys.stdout.write(("-" * (width - 1)) + "\n") + sys.stdout.write(("-" * WIDTH) + "\n") def checkout_method(*args): "Refresh the working copy from the history file." @@ -1300,11 +1293,10 @@ def tag_helper(args, legend, validation_hook, delete_method, set_method): if args[0] in ("-l", "list"): args.pop(0) ctx = CommandContext(legend + " listing", args, require_empty=True) - width = screenwidth() for arg in ctx.args: metadata = History(arg) sys.stdout.write("= %s %s\n" \ - % (arg, ((width - len(arg) - 5) * "="))) + % (arg, ((WIDTH - len(arg) - 5) * "="))) keys = metadata.symbols.keys() if metadata.branch in keys: keys.remove(metadata.branch) diff --git a/srctest b/srctest index 6e13892..2d00f92 100755 --- a/srctest +++ b/srctest @@ -66,7 +66,7 @@ src $TESTOPTS cat testfile1 | diff -u testfile1 - check "content check after second commit" cat >testfile2 <testfile2 <testfile3 @@ -102,16 +102,16 @@ src $TESTOPTS commit -f testfile4 testfile1 >/dev/null check "commit with -f" cat >testfile4 <testfile5 @@ -119,7 +119,7 @@ diff -u testfile4 testfile5 check "3-commit log test" cat >testfile6 <testfile8 <testfile9 @@ -150,7 +150,7 @@ src $TESTOPTS tag create basetag 1 check "tag set to revision 1" cat >testfile10 <testfile12 <testfile13 @@ -467,22 +467,22 @@ text EOF cat >sample.seqlog <tryit @@ -490,19 +490,19 @@ diff -u tryit sample.seqlog check "traversal by -" cat >sample.branchlog <tryit @@ -510,7 +510,7 @@ diff -u tryit sample.branchlog check "traversal by .." cat >sample.taglog <changes <branchlist <branchlog <newlist <newlog <tryit -- 2.43.0