Skip to content

Commit 590934c

Browse files
committed
Code runner like vscode
0 parents  commit 590934c

9 files changed

+401
-0
lines changed

.gitignore

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/python,lua
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=python,lua
4+
5+
### Lua ###
6+
# Compiled Lua sources
7+
luac.out
8+
9+
# luarocks build files
10+
*.src.rock
11+
*.zip
12+
*.tar.gz
13+
14+
# Object files
15+
*.o
16+
*.os
17+
*.ko
18+
*.obj
19+
*.elf
20+
21+
# Precompiled Headers
22+
*.gch
23+
*.pch
24+
25+
# Libraries
26+
*.lib
27+
*.a
28+
*.la
29+
*.lo
30+
*.def
31+
*.exp
32+
33+
# Shared objects (inc. Windows DLLs)
34+
*.dll
35+
*.so
36+
*.so.*
37+
*.dylib
38+
39+
# Executables
40+
*.exe
41+
*.out
42+
*.app
43+
*.i*86
44+
*.x86_64
45+
*.hex
46+
47+
48+
### Python ###
49+
# Byte-compiled / optimized / DLL files
50+
__pycache__/
51+
*.py[cod]
52+
*$py.class
53+
54+
# C extensions
55+
56+
# Distribution / packaging
57+
.Python
58+
build/
59+
develop-eggs/
60+
dist/
61+
downloads/
62+
eggs/
63+
.eggs/
64+
parts/
65+
sdist/
66+
var/
67+
wheels/
68+
pip-wheel-metadata/
69+
share/python-wheels/
70+
*.egg-info/
71+
.installed.cfg
72+
*.egg
73+
MANIFEST
74+
75+
# PyInstaller
76+
# Usually these files are written by a python script from a template
77+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
78+
*.manifest
79+
*.spec
80+
81+
# Installer logs
82+
pip-log.txt
83+
pip-delete-this-directory.txt
84+
85+
# Unit test / coverage reports
86+
htmlcov/
87+
.tox/
88+
.nox/
89+
.coverage
90+
.coverage.*
91+
.cache
92+
nosetests.xml
93+
coverage.xml
94+
*.cover
95+
*.py,cover
96+
.hypothesis/
97+
.pytest_cache/
98+
pytestdebug.log
99+
100+
# Translations
101+
*.mo
102+
*.pot
103+
104+
# Django stuff:
105+
*.log
106+
local_settings.py
107+
db.sqlite3
108+
db.sqlite3-journal
109+
110+
# Flask stuff:
111+
instance/
112+
.webassets-cache
113+
114+
# Scrapy stuff:
115+
.scrapy
116+
117+
# Sphinx documentation
118+
docs/_build/
119+
doc/_build/
120+
121+
# PyBuilder
122+
target/
123+
124+
# Jupyter Notebook
125+
.ipynb_checkpoints
126+
127+
# IPython
128+
profile_default/
129+
ipython_config.py
130+
131+
# pyenv
132+
.python-version
133+
134+
# pipenv
135+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
136+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
137+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
138+
# install all needed dependencies.
139+
#Pipfile.lock
140+
141+
# poetry
142+
#poetry.lock
143+
144+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
145+
__pypackages__/
146+
147+
# Celery stuff
148+
celerybeat-schedule
149+
celerybeat.pid
150+
151+
# SageMath parsed files
152+
*.sage.py
153+
154+
# Environments
155+
# .env
156+
.env/
157+
.venv/
158+
env/
159+
venv/
160+
ENV/
161+
env.bak/
162+
venv.bak/
163+
pythonenv*
164+
165+
# Spyder project settings
166+
.spyderproject
167+
.spyproject
168+
169+
# Rope project settings
170+
.ropeproject
171+
172+
# mkdocs documentation
173+
/site
174+
175+
# mypy
176+
.mypy_cache/
177+
.dmypy.json
178+
dmypy.json
179+
180+
# Pyre type checker
181+
.pyre/
182+
183+
# pytype static type analyzer
184+
.pytype/
185+
186+
# operating system-related files
187+
# file properties cache/storage on macOS
188+
*.DS_Store
189+
# thumbnail cache on Windows
190+
Thumbs.db
191+
192+
# profiling data
193+
.prof
194+
195+
196+
# End of https://www.toptal.com/developers/gitignore/api/python,lua

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 CRAG666
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<h1 align='center'>Code_Runner</h1>
2+
3+
<h4 align='center'>🔥 Code Runner like vscode written in lua and python 🔥</h4>
4+
5+
![Code_Runner](https://i.ibb.co/XX43DDs/2021-04-26-00-34.png "Code Runner with python")
6+
7+
### Requirements
8+
9+
- Neovim Nightly (0.5)
10+
11+
### Install
12+
13+
- With [packer.nvim](https://github.com/wbthomason/packer.nvim)
14+
15+
16+
#### Use FTerm
17+
```lua
18+
use {
19+
"CRAG666/code_runner.nvim",
20+
requires = {"numtostr/FTerm.nvim"}
21+
}
22+
```
23+
24+
#### Use native Terminal
25+
```lua
26+
use 'CRAG666/code_runner.nvim'
27+
```
28+
29+
- With [vim-plug](https://github.com/junegunn/vim-plug)
30+
31+
#### Use FTerm
32+
```vim
33+
Plug 'numtostr/FTerm.nvim'
34+
Plug 'CRAG666/code_runner.nvim'
35+
```
36+
37+
#### Use native Terminal
38+
```vim
39+
Plug 'CRAG666/code_runner.nvim'
40+
```
41+
42+
### Functions
43+
44+
- `:RunCode` - Run current file in native terminal.
45+
- `:FRunCode` - Run current file in FTerm.
46+
47+
### Configuration

lua/code_runner.lua

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
local o = require("code_runner.options")
2+
local M = {}
3+
4+
M.setup = function(user_options)
5+
o.set(user_options)
6+
vim.api.nvim_exec([[
7+
command! FRunCode lua require('code_runner').frun_code()
8+
command! RunCode lua require('code_runner').run_code()
9+
]], false)
10+
end
11+
12+
M.frun_code = function()
13+
run = require("code_runner.fterm_commands")
14+
run()
15+
end
16+
17+
M.run_code = function()
18+
run = require("code_runner.term_commands")
19+
run()
20+
end
21+
22+
return M

lua/code_runner/fterm_commands.lua

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
local o = require("code_runner.options")
2+
3+
local function get_command()
4+
filepath = vim.fn.expand("%")
5+
command ="python ~/.local/share/nvim/site/pack/packer/start/code_runner.nvim/python/code_runner.py "
6+
return command .. filepath .. " && read -n 1"
7+
end
8+
9+
10+
local function create_code_runner(term)
11+
run_code_command = term:new():setup({
12+
cmd = get_command(),
13+
dimensions = {
14+
height = o.get().fterm.height,
15+
width = o.get().fterm.width
16+
}
17+
})
18+
return run_code_command
19+
end
20+
21+
22+
local frun_code = function()
23+
hasfterm, fterm = pcall(require,"FTerm.terminal")
24+
if hasfterm then
25+
run_code = create_code_runner(fterm)
26+
run_code:toggle()
27+
else
28+
print(vim.inspect("add FTerm for use"))
29+
end
30+
end
31+
32+
return frun_code

lua/code_runner/options.lua

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
local options = {
2+
term = {
3+
position = "belowright",
4+
size = 8
5+
},
6+
fterm = {
7+
height = 0.7,
8+
width = 0.7
9+
}
10+
}
11+
12+
local M = {}
13+
M.set = function(user_options)
14+
options = vim.tbl_extend("force", options, user_options)
15+
end
16+
17+
M.get = function() return options end
18+
19+
return M
20+

lua/code_runner/term_commands.lua

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
local o = require("code_runner.options")
2+
3+
local trun_code = function()
4+
pos = o.get().term.position
5+
size = o.get().term.size
6+
term = string.format("%s %dsplit term://", pos, size)
7+
command = "python ~/.local/share/nvim/site/pack/packer/start/code_runner.nvim/python/code_runner.py "
8+
filepath = vim.fn.expand("%")
9+
vim_command = term .. command .. filepath
10+
vim.api.nvim_command(vim_command)
11+
end
12+
13+
return trun_code

python/code_runner.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"java": "cd {dir} && javac {fileName} && java {fileNameWithoutExt}",
3+
"kt": "cd {dir} && kotlinc-native {fileName} -o {fileNameWithoutExt} && ./{fileNameWithoutExt}.kexe",
4+
"c": "cd {dir} && gcc {fileName} -o {fileNameWithoutExt} && {dir}{fileNameWithoutExt}",
5+
"cpp": "cd {dir} && g++ {fileName} -o {fileNameWithoutExt} && {dir}{fileNameWithoutExt}",
6+
"py": "python -u {file}",
7+
"cs": "alacritty -e sh -c 'cd {dir} && mcs {fileName} && mono *.exe'",
8+
"ts": "deno run {file}",
9+
"rs": "cd {dir} && rustc {fileName} && {dir}{fileNameWithoutExt}"
10+
}

0 commit comments

Comments
 (0)