A C + C++ execution addon for Slidev's Monaco Runner, powered by Coliru's compilation API. Write, compile, and run C + C++ code directly in your presentations!
- 🖥️ In-slide C/C++ code execution
- ⚙️ Customizable compiler configurations
- 🔄 Real-time output display
- 📚 Support for multiple language standards
- 🎚️ Per-slide configuration overrides
- 🚦 Compiler output filtering
- 🛡️ Type-safe configuration options
npm install slidev-addon-cpp-runnerEnable the addon in your Slidev frontmatter:
---
addons:
- slidev-addon-cpp-runner
---# C
```c {monaco-run}
/** C2x CODE */# C++
```cpp {monaco-run}
/** C++20 CODE */---
addons:
- slidev-addon-cpp-runner
# C configuration using default settings
c:
# Compiler to use.
compiler: 'gcc'
# C standard.
standard: 'c2x'
# Optimization level.
optimization: 'O2'
# Compiler flags.
flags: '-Wall -Wextra -pedantic -pthread -pedantic-errors'
# Libraries to link.
libraries: '-lm -latomic'
# Additional shell commands to run after compilation.
extraCommands: ''
# Whether to always show the compiler output.
alwaysShowCompilerOutput: true
# C++ configuration using default settings
cpp:
# Compiler to use.
compiler: 'g++'
# C++ standard.
standard: 'c++20'
# Optimization level.
optimization: 'O2'
# Compiler flags.
flags: '-Wall -Wextra -pedantic -pthread -pedantic-errors'
# Libraries to link.
libraries: '-lm -latomic'
# Additional shell commands to run after compilation.
extraCommands: ''
# Whether to always show the compiler output.
alwaysShowCompilerOutput: false
---| Compiler | Standards |
|---|---|
| C++ | |
| g++ | 98,11,14,17,20,23 |
| clang++ | 98,11,14,17 |
| g++-4.9 | 98,11,14 |
| g++-5.2 | 98,11,14,1z |
| C | |
| gcc | 89,99,11,17,2x |
| clang | 89 |
| g++-4.9 | 89,99,11 |
| g++-5.2 | 89,99,11 |
| clang++ | 99,11 |
| Level | Description |
|---|---|
| O0 | No optimization |
| O1 | Basic optimization |
| O2 | Moderate optimization (default) |
| O3 | Aggressive optimization |
| Os | Optimize for size |
| Og | Debug-friendly optimization |
| Ofast | Maximum performance (unsafe) |
---
cpp:
standard: 'c++17'
optimization: 'O3'
---
# Custom Compilation Settings
```cpp {monaco-run}
/** C++17 CODE */- When
alwaysShowCompilerOutputistrue:- Compiler Output:
☘ [Compiler message] - Program Output:
☢ [Program output]
- Compiler Output:
- When
alwaysShowCompilerOutputisfalse:- Only program output is shown (unless there's a compiler error)
The addon includes comprehensive type safety features:
- Strict validation of compiler options, standards, and optimization levels.
- Runtime validation with fallback to defaults for invalid settings.
- Console warnings for invalid configuration options.
- TypeScript interfaces for configuration validation.
- 📩 Code sent to Coliru API.
- 🛠️ Compiled with specified options.
- 🏃 Executed in secure environment.
- 📤 Results returned to your slide.
- 🌐 Requires internet connection.
- 🛡️ Subject to Coliru's services and security restrictions.
Happy Coding in Your Slides! 🎉