~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-05-12 23:48:49 UTC
  • mfrom: (1704.2.13 bzr.mbp.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060512234849-259ff209fff58489
(mbp) various fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
                           IllegalPath,
40
40
                           )
41
41
from bzrlib.trace import mutter
 
42
import bzrlib.win32console
42
43
 
43
44
 
44
45
def make_readonly(filename):
667
668
 
668
669
def terminal_width():
669
670
    """Return estimated terminal width."""
670
 
 
671
 
    # TODO: Do something smart on Windows?
672
 
 
673
 
    # TODO: Is there anything that gets a better update when the window
674
 
    # is resized while the program is running? We could use the Python termcap
675
 
    # library.
 
671
    if sys.platform == 'win32':
 
672
        import bzrlib.win32console
 
673
        return bzrlib.win32console.get_console_size()[0]
 
674
    width = 0
676
675
    try:
677
 
        return int(os.environ['COLUMNS'])
678
 
    except (IndexError, KeyError, ValueError):
679
 
        return 80
 
676
        import struct, fcntl, termios
 
677
        s = struct.pack('HHHH', 0, 0, 0, 0)
 
678
        x = fcntl.ioctl(1, termios.TIOCGWINSZ, s)
 
679
        width = struct.unpack('HHHH', x)[1]
 
680
    except IOError:
 
681
        pass
 
682
    if width <= 0:
 
683
        try:
 
684
            width = int(os.environ['COLUMNS'])
 
685
        except:
 
686
            pass
 
687
    if width <= 0:
 
688
        width = 80
 
689
 
 
690
    return width
680
691
 
681
692
def supports_executable():
682
693
    return sys.platform != "win32"