Patchwork [7,of,7] crecord: use scmutil.termsize()

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 4, 2016, 7:49 a.m.
Message ID <afbe258b29cc994cfabf.1478245742@mimosa>
Download mbox | patch
Permalink /patch/17340/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 4, 2016, 7:49 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1476972992 -32400
#      Thu Oct 20 23:16:32 2016 +0900
# Node ID afbe258b29cc994cfabf6dcc7a31be245c2bec2c
# Parent  5a6ee9257e4d6c67c6414b9d0f0fef35d3f2d545
# EXP-Topic stdio
crecord: use scmutil.termsize()
Pierre-Yves David - Nov. 7, 2016, 3:03 p.m.
On 11/04/2016 08:49 AM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1476972992 -32400
> #      Thu Oct 20 23:16:32 2016 +0900
> # Node ID afbe258b29cc994cfabf6dcc7a31be245c2bec2c
> # Parent  5a6ee9257e4d6c67c6414b9d0f0fef35d3f2d545
> # EXP-Topic stdio
> crecord: use scmutil.termsize()

This is pushed, thanks.

Patch

diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -14,14 +14,13 @@  import locale
 import os
 import re
 import signal
-import struct
-import sys
 
 from .i18n import _
 from . import (
     encoding,
     error,
     patch as patchmod,
+    scmutil,
     util,
 )
 stringio = util.stringio
@@ -52,11 +51,7 @@  patchhelptext = _("""#
 
 try:
     import curses
-    import fcntl
-    import termios
     curses.error
-    fcntl.ioctl
-    termios.TIOCGWINSZ
 except ImportError:
     # I have no idea if wcurses works with crecord...
     try:
@@ -75,8 +70,6 @@  def checkcurses(ui):
     """
     return curses and ui.interface("chunkselector") == "curses"
 
-_origstdout = sys.__stdout__ # used by gethw()
-
 class patchnode(object):
     """abstract class for patch graph nodes
     (i.e. patchroot, header, hunk, hunkline)
@@ -473,18 +466,6 @@  def filterpatch(ui, chunks, chunkselecto
 
     return (appliedhunklist, ret)
 
-def gethw():
-    """
-    magically get the current height and width of the window (without initscr)
-
-    this is a rip-off of a rip-off - taken from the bpython code.  it is
-    useful / necessary because otherwise curses.initscr() must be called,
-    which can leave the terminal in a nasty state after exiting.
-    """
-    h, w = struct.unpack(
-        "hhhh", fcntl.ioctl(_origstdout, termios.TIOCGWINSZ, "\000"*8))[0:2]
-    return h, w
-
 def chunkselector(ui, headerlist):
     """
     curses interface to get selection of chunks, and mark the applied flags
@@ -1259,7 +1240,7 @@  class curseschunkselector(object):
         "handle window resizing"
         try:
             curses.endwin()
-            self.yscreensize, self.xscreensize = gethw()
+            self.xscreensize, self.yscreensize = scmutil.termsize(self.ui)
             self.statuswin.resize(self.numstatuslines, self.xscreensize)
             self.numpadlines = self.getnumlinesdisplayed(ignorefolding=True) + 1
             self.chunkpad = curses.newpad(self.numpadlines, self.xscreensize)