From ac862b4cd466c96980cde7c5b31702ddfda9cb3d Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 15 Dec 2021 09:00:37 +0100 Subject: [PATCH 1/6] Prolog_gnu -> Prolog_original --- doc/{Prolog_gnu.md => Prolog_original.md} | 2 +- .../{Prolog_gnu.rs => Prolog_original.rs} | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) rename doc/{Prolog_gnu.md => Prolog_original.md} (85%) rename src/interpreters/{Prolog_gnu.rs => Prolog_original.rs} (87%) diff --git a/doc/Prolog_gnu.md b/doc/Prolog_original.md similarity index 85% rename from doc/Prolog_gnu.md rename to doc/Prolog_original.md index 66a1ef4f..0d6aaf39 100644 --- a/doc/Prolog_gnu.md +++ b/doc/Prolog_original.md @@ -8,7 +8,7 @@ you can set it with the following key: ``` require'sniprun'.setup({ interpreter_options = { - Prolog_gnu = { interpreter = "swipl" } + Prolog_original = { interpreter = "swipl" } } } }) diff --git a/src/interpreters/Prolog_gnu.rs b/src/interpreters/Prolog_original.rs similarity index 87% rename from src/interpreters/Prolog_gnu.rs rename to src/interpreters/Prolog_original.rs index e30fdc44..a3fe1ac8 100644 --- a/src/interpreters/Prolog_gnu.rs +++ b/src/interpreters/Prolog_original.rs @@ -1,6 +1,6 @@ #[derive(Clone)] #[allow(non_camel_case_types)] -pub struct Prolog_gnu { +pub struct Prolog_original { support_level: SupportLevel, data: DataHolder, code: String, @@ -8,17 +8,17 @@ pub struct Prolog_gnu { main_file_path: String, interpreter: String, } -impl ReplLikeInterpreter for Prolog_gnu {} -impl Interpreter for Prolog_gnu { - fn new_with_level(data: DataHolder, level: SupportLevel) -> Box { - let bwd = data.work_dir.clone() + "/prolog-gnu"; +impl ReplLikeInterpreter for Prolog_original {} +impl Interpreter for Prolog_original { + fn new_with_level(data: DataHolder, level: SupportLevel) -> Box { + let bwd = data.work_dir.clone() + "/prolog-original"; let mut builder = DirBuilder::new(); builder.recursive(true); builder .create(&bwd) - .expect("Could not create directory for prolog-gnu"); + .expect("Could not create directory for prolog-original"); let mfp = bwd.clone() + "/main.pl"; - Box::new(Prolog_gnu { + Box::new(Prolog_original { data, support_level: level, code: String::from(""), @@ -28,7 +28,7 @@ impl Interpreter for Prolog_gnu { }) } fn get_name() -> String { - String::from("Prolog_gnu") + String::from("Prolog_original") } fn get_supported_languages() -> Vec { vec![String::from("Prolog"), String::from("prolog")] @@ -86,9 +86,9 @@ impl Interpreter for Prolog_gnu { } fn build(&mut self) -> Result<(), SniprunError> { let mut _file = - File::create(&self.main_file_path).expect("Failed to create file for prolog-gnu"); + File::create(&self.main_file_path).expect("Failed to create file for prolog-original"); - write(&self.main_file_path, &self.code).expect("Unable to write to file for prolog-gnu"); + write(&self.main_file_path, &self.code).expect("Unable to write to file for prolog-original"); Ok(()) } fn execute(&mut self) -> Result { @@ -108,7 +108,7 @@ impl Interpreter for Prolog_gnu { .output() .expect("Unable to start process"); } - info!("yay from gnu Prolog interpreter"); + info!("yay from Prolog interpreter"); if output.status.success() { Ok(String::from_utf8(output.stdout).unwrap()) } else { @@ -119,14 +119,14 @@ impl Interpreter for Prolog_gnu { } } #[cfg(test)] -mod test_prolog_gnu { +mod test_prolog_original { use super::*; // #[test] fn simple_print() { let mut data = DataHolder::new(); data.current_bloc = String::from(":- write(ok), halt."); - let mut interpreter = Prolog_gnu::new(data); + let mut interpreter = Prolog_original::new(data); let res = interpreter.run(); // should panic if not an Ok() From 814ca740657416df7ec7f3affdc0985fdb3e2d98 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Wed, 15 Dec 2021 09:07:58 +0100 Subject: [PATCH 2/6] contributing repl tweaks --- ressources/CONTRIBUTING_REPL.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ressources/CONTRIBUTING_REPL.md b/ressources/CONTRIBUTING_REPL.md index a4df68cf..17e6f7bf 100644 --- a/ressources/CONTRIBUTING_REPL.md +++ b/ressources/CONTRIBUTING_REPL.md @@ -15,10 +15,10 @@ To avoid confusion, we'll call the language interpreter 'interpreter', and snipr - you make use of a named pipe (fifo) and pipe what sniprun says into it. the pipe is connected to a live, running, interpreter for your language. Its output is written to a file and sniprun waits for landmarks (start, end) to be printed. - I strongly advise the latter methodology, which has several advantages that I won't discuss here, but can be harder to implement if your language's interpreter has weird stdin/stdou/stderr behavior. Like non-disablable prompts printed to stdout. + I strongly advise the latter methodology, which has several advantages that I won't discuss here, but can be harder to implement if your language's interpreter has weird stdin/stdout/stderr behavior. Like non-disablable prompts printed to stdout. - ## How to implement a pipe-based repl-capable runner +## How to implement a pipe-based repl-capable runner The best example I'm going to discuss is Python3\_fifo, even if it's a bit bloated from python-specific things. @@ -119,4 +119,5 @@ fn new_with_level(...) .... ``` -- disable prompts for your interpreter. They'll pollute stdout +- disable prompts for your interpreter. They'll pollute stdout. For example, in python, you'll have to set `sys.ps1` and `sys.ps2` to `""`. + From cf7947fe7ea1c5f0d119949bc3866c9a57affb4c Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Thu, 16 Dec 2021 16:00:53 +0100 Subject: [PATCH 3/6] fix imports & indents for python's --- src/interpreters/Python3_fifo.rs | 14 +++++++++----- src/interpreters/Python3_jupyter.rs | 3 ++- src/interpreters/Python3_original.rs | 4 +++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 5180ba45..04ba4251 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -135,8 +135,9 @@ impl Python3_fifo { let already_imported: String = self.read_previous_code(); if !already_imported.contains(line) { - self.imports = self.imports.clone() + "\n" + line; - self.save_code(already_imported + "\n" + line); + let line = unindent(&line); + self.imports = self.imports.clone() + "\n" + &line; + self.save_code(already_imported + "\n" + &line); } } } @@ -313,7 +314,9 @@ impl Interpreter for Python3_fifo { self.code = source_venv + &self.imports.clone() - + &unindent(&format!("{}{}", "\n", self.code.as_str())); + + "\n## Imports above, code below, a #\\n# marker is very important to separate the try/catch bloc from the code ##Here it is: #\n#" + + &unindent(&format!("{}{}", "\n\n", self.code.as_str())); + info!("source code::::: {}", self.code); Ok(()) } fn build(&mut self) -> Result<(), SniprunError> { @@ -414,9 +417,10 @@ impl ReplLikeInterpreter for Python3_fifo { .lines() .filter(|l| !l.trim().is_empty()) .collect::>() - .join("\n"); + .join("\n") + .replace("#\n#","\n"); - let all_code = self.imports.clone() + "\n" + &self.code + "\n\n"; + let all_code = String::from("\n") + &self.code + "\n\n"; self.code = String::from("\nimport sys\n\n") + &start_mark + &start_mark_err diff --git a/src/interpreters/Python3_jupyter.rs b/src/interpreters/Python3_jupyter.rs index 3c73df95..5d7c53c5 100644 --- a/src/interpreters/Python3_jupyter.rs +++ b/src/interpreters/Python3_jupyter.rs @@ -53,7 +53,8 @@ impl Python3_jupyter { && self.module_used(line, &self.code) { // embed in try catch blocs in case uneeded module is unavailable - self.imports = self.imports.clone() + "\n" + line; + let line = unindent(&line); + self.imports = self.imports.clone() + "\n" + &line; } } info!("import founds : {:?}", self.imports); diff --git a/src/interpreters/Python3_original.rs b/src/interpreters/Python3_original.rs index fb7a1bb9..87cd2480 100644 --- a/src/interpreters/Python3_original.rs +++ b/src/interpreters/Python3_original.rs @@ -52,7 +52,8 @@ impl Python3_original { && self.module_used(line, &self.code) { // embed in try catch blocs in case uneeded module is unavailable - self.imports = self.imports.clone() + "\n" + line; + let line = unindent(&line); + self.imports = self.imports.clone() + "\n" + &line; } } info!("import founds : {:?}", self.imports); @@ -227,6 +228,7 @@ impl Interpreter for Python3_original { self.code = source_venv + &self.imports.clone() + + "\n" + &unindent(&format!("{}{}", "\n", self.code.as_str())); Ok(()) } From ba2499ec6c611c418ce4e2f68394b013d142de3c Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Sun, 19 Dec 2021 10:39:15 +0100 Subject: [PATCH 4/6] terminal config options --- CHANGELOG.md | 4 ++++ Cargo.lock | 22 +++++++++++----------- Cargo.toml | 2 +- README.md | 5 +++++ lua/sniprun.lua | 9 +++++++-- lua/sniprun/display.lua | 6 ++++-- ressources/display_notify.md | 8 ++++++++ ressources/display_terminal.md | 7 ++++++- 8 files changed, 46 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c358f80..1d45e0e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v1.1.1 +- Fix terminal display issues +- Configurable display options + ## v1.1.0 - TerminalWithCode display option (courtesy of @control13) - Fix default interpreter issue diff --git a/Cargo.lock b/Cargo.lock index fcf49a09..4edf1147 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -89,9 +89,9 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.8" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" +checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" [[package]] name = "lazy_static" @@ -101,9 +101,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.111" +version = "0.2.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e167738f1866a7ec625567bae89ca0d44477232a4f7c52b1c7f2adc2c98804f" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" [[package]] name = "lock_api" @@ -177,9 +177,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.33" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb37d2df5df740e582f28f8560cf425f52bb267d872fe58358eadb554909f07a" +checksum = "2f84e92c0f7c9d58328b85a78557813e4bd845130db68d7184635344399423b1" dependencies = [ "unicode-xid", ] @@ -271,9 +271,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.131" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ad69dfbd3e45369132cc64e6748c2d65cdfb001a2b1c232d128b4ad60561c1" +checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008" [[package]] name = "serde_bytes" @@ -286,9 +286,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ffa0837f2dfa6fb90868c2b5468cad482e175f7dad97e7421951e663f2b527" +checksum = "bcbd0344bc6533bc7ec56df11d42fb70f1b912351c0825ccb7211b59d8af7cf5" dependencies = [ "itoa", "ryu", @@ -336,7 +336,7 @@ checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" [[package]] name = "sniprun" -version = "1.1.0" +version = "1.1.1" dependencies = [ "dirs", "libc", diff --git a/Cargo.toml b/Cargo.toml index 24845c13..0e993378 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sniprun" -version = "1.1.0" +version = "1.1.1" authors = ["michaelb "] edition = "2018" diff --git a/README.md b/README.md index 754afc55..a898a69f 100755 --- a/README.md +++ b/README.md @@ -295,6 +295,11 @@ require'sniprun'.setup({ -- "Api" --# return output to a programming interface }, + display_options = { + terminal_width = 45, --# change the terminal display option width + notification_timeout = 5 --# timeout for nvim_notify output + }, + --# You can use the same keys to customize whether a sniprun producing --# no output should display nothing or '(no output)' show_no_output = { diff --git a/lua/sniprun.lua b/lua/sniprun.lua index db294e38..b663ce41 100644 --- a/lua/sniprun.lua +++ b/lua/sniprun.lua @@ -32,9 +32,14 @@ M.config_values = { -- "NvimNotify" }, + display_options = { + terminal_width = 45, -- change the terminal display option width + notification_timeout = 5 -- timeout for nvim_notify output + }, + show_no_output = { "Classic", - "TempFloatingWindow", -- implies LongTempFloatingWindow, which is not a correct key here + "TempFloatingWindow", -- implies LongTempFloatingWindow, which is not a correct key here }, inline_messages = 0, @@ -109,7 +114,7 @@ end function M.setup_highlights() local colors_table = M.config_values["snipruncolors"] - if M.custom_highlight then + if M.custom_highlight then vim.cmd('augroup snip_highlights') vim.cmd('autocmd!') for group, styles in pairs(colors_table) do diff --git a/lua/sniprun/display.lua b/lua/sniprun/display.lua index 8fbcb279..215f9290 100644 --- a/lua/sniprun/display.lua +++ b/lua/sniprun/display.lua @@ -35,12 +35,14 @@ end function M.term_open() if M.term.opened ~= 0 then return end - vim.cmd(':rightb45vsplit') + local open_term_cmd = ':rightb'.. M.display_options.terminal_width .. 'vsplit' + vim.cmd(open_term_cmd) local buf = vim.api.nvim_create_buf(false,true) local win = vim.api.nvim_get_current_win() vim.api.nvim_win_set_buf(win,buf) local chan = vim.api.nvim_open_term(buf, {}) vim.cmd("set scrollback=1") + vim.cmd('setlocal nonu') vim.cmd("wincmd p") M.term.opened = 1 @@ -122,7 +124,7 @@ function M.display_nvim_notify(message, ok) local title = ok and "Sniprun: Ok" or "Sniprun: Error" local notif_style = ok and "info" or "error" - require("notify")(message, notif_style, {title=title}) + require("notify")(message, notif_style, {title=title, timeout=M.display_options.notification_timeout}) end function M.display_extmark(ns,line, message, highlight) diff --git a/ressources/display_notify.md b/ressources/display_notify.md index 51c4ed31..12bc8b18 100644 --- a/ressources/display_notify.md +++ b/ressources/display_notify.md @@ -14,3 +14,11 @@ require'sniprun'.setup({ }) EOF ``` + +The notification timeout can be changed with this configuration option: + +``` + display_options = { + notification_timeout = 5 -- timeout for nvim_notify output + }, +``` diff --git a/ressources/display_terminal.md b/ressources/display_terminal.md index 479c6c81..277122ac 100644 --- a/ressources/display_terminal.md +++ b/ressources/display_terminal.md @@ -23,7 +23,12 @@ require'sniprun'.setup({ }) EOF ``` - +You can change the width of the terminal by using the display option in the configuration: +``` + display_options = { + terminal_width = 45, -- change the terminal display option width + }, +``` ![](visual_assets/terminal.png) From 9c1f0512ecdd4b0820f3515fb5cca8560be628a8 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Sun, 19 Dec 2021 10:45:11 +0100 Subject: [PATCH 5/6] fix display options --- lua/sniprun/display.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/sniprun/display.lua b/lua/sniprun/display.lua index 215f9290..6b334b11 100644 --- a/lua/sniprun/display.lua +++ b/lua/sniprun/display.lua @@ -35,7 +35,7 @@ end function M.term_open() if M.term.opened ~= 0 then return end - local open_term_cmd = ':rightb'.. M.display_options.terminal_width .. 'vsplit' + local open_term_cmd = ':rightb'.. M.config_values.display_options.terminal_width .. 'vsplit' vim.cmd(open_term_cmd) local buf = vim.api.nvim_create_buf(false,true) local win = vim.api.nvim_get_current_win() @@ -124,7 +124,7 @@ function M.display_nvim_notify(message, ok) local title = ok and "Sniprun: Ok" or "Sniprun: Error" local notif_style = ok and "info" or "error" - require("notify")(message, notif_style, {title=title, timeout=M.display_options.notification_timeout}) + require("notify")(message, notif_style, {title=title, timeout=M.config_values.display_options.notification_timeout}) end function M.display_extmark(ns,line, message, highlight) From 6a584e832958be535ef1da5f5b348452be294deb Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Sun, 19 Dec 2021 10:50:51 +0100 Subject: [PATCH 6/6] fix configurable display options again --- lua/sniprun/display.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/sniprun/display.lua b/lua/sniprun/display.lua index 6b334b11..93b9693f 100644 --- a/lua/sniprun/display.lua +++ b/lua/sniprun/display.lua @@ -35,7 +35,7 @@ end function M.term_open() if M.term.opened ~= 0 then return end - local open_term_cmd = ':rightb'.. M.config_values.display_options.terminal_width .. 'vsplit' + local open_term_cmd = ':rightb'.. require('sniprun').config_values.display_options.terminal_width .. 'vsplit' vim.cmd(open_term_cmd) local buf = vim.api.nvim_create_buf(false,true) local win = vim.api.nvim_get_current_win() @@ -124,7 +124,7 @@ function M.display_nvim_notify(message, ok) local title = ok and "Sniprun: Ok" or "Sniprun: Error" local notif_style = ok and "info" or "error" - require("notify")(message, notif_style, {title=title, timeout=M.config_values.display_options.notification_timeout}) + require("notify")(message, notif_style, {title=title, timeout=require('sniprun').config_values.display_options.notification_timeout}) end function M.display_extmark(ns,line, message, highlight)