6

我们有一个高度并行化的构建过程,所以我经常不得不浏览 javac 的大量输出来查找构建错误。

为了使这更容易,如果有一些工具可以将 javac 的输出着色到我的终端,并突出显示代码中的错误,那就太好了。

我可以使用什么工具来着色 javac 的输出?

4

3 回答 3

1

grep与“--color”选项一起使用?

~$ javac Test.java 2>&1 | egrep --color "^|error"
于 2012-10-03T06:33:41.800 回答
0

我最终使用了一个名为Generic Colorizer Tool的工具,并编写了自己的配置来为最重要的输出着色。工作得很好。:)

于 2012-10-20T15:18:59.040 回答
0

通过使用任何正则表达式匹配器来匹配您的文本并用终端颜色转义码将其包围以应用颜色,从而滚动您自己的 javac 错误着色器:

使用readfilesubstitute意识形态:

#1.  Do your javac and pipe the result to a file:
javac whatever.java 2>/tmp/javac_errors.out;

#define the escape start and stop codes that your terminal 
#uses to apply foreground and background color:
let redbackground        = '\\e[48;5;196m'
let normalbackground     = '\\e[0;0m'

#iterate the lines in the saved file:
for line in readfile("/tmp/javac_errors.out")

    #Use sed, match, substitute or whatever to regex substitute 
    #the text with the text surrounded by the color escape codes
    #find and replace the text 'error:' with the same surrounded by escape codes
    let line = substitute(line, 
                          'error:',
                           redbackground . 
                           'error:' . 
                           normalbackground, 'g')

    #use echo -e flag to tell the terminal to interpret the escape codes:
    echo -e line
endfor

为我工作:

javac着色示例

此代码与上面相同,但它使用终端行迭代器和sed替换思想:

#run javac pipe to file
javac whatever.java 2>/tmp/errors.out

#Define terminal color codes
redbackground='\\e[48;5;196m'
normalbackground='\\e[0;0m'

#read the file and print out each line 
filename="/tmp/errors.out" 
while read -r line; do  
    #replace error surround with escape codes 
    line=`sed "s/error:/${redbackground}error:${normalbackground}/g" <<<"$line"` 
    echo -e "$line" 
done < "$filename" 
于 2018-12-12T05:29:59.570 回答