V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
shino996
V2EX  ›  Sublime Text

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

  •  
  •   shino996 · 2017-04-13 16:47:05 +08:00 · 4160 次点击
    这是一个创建于 2541 天前的主题,其中的信息可能已经有所发展或是发生改变。

    写点简单的 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 错误,网上没找到合理的解释,不知道有没有人遇到过。

    2 条回复    2017-04-14 02:34:34 +08:00
    yangg
        1
    yangg  
       2017-04-13 22:10:31 +08:00 via iPhone
    Vscode 的 runner 设置 run in terminal
    mb4555
        2
    mb4555  
       2017-04-14 02:34:34 +08:00 via Android
    atom 加插件
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3326 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 13:44 · PVG 21:44 · LAX 06:44 · JFK 09:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.