Skip to content

Instantly share code, notes, and snippets.

@Himanshu-Mishr
Created March 27, 2015 18:02
Show Gist options
  • Save Himanshu-Mishr/44a4c87a8799f74c3880 to your computer and use it in GitHub Desktop.
Save Himanshu-Mishr/44a4c87a8799f74c3880 to your computer and use it in GitHub Desktop.
BEO - Better Error Output. works with GCC/G++. Requires python3
#!/bin/python3
#
# Copyright 2015 Himanshu Mishra
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
import subprocess
import sys
import re
def printError(outputList):
"""Beautifying error output"""
# print(outputList)
for i in outputList:
d = i.split(":")
content = i
content = re.sub(r"‘", "'\033[1m", content)
content = re.sub(r"’", "\033[1;m'", content)
i = content
content = i
content = re.sub(r"note", "\033[32mnote\033[1;m", content)
content = re.sub(r"warning", "\033[33mwarning\033[1;m", content)
content = re.sub(r"error", "\033[31merror\033[1;m", content)
i = content
if len(d) > 1:
print("\033[1;33m" + d[0] +"\033[1;m", end="")
l = len(d[0])
print(i[l:])
else:
if "^" in i:
print('\033[1;31m'+ i +'\033[1;m')
else:
print('\033[1;37m'+ i +'\033[1;m')
def colorizeError():
"""main function"""
restArgument = sys.argv[:]
restArgument[0] = '/usr/bin/gcc'
cmd = subprocess.Popen(restArgument, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = cmd.communicate()
errorList = err.decode('utf-8').split('\n')
if len(errorList) > 2:
print('\033[1;31mError during compiling\033[1;m')
printError(errorList)
else:
# outputList = out.decode('utf-8').split('\n')
print('\033[1;32mCompiled successfully\033[1;m')
return 0
if __name__ == '__main__':
colorizeError()
@Himanshu-Mishr
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment