Skip to content

Commit

Permalink
Merge pull request #126 from michaelb/dev
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
michaelb authored Dec 13, 2021
2 parents ba6c05c + ee18e15 commit 68ebb6c
Show file tree
Hide file tree
Showing 21 changed files with 269 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v1.1.0
- TerminalWithCode display option (courtesy of @control13)
- Fix default interpreter issue
- Python3\_fifo venv support + doc + fix indented bloc failure

## v1.0.6
- fix output with escape sequences

Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sniprun"
version = "1.0.6"
version = "1.1.0"
authors = ["michaelb <[email protected]>"]
edition = "2018"

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ require'sniprun'.setup({
-- "TempFloatingWindow", --# display results in a floating window
-- "LongTempFloatingWindow", --# same as above, but only long results. To use with VirtualText__
-- "Terminal", --# display results in a vertical split
-- "TerminalWithCode", --# display results and code history in a vertical split
-- "NvimNotify", --# display with the nvim-notify plugin
-- "Api" --# return output to a programming interface
},
Expand Down
16 changes: 16 additions & 0 deletions doc/Prolog_gnu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This interpreter is currently a work in progress and is probably not usable

The Prolog interpreter supports setting a different compiler/interpreter for prolog such as swi ('swipl')

you can set it with the following key:


```
require'sniprun'.setup({
interpreter_options = {
Prolog_gnu = { interpreter = "swipl" }
}
}
})
```

17 changes: 17 additions & 0 deletions doc/Python3_fifo.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,20 @@ require'sniprun'.setup({
```

if a snippet produce an error important enough to crash the interpreter, you may be required to re-launch the kernel (with a `SnipRun`)


setting a custom python interpreter and venv is also supported


```
require'sniprun'.setup({
interpreter_options = {
Python3_fifo = {
intepreter = "python3.9",
venv = {"venv_project1", "venv_project2", "../venv_project2"},
}
}
}
})
```

1 change: 1 addition & 0 deletions doc/sniprun.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ require'sniprun'.setup({
-- "TempFloatingWindow", -- "display results in a floating window
-- "LongTempFloatingWindow", -- "same as above, but only long results. To use with VirtualText__
-- "Terminal" -- "display results in a vertical split
-- "TerminalWithCode", --# display results and code history in a vertical split
-- "NvimNotify", --# display with the nvim-notify plugin
-- "Api" --# return output to a programming interface
},
Expand Down
1 change: 1 addition & 0 deletions lua/sniprun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ M.config_values = {
-- "LongTempFloatingWindow",
-- "TempFloatingWindow",
-- "Terminal",
-- "TerminalWithCode",
-- "Api",
-- "NvimNotify"
},
Expand Down
6 changes: 6 additions & 0 deletions ressources/display_terminal.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ EOF
![](visual_assets/terminal.png)


If you also want to print the code being executed to the 'terminal', then use `"TerminalWithCode"` instead in the 'display' key.



![](visual_assets/terminalWithCode.png)

1 change: 1 addition & 0 deletions ressources/install_all_compilers_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ sudo apt install scala
pip3 install jupyter
sudo apt install lua5.3
sudo apt install sagemath
sudo apt install gprolog
./ressources/go_install.sh
export PATH=$PATH:$HOME/golang/go/bin/
Binary file added ressources/visual_assets/terminalWithCode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 52 additions & 2 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use neovim_lib::{Neovim, NeovimApi};
use std::fmt;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use unindent::Unindent;

#[derive(Clone, Debug, Ord, PartialOrd, PartialEq, Eq)]
pub enum DisplayType {
Expand All @@ -13,6 +14,7 @@ pub enum DisplayType {
VirtualTextOk,
VirtualTextErr,
Terminal,
TerminalWithCode,
LongTempFloatingWindow,
TempFloatingWindow,
Api,
Expand All @@ -27,6 +29,7 @@ impl FromStr for DisplayType {
"VirtualTextOk" => Ok(VirtualTextOk),
"VirtualTextErr" => Ok(VirtualTextErr),
"Terminal" => Ok(Terminal),
"TerminalWithCode" => Ok(TerminalWithCode),
"LongTempFloatingWindow" => Ok(LongTempFloatingWindow),
"TempFloatingWindow" => Ok(TempFloatingWindow),
"Api" => Ok(Api),
Expand All @@ -45,6 +48,7 @@ impl fmt::Display for DisplayType {
DisplayType::VirtualTextOk => "VirtualTextOk",
DisplayType::VirtualTextErr => "VirtualTextErr",
DisplayType::Terminal => "Terminal",
DisplayType::TerminalWithCode => "TerminalWithCode",
DisplayType::LongTempFloatingWindow => "LongTempFloatingWindow",
DisplayType::TempFloatingWindow => "TempFloatingWindow",
DisplayType::Api => "Api",
Expand All @@ -59,13 +63,19 @@ pub fn display(result: Result<String, SniprunError>, nvim: Arc<Mutex<Neovim>>, d
display_type.sort();
display_type.dedup(); //now only uniques display types

// remove transparently incompatible/redundant displays
if display_type.contains(&TerminalWithCode) {
display_type.retain(|dt| dt != &Terminal);
}

info!("Display type chosen: {:?}", display_type);
for dt in display_type.iter() {
match dt {
Classic => return_message_classic(&result, &nvim, &data.return_message_type, data),
VirtualTextOk => display_virtual_text(&result, &nvim, data, true),
VirtualTextErr => display_virtual_text(&result, &nvim, data, false),
Terminal => display_terminal(&result, &nvim, data),
TerminalWithCode => display_terminal_with_code(&result, &nvim, data),
LongTempFloatingWindow => display_floating_window(&result, &nvim, data, true),
TempFloatingWindow => display_floating_window(&result, &nvim, data, false),
Api => send_api(&result, &nvim, data),
Expand Down Expand Up @@ -198,14 +208,54 @@ pub fn display_terminal(
nvim: &Arc<Mutex<Neovim>>,
data: &DataHolder,
) {
info!("data_bloc = {}", data.current_bloc);
let a = data.current_bloc.lines();
info!("length = {}", a.count());
let res = match message {
Ok(result) => nvim.lock().unwrap().command(&format!(
"lua require\"sniprun.display\".write_to_term(\"{}\", true)",
no_output_wrap(result, data, &DisplayType::Terminal),
no_output_wrap(result, data, &DisplayType::Terminal).replace("\n", "\\\n"),
)),
Err(result) => nvim.lock().unwrap().command(&format!(
"lua require\"sniprun.display\".write_to_term(\"{}\", false)",
no_output_wrap(&result.to_string(), data, &DisplayType::Terminal),
no_output_wrap(&result.to_string(), data, &DisplayType::Terminal).replace("\n", "\\\n"),
)),
};
info!("display terminal res = {:?}", res);
}

pub fn display_terminal_with_code(
message: &Result<String, SniprunError>,
nvim: &Arc<Mutex<Neovim>>,
data: &DataHolder,
) {
let res = match message {
Ok(result) => nvim.lock().unwrap().command(&format!(
"lua require\"sniprun.display\".write_to_term(\"{}\\n{}\", true)",
cleanup_and_escape(
&format!("\n{}", &data.current_bloc)
.unindent()
.lines()
.fold("".to_string(), |cur_bloc, line_in_bloc| {
cur_bloc + "> " + line_in_bloc + "\n"
})
)
.replace("\n", "\\\n"),
no_output_wrap(result, data, &DisplayType::TerminalWithCode).replace("\n", "\\\n"),
)),
Err(result) => nvim.lock().unwrap().command(&format!(
"lua require\"sniprun.display\".write_to_term(\"{}\\n{}\", false)",
cleanup_and_escape(
&format!("\n{}", &data.current_bloc)
.unindent()
.lines()
.fold("".to_string(), |cur_bloc, line_in_bloc| {
cur_bloc + "> " + line_in_bloc + "\n"
})
)
.replace("\n", "\\\n"),
no_output_wrap(&result.to_string(), data, &DisplayType::TerminalWithCode)
.replace("\n", "\\\n"),
)),
};
info!("display terminal res = {:?}", res);
Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/C_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ impl C_original {

fn fetch_config(&mut self) {
let default_compiler = String::from("gcc");
self.compiler = default_compiler;
if let Some(used_compiler) = C_original::get_interpreter_option(&self.get_data(), "compiler") {
if let Some(compiler_string) = used_compiler.as_str() {
info!("Using custom compiler: {}", compiler_string);
self.compiler = compiler_string.to_string();
}
}
self.compiler = default_compiler;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/Cpp_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ impl Cpp_original {

fn fetch_config(&mut self) {
let default_compiler = String::from("g++");
self.compiler = default_compiler;
if let Some(used_compiler) = Cpp_original::get_interpreter_option(&self.get_data(), "compiler") {
if let Some(compiler_string) = used_compiler.as_str() {
info!("Using custom compiler: {}", compiler_string);
self.compiler = compiler_string.to_string();
}
}
self.compiler = default_compiler;
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/Go_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ pub struct Go_original {
impl Go_original {
fn fetch_config(&mut self) {
let default_compiler = String::from("go");
self.compiler = default_compiler;
if let Some(used_compiler) = Go_original::get_interpreter_option(&self.get_data(),"compiler") {
if let Some(compiler_string) = used_compiler.as_str() {
info!("Using custom compiler: {}", compiler_string);
self.compiler = compiler_string.to_string();
}
}
self.compiler = default_compiler;
}
}

Expand Down
Loading

0 comments on commit 68ebb6c

Please sign in to comment.