Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions coloredlogcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@

HEADER_SIZE = USER_WIDTH + PROCESS_WIDTH + TAG_WIDTH + PRIORITY_WIDTH + 4

# enable interactive mode only if we're printing to a tty, not if we're piping to someone
interactive = sys.stdout.isatty()

# unpack the current terminal width/height
data = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, '1234')
HEIGHT, WIDTH = struct.unpack('hh',data)
if interactive:
data = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, '1234')
HEIGHT, WIDTH = struct.unpack('hh',data)

BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)

Expand Down Expand Up @@ -143,6 +147,7 @@ def millis_color(match):
try:
line = input.readline()
except KeyboardInterrupt:
sys.stdout.flush()
break

line = line.expandtabs(4)
Expand Down Expand Up @@ -201,7 +206,8 @@ def millis_color(match):
message = retime.sub(millis_color, message)

# insert line wrapping as needed
message = indent_wrap(message, HEADER_SIZE, WIDTH)
if interactive:
message = indent_wrap(message, HEADER_SIZE, WIDTH)

linebuf.write(message)
print linebuf.getvalue()