Sublime Forum

Input in Build System

#1

I’ve been using Sublime Text for a month now. I want to do everything on Sublime now :smile:.
I have Builds for all the languages I use. The only problem I’m facing is taking input from the user. Is it possible to take input from the console itself?

If not is there any other work around?

If its not within the scope of Sublime Text 2, what parameter should I supply in Sublime Build file, so that it opens the output in cmd.

0 Likes

Running Python on sublime console
#2

You can implement your build system as a Sublime Text window command and hook it up though the target option.
In the command implementation, any part of the Sublime API can used, including sublime.Window.show_input_panel().

0 Likes

#3

This is very easy to do with a combination of the Command Prompt and Sublime.

Step 1. Ensure GCC or some C/C++ Compiler is installed

Step 2. Create a new build system file (Tools > Build System > New Build System) and remove everything that pre-exists in the file.

Step 3. Paste the code below into the file and save (Preferably naming it something like C++ Build)

{
“cmd”: [“g++”, “-Wall”, “-ansi”, “-pedantic-errors”, “$file_name”, “-o”, “${file_base_name}.exe”, “&&”, “start”, “cmd”, “/k” , “$file_base_name”],
“selector”: “source.cpp”,
“working_dir”: “${file_path}”,
“shell”: true
}

Step 4. When you run C++ code in the editor now, you will get a Command Prompt dialogue that executes the code and properly takes Input/Output from the user.

Step 5. Profit???

1 Like

#4

Hey this code I copied and is showing “No build system”. I tried a C code.

0 Likes

#5

The reason for that is that the build system code above is not a proper code block, so the forum has replaced all of the “straight” quotes with typographic double quotes, which is not valid JSON.

A properly cleaned up version would be:

{
"cmd": ["g++", "-Wall", "-ansi", "-pedantic-errors", "$file_name", "-o", "${file_base_name}.exe", "&&", "start", "cmd", "/k" , "$file_base_name"],
"selector": "source.cpp",
"working_dir": "${file_path}",
"shell": true
}

That said, if you want a build system that’s interactive but also still within Sublime, you can do that with the Terminus package. The following video demonstrates how:

0 Likes