From 54412d34be91eb7fbe3a03a1b81e96abbb664da3 Mon Sep 17 00:00:00 2001 From: Michael B Date: Tue, 16 Jan 2024 21:00:16 +0100 Subject: [PATCH 1/6] beta --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 59c46c0..322e460 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sniprun" -version = "1.3.11" +version = "1.3.12-beta" authors = ["michaelb "] rust-version = "1.65" edition = "2018" From a10938b021dd4349aae12a3c6ade7c1bd3108d06 Mon Sep 17 00:00:00 2001 From: Joshua Inscoe Date: Sat, 23 Mar 2024 15:04:57 -0700 Subject: [PATCH 2/6] Use nvim_set_hl() to set highlights --- lua/sniprun.lua | 57 +++++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/lua/sniprun.lua b/lua/sniprun.lua index fe29d1e..d04045d 100644 --- a/lua/sniprun.lua +++ b/lua/sniprun.lua @@ -1,6 +1,5 @@ local M = {} M.ping_anwsered=0 -M.custom_highlight=false M.info_floatwin = {} -- See https://github.com/tjdevries/rofl.nvim/blob/632c10f2ec7c56882a3f7eda8849904bcac6e8af/lua/rofl.lua @@ -54,10 +53,10 @@ M.config_values = { -- default highlight stuff goes here snipruncolors = { - SniprunVirtualTextOk = {bg="#66eeff",fg="#000000",ctermbg="Cyan",ctermfg="Black"}, - SniprunFloatingWinOk = {fg="#66eeff",ctermfg="Cyan"}, - SniprunVirtualTextErr = {bg="#881515",fg="#000000",ctermbg="DarkRed",ctermfg="Black"}, - SniprunFloatingWinErr = {fg="#881515",ctermfg="DarkRed"}, + SniprunVirtualTextOk = { default = true, bg="#66eeff", fg="#000000", ctermbg="Cyan", ctermfg="Black" }, + SniprunFloatingWinOk = { default = true, fg="#66eeff", ctermfg="Cyan" }, + SniprunVirtualTextErr = { default = true, bg="#881515", fg="#000000", ctermbg="DarkRed", ctermfg="Black" }, + SniprunFloatingWinErr = { default = true, fg="#881515", ctermfg="DarkRed" }, }, -- whether the user can toggle the live_mode. It's kept as an option so it's not activated by chance @@ -92,14 +91,14 @@ function M.setup(opts) error(string.format('[Sniprun] Key %s does not exist in config values',key)) return end - if key == 'snipruncolors' then - M.custom_highlight = true - end if key == 'live_mode_toggle' and opts[key] == 'enable' then require('sniprun.live_mode') end end + -- Replace default highlights with custom ones rather than merging them together. + M.config_values.snipruncolors = vim.tbl_extend("force", M.config_values.snipruncolors, opts.snipruncolors or {}) + -- merge user config into default config values M.config_values = vim.tbl_deep_extend("force", M.config_values, opts) @@ -115,16 +114,15 @@ end local highlight = function(group, styles) - local gui = styles.gui and 'gui='..styles.gui or 'gui=NONE' - local sp = styles.sp and 'guisp='..styles.sp or 'guisp=NONE' - local fg = styles.fg and 'guifg='..styles.fg or 'guifg=NONE' - local bg = styles.bg and 'guibg='..styles.bg or 'guibg=NONE' - local ctermbg = styles.ctermbg and 'ctermbg='..styles.ctermbg or 'ctermbg=NONE' - local ctermfg = styles.ctermfg and 'ctermfg='..styles.ctermfg or 'ctermfg=NONE' - -- This somehow works for default highlighting. with or even without cterm colors - -- hacky way tho.Still I think better than !hlexists - vim.cmd('highlight '..group..' '..gui..' '..sp..' '..fg..' '..bg..' '..ctermbg..' '..ctermfg) - vim.api.nvim_command('autocmd ColorScheme * highlight '..group..' '..gui..' '..sp..' '..fg..' '..bg..' '..ctermbg..' '..ctermfg) + -- Maintain compatibility with the previous way of setting highlights. + local attrs = {} + if styles.gui then + for val in vim.gsplit(styles.gui, ",", { plain = true }) do + attrs[val] = true + end + end + + vim.api.nvim_set_hl(0, group, vim.tbl_extend("force", attrs, styles)) end @@ -135,26 +133,9 @@ end function M.setup_highlights() - local colors_table = M.config_values["snipruncolors"] - if M.custom_highlight then - vim.cmd('augroup snip_highlights') - vim.cmd('autocmd!') - for group, styles in pairs(colors_table) do - -- print('setting up for '..group,'with style :','bg :',styles.bg,'fg :',styles.fg) - highlight(group, styles) - end - vim.cmd('augroup END') - else - for group, styles in pairs(colors_table) do - local gui = styles.gui and 'gui='..styles.gui or 'gui=NONE' - local sp = styles.sp and 'guisp='..styles.sp or 'guisp=NONE' - local fg = styles.fg and 'guifg='..styles.fg or 'guifg=NONE' - local bg = styles.bg and 'guibg='..styles.bg or 'guibg=NONE' - local ctermbg = styles.ctermbg and 'ctermbg='..styles.ctermbg or 'ctermbg=NONE' - local ctermfg = styles.ctermfg and 'ctermfg='..styles.ctermfg or 'ctermfg=NONE' - - vim.cmd("if !hlexists('"..group.."') \n hi "..group.." "..gui.." "..sp.." "..fg.." "..bg.." "..ctermbg.." "..ctermfg) - end + local snipruncolors = M.config_values.snipruncolors + for group, styles in pairs(snipruncolors) do + highlight(group, styles) end end From d9e0738b4f091794b0af0d0869cd1242654fca92 Mon Sep 17 00:00:00 2001 From: Michael B Date: Sun, 24 Mar 2024 15:59:11 +0100 Subject: [PATCH 3/6] replace shebangs --- doc/build.sh | 2 +- ressources/init_repl.sh | 2 +- ressources/launcher_repl.sh | 2 +- ressources/sync_repl.sh | 2 +- src/interpreters/Julia_original/init_repl.sh | 2 +- src/interpreters/Mathematica_original/init_repl.sh | 2 +- src/interpreters/Mathematica_original/launcher.sh | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/build.sh b/doc/build.sh index b0f657d..b373ab7 100755 --- a/doc/build.sh +++ b/doc/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -x set -e diff --git a/ressources/init_repl.sh b/ressources/init_repl.sh index 45f8a6c..3c31649 100755 --- a/ressources/init_repl.sh +++ b/ressources/init_repl.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # this script takes 3 (or more) args. # $1 is a path to a working directory diff --git a/ressources/launcher_repl.sh b/ressources/launcher_repl.sh index 23da816..542ef83 100755 --- a/ressources/launcher_repl.sh +++ b/ressources/launcher_repl.sh @@ -1,2 +1,2 @@ -#!/bin/bash +#!/usr/bin/env bash \cat $1 > $2 diff --git a/ressources/sync_repl.sh b/ressources/sync_repl.sh index 59f3b7d..1bc10df 100755 --- a/ressources/sync_repl.sh +++ b/ressources/sync_repl.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash working_dir="$1/fifo_repl" echo "sync requested" >> $working_dir/log diff --git a/src/interpreters/Julia_original/init_repl.sh b/src/interpreters/Julia_original/init_repl.sh index 64eb293..ab7c4b1 100755 --- a/src/interpreters/Julia_original/init_repl.sh +++ b/src/interpreters/Julia_original/init_repl.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # this script takes 3 (or more) args. # $1 is a path to a working directory diff --git a/src/interpreters/Mathematica_original/init_repl.sh b/src/interpreters/Mathematica_original/init_repl.sh index 91ec221..3ca6c6c 100755 --- a/src/interpreters/Mathematica_original/init_repl.sh +++ b/src/interpreters/Mathematica_original/init_repl.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash working_dir=$1 if [ -z "$working_dir" ]; then exit 1 diff --git a/src/interpreters/Mathematica_original/launcher.sh b/src/interpreters/Mathematica_original/launcher.sh index 749c55e..c2ba576 100755 --- a/src/interpreters/Mathematica_original/launcher.sh +++ b/src/interpreters/Mathematica_original/launcher.sh @@ -1,2 +1,2 @@ -#!/bin/bash +#!/usr/bin/env bash cat $1 > $2 From 525ebbe115ff80fc4818ab0ffaba83a89f6c45a0 Mon Sep 17 00:00:00 2001 From: Michael B Date: Sun, 24 Mar 2024 16:26:14 +0100 Subject: [PATCH 4/6] doc --- CHANGELOG.md | 4 ++++ doc/sources/README.md | 9 +++++---- lua/sniprun.lua | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28a2de2..52d802b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v1.3.12 +- More universally-working shebang in scripts +- Use Lua api to set highlights in a more extensible way + ## v1.3.11 - Support compiler flags for C++ (courtesy of @jonathanffon) and all other languages - Scripts use \cat instead of /bin/cat (courtesy of @GaetanLepage) diff --git a/doc/sources/README.md b/doc/sources/README.md index 9ef3b6a..0d04ccc 100755 --- a/doc/sources/README.md +++ b/doc/sources/README.md @@ -288,11 +288,12 @@ require'sniprun'.setup({ }, --# customize highlight groups (setting this overrides colorscheme) + --# any parameters of nvim_set_hl() can be passed as-is snipruncolors = { - SniprunVirtualTextOk = {bg="#66eeff",fg="#000000",ctermbg="Cyan",cterfg="Black"}, - SniprunFloatingWinOk = {fg="#66eeff",ctermfg="Cyan"}, - SniprunVirtualTextErr = {bg="#881515",fg="#000000",ctermbg="DarkRed",cterfg="Black"}, - SniprunFloatingWinErr = {fg="#881515",ctermfg="DarkRed"}, + SniprunVirtualTextOk = {bg="#66eeff", fg="#000000", ctermbg="Cyan", ctermfg="Black"}, + SniprunFloatingWinOk = {fg="#66eeff", ctermfg="Cyan"}, + SniprunVirtualTextErr = {bg="#881515", fg="#000000", ctermbg="DarkRed", ctermfg="Black"}, + SniprunFloatingWinErr = {fg="#881515", ctermfg="DarkRed", bold=true}, }, live_mode_toggle='off' --# live mode toggle, see Usage - Running for more info diff --git a/lua/sniprun.lua b/lua/sniprun.lua index d04045d..8894559 100644 --- a/lua/sniprun.lua +++ b/lua/sniprun.lua @@ -189,6 +189,7 @@ end function M.start() if M.job_id ~= nil then return end M.job_id = vim.fn.jobstart({ M.config_values.binary_path }, { rpc = true }) + -- M.setup_highlights() -- some configurations break highlights (lunarvim/lazy for example) end function M.notify(method, ...) From 82ea1a3c55e60f64300584f5e9349cdd4a9a8517 Mon Sep 17 00:00:00 2001 From: Michael B Date: Sun, 24 Mar 2024 16:51:45 +0100 Subject: [PATCH 5/6] small fixes --- CHANGELOG.md | 2 +- Cargo.lock | 2 +- lua/sniprun.lua | 2 +- src/display.rs | 32 ++++++++++---------------------- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52d802b..d386371 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## v1.3.12 - More universally-working shebang in scripts -- Use Lua api to set highlights in a more extensible way +- Use Lua api to set highlights in a more extensible way (courtesy of @pwnalone) ## v1.3.11 - Support compiler flags for C++ (courtesy of @jonathanffon) and all other languages diff --git a/Cargo.lock b/Cargo.lock index b024ae7..58f5e5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -798,7 +798,7 @@ checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "sniprun" -version = "1.3.11" +version = "1.3.12-beta" dependencies = [ "close_fds", "dirs", diff --git a/lua/sniprun.lua b/lua/sniprun.lua index 8894559..4a6002d 100644 --- a/lua/sniprun.lua +++ b/lua/sniprun.lua @@ -189,7 +189,7 @@ end function M.start() if M.job_id ~= nil then return end M.job_id = vim.fn.jobstart({ M.config_values.binary_path }, { rpc = true }) - -- M.setup_highlights() -- some configurations break highlights (lunarvim/lazy for example) + M.setup_highlights() -- some configurations break highlights (lunarvim/lazy for example) end function M.notify(method, ...) diff --git a/src/display.rs b/src/display.rs index 121f600..77b92f3 100644 --- a/src/display.rs +++ b/src/display.rs @@ -7,25 +7,13 @@ use std::str::FromStr; use std::sync::{Arc, Mutex}; use unindent::Unindent; -#[derive(Clone, Copy, Debug, Ord, PartialOrd)] +#[derive(Clone, Copy, Debug, Ord, PartialOrd, Eq, PartialEq)] pub enum DisplayFilter { OnlyOk, OnlyErr, Both, } -// abusing a little the system -impl PartialEq for DisplayFilter { - fn eq(&self, other: &Self) -> bool { - match self { - Both => true, - OnlyOk => !matches!(other, OnlyErr), - OnlyErr => !matches!(other, OnlyOk), - } - } -} -impl Eq for DisplayFilter {} - use DisplayFilter::*; #[derive(Clone, Debug, Ord, PartialOrd, PartialEq, Eq)] @@ -85,16 +73,16 @@ impl fmt::Display for DisplayFilter { impl fmt::Display for DisplayType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let name = match &self { - DisplayType::Classic(f) => "Classic".to_string() + &f.to_string(), - DisplayType::VirtualText(f) => "VirtualText".to_string() + &f.to_string(), - DisplayType::Terminal(f) => "Terminal".to_string() + &f.to_string(), - DisplayType::TerminalWithCode(f) => "TerminalWithCode".to_string() + &f.to_string(), - DisplayType::LongTempFloatingWindow(f) => { - "LongTempFloatingWindow".to_string() + &f.to_string() + DisplayType::Classic(filter) => "Classic".to_string() + &filter.to_string(), + DisplayType::VirtualText(filter) => "VirtualText".to_string() + &filter.to_string(), + DisplayType::Terminal(filter) => "Terminal".to_string() + &filter.to_string(), + DisplayType::TerminalWithCode(filter) => "TerminalWithCode".to_string() + &filter.to_string(), + DisplayType::LongTempFloatingWindow(filter) => { + "LongTempFloatingWindow".to_string() + &filter.to_string() } - DisplayType::TempFloatingWindow(f) => "TempFloatingWindow".to_string() + &f.to_string(), - DisplayType::Api(f) => "Api".to_string() + &f.to_string(), - DisplayType::NvimNotify(f) => "NvimNotify".to_string() + &f.to_string(), + DisplayType::TempFloatingWindow(filter) => "TempFloatingWindow".to_string() + &filter.to_string(), + DisplayType::Api(filter) => "Api".to_string() + &filter.to_string(), + DisplayType::NvimNotify(filter) => "NvimNotify".to_string() + &filter.to_string(), }; write!(f, "{}", name) } From 4a89b1c19e9a7ee0976deadd44d46eb34519620a Mon Sep 17 00:00:00 2001 From: Michael B Date: Sun, 24 Mar 2024 16:54:34 +0100 Subject: [PATCH 6/6] remove beta from version --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58f5e5f..e999ed7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -798,7 +798,7 @@ checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "sniprun" -version = "1.3.12-beta" +version = "1.3.12" dependencies = [ "close_fds", "dirs", diff --git a/Cargo.toml b/Cargo.toml index 322e460..e85509c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sniprun" -version = "1.3.12-beta" +version = "1.3.12" authors = ["michaelb "] rust-version = "1.65" edition = "2018"