]> arthur.barton.de Git - bup.git/blob - cmd/newliner-cmd.py
wvtest: set a very large timeout to disable test time colors
[bup.git] / cmd / newliner-cmd.py
1 #!/bin/sh
2 """": # -*-python-*-
3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
5 """
6 # end of bup preamble
7 import sys, os, re
8 from bup import options
9 from bup import _helpers   # fixes up sys.argv on import
10
11 optspec = """
12 bup newliner
13 """
14 o = options.Options(optspec)
15 (opt, flags, extra) = o.parse(sys.argv[1:])
16
17 if extra:
18     o.fatal("no arguments expected")
19
20 r = re.compile(r'([\r\n])')
21 lastlen = 0
22 all = ''
23 width = options._tty_width() or 78
24 while 1:
25     l = r.split(all, 1)
26     if len(l) <= 1:
27         if len(all) >= 160:
28             sys.stdout.write('%s\n' % all[:78])
29             sys.stdout.flush()
30             all = all[78:]
31         try:
32             b = os.read(sys.stdin.fileno(), 4096)
33         except KeyboardInterrupt:
34             break
35         if not b:
36             break
37         all += b
38     else:
39         assert(len(l) == 3)
40         (line, splitchar, all) = l
41         if splitchar == '\r':
42             line = line[:width]
43         sys.stdout.write('%-*s%s' % (lastlen, line, splitchar))
44         if splitchar == '\r':
45             lastlen = len(line)
46         else:
47             lastlen = 0
48         sys.stdout.flush()
49
50 if lastlen:
51     sys.stdout.write('%-*s\r' % (lastlen, ''))
52 if all:
53     sys.stdout.write('%s\n' % all)