Patchwork [2,of,7] scmutil: make termwidth() obtain stdio from ui

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 4, 2016, 7:48 a.m.
Message ID <433d529a9bbb40172812.1478245737@mimosa>
Download mbox | patch
Permalink /patch/17335/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 4, 2016, 7:48 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1476967331 -32400
#      Thu Oct 20 21:42:11 2016 +0900
# Node ID 433d529a9bbb4017281215dd3fa028410682e4dc
# Parent  e8790ea449691089861957e8259adb2a753748c8
# EXP-Topic stdio
scmutil: make termwidth() obtain stdio from ui

I'm getting rid of direct sys.stderr|out|in references so Py3 porting will
be slightly easier.

Patch

diff --git a/mercurial/scmposix.py b/mercurial/scmposix.py
--- a/mercurial/scmposix.py
+++ b/mercurial/scmposix.py
@@ -41,11 +41,11 @@  def userrcpath():
     else:
         return [os.path.expanduser('~/.hgrc')]
 
-def termwidth():
+def termwidth(ui):
     try:
         import array
         import termios
-        for dev in (sys.stderr, sys.stdout, sys.stdin):
+        for dev in (ui.ferr, ui.fout, ui.fin):
             try:
                 try:
                     fd = dev.fileno()
diff --git a/mercurial/scmwindows.py b/mercurial/scmwindows.py
--- a/mercurial/scmwindows.py
+++ b/mercurial/scmwindows.py
@@ -53,5 +53,5 @@  def userrcpath():
         path.append(os.path.join(userprofile, '.hgrc'))
     return path
 
-def termwidth():
+def termwidth(ui):
     return win32.termwidth()
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -822,7 +822,7 @@  class ui(object):
                 return int(encoding.environ['COLUMNS'])
             except ValueError:
                 pass
-        return scmutil.termwidth()
+        return scmutil.termwidth(self)
 
     def formatted(self):
         '''should formatted output be used?