Last active
July 20, 2016 23:57
-
-
Save ajeddeloh/023f0646d4c1570c4f2bf99bd62e27cd to your computer and use it in GitHub Desktop.
jq for go structs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import sys | |
indent = 0 | |
# characters to increase the indent | |
indentchars = '{[' | |
# characters to decrease the indent | |
unindentchars = '}]' | |
# characters to cause a line break | |
nlchars = ' \n' | |
# where to have indentchars on the same line | |
sameline = True | |
while True: | |
c = sys.stdin.read(1) | |
if c == '': | |
break | |
if c in indentchars: | |
if not sameline: | |
print('\n', ' ' * indent, sep='', end='') | |
print(c) | |
indent += 2 | |
print(' ' * indent, end='') | |
elif c in unindentchars: | |
print('') | |
indent -= 2 | |
print(' ' * indent, end='') | |
print(c, end='') | |
elif c in nlchars: | |
print('') | |
print(' ' * indent, end='') | |
else: | |
print(c, end='') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment