Mercurial > public > mercurial-scm > hg
comparison mercurial/win32.py @ 30314:365812902904
scmutil: extend termwidth() to return terminal height, renamed to termsize()
It appears crecord.py has its own termsize() function. I want to get rid of it.
The fallback height is chosen from the default of cmd.exe on Windows, and
VT100 on Unix.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 20 Oct 2016 23:09:05 +0900 |
parents | 392633d7860e |
children | 344e68882cd3 |
comparison
equal
deleted
inserted
replaced
30313:392633d7860e | 30314:365812902904 |
---|---|
345 return True | 345 return True |
346 | 346 |
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 |
370 | 372 |
371 None is returned when no child is found''' | 373 None is returned when no child is found''' |