##// END OF EJS Templates
scmutil: extend termwidth() to return terminal height, renamed to termsize()...
Yuya Nishihara -
r30314:36581290 default
parent child Browse files
Show More
@@ -42,12 +42,12 b' def userrcpath():'
42 else:
42 else:
43 return [os.path.expanduser('~/.hgrc')]
43 return [os.path.expanduser('~/.hgrc')]
44
44
45 def termwidth(ui):
45 def termsize(ui):
46 try:
46 try:
47 import termios
47 import termios
48 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449)
48 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449)
49 except (AttributeError, ImportError):
49 except (AttributeError, ImportError):
50 return 80
50 return 80, 24
51
51
52 for dev in (ui.ferr, ui.fout, ui.fin):
52 for dev in (ui.ferr, ui.fout, ui.fin):
53 try:
53 try:
@@ -58,9 +58,9 b' def termwidth(ui):'
58 if not os.isatty(fd):
58 if not os.isatty(fd):
59 continue
59 continue
60 arri = fcntl.ioctl(fd, TIOCGWINSZ, '\0' * 8)
60 arri = fcntl.ioctl(fd, TIOCGWINSZ, '\0' * 8)
61 width = array.array('h', arri)[1]
61 height, width = array.array('h', arri)[:2]
62 if width > 0:
62 if width > 0 and height > 0:
63 return width
63 return width, height
64 except ValueError:
64 except ValueError:
65 pass
65 pass
66 except IOError as e:
66 except IOError as e:
@@ -68,4 +68,4 b' def termwidth(ui):'
68 pass
68 pass
69 else:
69 else:
70 raise
70 raise
71 return 80
71 return 80, 24
@@ -40,7 +40,7 b' else:'
40
40
41 systemrcpath = scmplatform.systemrcpath
41 systemrcpath = scmplatform.systemrcpath
42 userrcpath = scmplatform.userrcpath
42 userrcpath = scmplatform.userrcpath
43 termwidth = scmplatform.termwidth
43 termsize = scmplatform.termsize
44
44
45 class status(tuple):
45 class status(tuple):
46 '''Named tuple with a list of files per status. The 'deleted', 'unknown'
46 '''Named tuple with a list of files per status. The 'deleted', 'unknown'
@@ -53,5 +53,5 b' def userrcpath():'
53 path.append(os.path.join(userprofile, '.hgrc'))
53 path.append(os.path.join(userprofile, '.hgrc'))
54 return path
54 return path
55
55
56 def termwidth(ui):
56 def termsize(ui):
57 return win32.termwidth()
57 return win32.termsize()
@@ -822,7 +822,7 b' class ui(object):'
822 return int(encoding.environ['COLUMNS'])
822 return int(encoding.environ['COLUMNS'])
823 except ValueError:
823 except ValueError:
824 pass
824 pass
825 return scmutil.termwidth(self)
825 return scmutil.termsize(self)[0]
826
826
827 def formatted(self):
827 def formatted(self):
828 '''should formatted output be used?
828 '''should formatted output be used?
@@ -347,23 +347,25 b' def hidewindow():'
347 pid = _kernel32.GetCurrentProcessId()
347 pid = _kernel32.GetCurrentProcessId()
348 _user32.EnumWindows(_WNDENUMPROC(callback), pid)
348 _user32.EnumWindows(_WNDENUMPROC(callback), pid)
349
349
350 def termwidth():
350 def termsize():
351 # cmd.exe does not handle CR like a unix console, the CR is
351 # cmd.exe does not handle CR like a unix console, the CR is
352 # counted in the line length. On 80 columns consoles, if 80
352 # counted in the line length. On 80 columns consoles, if 80
353 # characters are written, the following CR won't apply on the
353 # characters are written, the following CR won't apply on the
354 # current line but on the new one. Keep room for it.
354 # current line but on the new one. Keep room for it.
355 width = 80 - 1
355 width = 80 - 1
356 height = 25
356 # Query stderr to avoid problems with redirections
357 # Query stderr to avoid problems with redirections
357 screenbuf = _kernel32.GetStdHandle(
358 screenbuf = _kernel32.GetStdHandle(
358 _STD_ERROR_HANDLE) # don't close the handle returned
359 _STD_ERROR_HANDLE) # don't close the handle returned
359 if screenbuf is None or screenbuf == _INVALID_HANDLE_VALUE:
360 if screenbuf is None or screenbuf == _INVALID_HANDLE_VALUE:
360 return width
361 return width, height
361 csbi = _CONSOLE_SCREEN_BUFFER_INFO()
362 csbi = _CONSOLE_SCREEN_BUFFER_INFO()
362 if not _kernel32.GetConsoleScreenBufferInfo(
363 if not _kernel32.GetConsoleScreenBufferInfo(
363 screenbuf, ctypes.byref(csbi)):
364 screenbuf, ctypes.byref(csbi)):
364 return width
365 return width, height
365 width = csbi.srWindow.Right - csbi.srWindow.Left # don't '+ 1'
366 width = csbi.srWindow.Right - csbi.srWindow.Left # don't '+ 1'
366 return width
367 height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1
368 return width, height
367
369
368 def _1stchild(pid):
370 def _1stchild(pid):
369 '''return the 1st found child of the given pid
371 '''return the 1st found child of the given pid
General Comments 0
You need to be logged in to leave comments. Login now