Skip to content

Instantly share code, notes, and snippets.

@bheesham
Created April 7, 2014 23:00
Show Gist options
  • Save bheesham/10071368 to your computer and use it in GitHub Desktop.
Save bheesham/10071368 to your computer and use it in GitHub Desktop.
Highlights tabs (red, 8 spaces) and spaces (green)
#!/usr/bin/env python3
__author__ = 'Bheesham Persaud <bheesham.persaud@live.ca>'
__license__ = 'ISC License'
__copyright__ = 'Copyright (C) 2014 Bheesham Persaud.'
__version__ = '0.0.1'
__usage__ = """tas <input file>
highlights tabs and spaces
"""
import sys, string
from colorama import init, Back, Style
init(autoreset=True)
def highlight_indent(line):
ret = ''
no_skip = True
for i in range(len(line)):
if line[i] in string.whitespace and no_skip:
if line[i] == ' ':
print(Back.GREEN + ' ', end='')
elif line[i] == '\t':
for _ in range(8):
print(Back.RED + ' ', end='')
else:
no_skip = False
print(line[i], end='')
def tas(file):
handle = open(file, 'r')
for line in handle:
highlight_indent(line)
if __name__ == '__main__':
if len(sys.argv) != 2:
print(__usage__)
else:
tas(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment