crecord: use scmutil.termsize()
authorYuya Nishihara <yuya@tcha.org>
Thu, 20 Oct 2016 23:16:32 +0900
changeset 30315 0911191dc4c9
parent 30314 365812902904
child 30316 faf1b8923da2
crecord: use scmutil.termsize()
mercurial/crecord.py
--- a/mercurial/crecord.py	Thu Oct 20 23:09:05 2016 +0900
+++ b/mercurial/crecord.py	Thu Oct 20 23:16:32 2016 +0900
@@ -14,14 +14,13 @@
 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 @@
 
 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 @@
     """
     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 @@
 
     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 @@
         "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)