- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想在 linux 终端上使用 sed 命令高亮显示 C 程序的函数名称。
我可以使用 tput 为函数名称着色。为此,我提供了以下代码。 (第一行)
如果我使用 printf/echo/命令替换为终端的输出着色,我将无法进行着色。 (第二行代码)。我想这是因为我无法用\1 和\2 引用字符串。使用它时,它会显示一些其他字符而不是函数名称。
我使用的正则表达式是,函数名的第一个字符可以是字母或下划线,第二个字符可以是字母数字和下划线,第三个字符应该是左括号。我想通过使用\1\2 和\3 来引用正则表达式,并为除\3 之外的所有内容着色。这是我想出的主意。
我的问题是,是否有任何其他方法可以不为左括号着色或使用 printf 并为函数名称着色。
sed -E "s,([a-zA-Z_])([a-zA-Z0-9_]*)(\(),$(tput setaf 1)\1\2$( tput sgr0)\3,"Sample.c
sed -E "s,([a-zA-Z_])([a-zA-Z0-9_]*)(\(),$(printf "\033[0;36m\1\2\033[0m\3"),"Sample.c
示例.c:
#include <stdio.h>
int main()
{
int array[100], maximum, size, c, location = 1;
printf("Enter the number of elements in array\n");
scanf("%d", &size);
printf("Enter %d integers\n", size);
for (c = 0; c < size; c++)
scanf("%d", &array[c]);
return 0;
}
预期结果 -> main、printf、scanf 应该在 Sample.c 中着色。
最佳答案
tput 很聪明,但是回溯不会解析嵌入式 printf,因为它在子 shell 中,因此 printf 将无法工作。
在 var=$'ansi-ized content'
语法中有一个 bashism 可能对您有用。三个捕获组似乎并不重要。所以省略:
BEGC=$'\033[0;36m' ENDC=$'\033[0m'; \
sed -E "s,([a-zA-Z_][a-zA-Z0-9_]*)(\(),${BEGC}\1${ENDC}\2," Sample.c
但是,还有一个更根本的问题是嵌套函数不会被高亮显示。请注意,在此处更新的 Sample.c 中,虚构的“getSize()”函数不会突出显示:
#include <stdio.h>
int main()
{
int array[100], maximum, size, c, location = 1;
printf("Enter the number of elements in array\n");
scanf("%d", &size);
printf("Enter %d integers\n", getSize(size));
for (c = 0; c < size; c++)
scanf("%d", &array[c]);
return 0;
}
简单的正则表达式将无法工作,因为存在递归要求。可能 awk 可以做到这一点,因为它有一个 while 循环和函数(可能是 gensub()?)
关于regex - 如何在 te gnome-terminal 中使用 sed 命令实现语法高亮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57369336/
首先,我想补充一点,我认为这是一个错误。我正在尝试将占位符添加到 jqueryte像here 。 但它根本不使用 $().jqte({placeholder: "myplaceholder"}); 来
当我对输出进行类型转换时,我观察到一个有趣的结果: 这是代码片段: int bitSize = (int)log10(1.0*16)/log10(2.0); //bistsize = 3 it
我正在考虑选择一个 html 编辑器。我试过 jHtmlArea ( thinking 它是 JQueryTE。 无论如何,我也尝试了使用简单的 JQuery TE,只需调用 jqte()。 但是我似
.surveyform-class { background: yellow; margin: 0 25%; width: 50%; border-right: 40px so
我正在尝试一些关于字符串池的性能基准。然而,结果并非预期。 我做了3个静态方法 perform0() 方法...每次创建一个新对象 perform1() 方法 ... 字符串文字“Test” perf
这个问题在这里已经有了答案: adding touch listener for liner layout filled with buttons (2 个答案) 关闭 8 年前。 我有这样的布局。
我有一个客户端向服务器执行非常繁重的请求,服务器成功完成请求,但在成功之前浏览器收到 504 GATEWAY TIMEOUT...我怎样才能让浏览器等待服务器响应? 最佳答案 浏览器将等待多长时间,服
我想在 linux 终端上使用 sed 命令高亮显示 C 程序的函数名称。 我可以使用 tput 为函数名称着色。为此,我提供了以下代码。 (第一行) 如果我使用 printf/echo/命令替换为终
事实上,我正在使用一个对象来存储我的表单收集的所有数据。在这个对象中,我有一个数组,我发现更新它的唯一解决方案是创建一个函数,将每个输入添加到一个数组中,然后设置:this.setState({ 'i
我正在尝试使用 RSpec 和 Capybara 编写测试,但是,我总是收到以下错误: No route matches [GET] "/semead/assets/application-7a2cf
我正在使用 jQuery TE 进行文本格式化。我在文本编辑器中输入一些文本并执行一些操作,例如粗体、斜体、有序列表、文本标题和格式设置。一旦我完成文本格式设置。 我需要点击提交按钮。单击提交按钮后,
当此计数器被另一个计时器事件(stop_future)中断并完成时,我无法清除下面的 count_timer( sleep )。 import asyncio import datetime from
如果文件名由正斜杠组成,如“te/st.pdf” [data writeToFile:@"/Documents/te/st.pdf" atomically:YES encoding:NSUTF8Str
我在一家广播电台工作,所以我制作了该广播电台播放轨道的播放列表,您可以在这里找到它 -> http://www.facebook.com/QmusicNL?sk=app_258630990850514
我是一名优秀的程序员,十分优秀!