总算想出了一个可以在 sublime 编绎选项里打开终端接受键盘输入的方法

2017-04-13 16:47:05 +08:00
 shino996

写点简单的 C++ 什么的不想打开 Xcode 这么大的 IDE ,而 sublime 的 build system 里接受的命令输出都被重定向到了 sublime 自身, cin 之类的没法接受输入。

网上有一种解决方法是 Clang++ 编绎好执行文件后,用 open 命令打开终端运行,不过如果想加上些运行参数就不行了。

我的解决方案是在编绎后目录临时写一个脚本,里面是要执行的命令,再用 open 命令运行这个脚本:

{
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.cpp",

    "shell_cmd": "clang++ -std=c++1y -stdlib=libc++ -o \"${file_path}/${file_base_name}\" \"${file}\"",

    "variants": 
    [
        {
            "name": "Run",
            "shell_cmd": "clang++ -std=c++1y -stdlib=libc++ -o \"${file_path}/${file_base_name}\" \"${file}\" && open -a Terminal.app \"${file_path}/${file_base_name}\""
        },
        {
            "name": "Debug",
            "shell_cmd": "clang++ -std=c++1y -stdlib=libc++ \"${file}\" -g -o \"${file_path}/${file_base_name}\" && echo \"lldb ${file_path}/${file_base_name}\" > debug_shell.sh && chmod +x ${file_path}/debug_shell.sh && open ${file_path}/debug_shell.sh -a Terminal.app"
        }
    ]
}

还有一个问题是终端里用 lldb 调试程序时总会出现 NameError: name 'run_one_line' is not defined 错误,网上没找到合理的解释,不知道有没有人遇到过。

4195 次点击
所在节点    Sublime Text
2 条回复
yangg
2017-04-13 22:10:31 +08:00
Vscode 的 runner 设置 run in terminal
mb4555
2017-04-14 02:34:34 +08:00
atom 加插件

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/354646

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX