~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin Pool
  • Date: 2006-05-09 07:09:48 UTC
  • mto: This revision was merged to the branch mainline in revision 1707.
  • Revision ID: mbp@sourcefrog.net-20060509070948-734ebe91f1c96032
Detect terminal width using ioctl

Show diffs side-by-side

added added

removed removed

Lines of Context:
673
673
    # TODO: Is there anything that gets a better update when the window
674
674
    # is resized while the program is running? We could use the Python termcap
675
675
    # library.
 
676
 
 
677
    width = 0
 
678
    
676
679
    try:
677
 
        return int(os.environ['COLUMNS'])
678
 
    except (IndexError, KeyError, ValueError):
679
 
        return 80
 
680
        import struct, fcntl, termios
 
681
        s = struct.pack('HHHH', 0, 0, 0, 0)
 
682
        x = fcntl.ioctl(1, termios.TIOCGWINSZ, s)
 
683
        width = struct.unpack('HHHH', x)[1]
 
684
    except IOError:
 
685
        pass
 
686
    if width <= 0:
 
687
        try:
 
688
            width = int(os.environ['COLUMNS'])
 
689
        except:
 
690
            pass
 
691
    if width <= 0:
 
692
        width = 80
 
693
 
 
694
    return width
680
695
 
681
696
def supports_executable():
682
697
    return sys.platform != "win32"