Skip to content

Commit 97daa50

Browse files
authored
Merge pull request #281 from michaelb/dev
Dev
2 parents 0079f9c + 4a89b1c commit 97daa50

File tree

13 files changed

+48
-73
lines changed

13 files changed

+48
-73
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v1.3.12
2+
- More universally-working shebang in scripts
3+
- Use Lua api to set highlights in a more extensible way (courtesy of @pwnalone)
4+
15
## v1.3.11
26
- Support compiler flags for C++ (courtesy of @jonathanffon) and all other languages
37
- Scripts use \cat instead of /bin/cat (courtesy of @GaetanLepage)

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sniprun"
3-
version = "1.3.11"
3+
version = "1.3.12"
44
authors = ["michaelb <[email protected]>"]
55
rust-version = "1.65"
66
edition = "2018"

doc/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
set -x
33
set -e
44

doc/sources/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,12 @@ require'sniprun'.setup({
288288
},
289289
290290
--# customize highlight groups (setting this overrides colorscheme)
291+
--# any parameters of nvim_set_hl() can be passed as-is
291292
snipruncolors = {
292-
SniprunVirtualTextOk = {bg="#66eeff",fg="#000000",ctermbg="Cyan",cterfg="Black"},
293-
SniprunFloatingWinOk = {fg="#66eeff",ctermfg="Cyan"},
294-
SniprunVirtualTextErr = {bg="#881515",fg="#000000",ctermbg="DarkRed",cterfg="Black"},
295-
SniprunFloatingWinErr = {fg="#881515",ctermfg="DarkRed"},
293+
SniprunVirtualTextOk = {bg="#66eeff", fg="#000000", ctermbg="Cyan", ctermfg="Black"},
294+
SniprunFloatingWinOk = {fg="#66eeff", ctermfg="Cyan"},
295+
SniprunVirtualTextErr = {bg="#881515", fg="#000000", ctermbg="DarkRed", ctermfg="Black"},
296+
SniprunFloatingWinErr = {fg="#881515", ctermfg="DarkRed", bold=true},
296297
},
297298
298299
live_mode_toggle='off' --# live mode toggle, see Usage - Running for more info

lua/sniprun.lua

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local M = {}
22
M.ping_anwsered=0
3-
M.custom_highlight=false
43
M.info_floatwin = {}
54

65
-- See https://github.com/tjdevries/rofl.nvim/blob/632c10f2ec7c56882a3f7eda8849904bcac6e8af/lua/rofl.lua
@@ -54,10 +53,10 @@ M.config_values = {
5453

5554
-- default highlight stuff goes here
5655
snipruncolors = {
57-
SniprunVirtualTextOk = {bg="#66eeff",fg="#000000",ctermbg="Cyan",ctermfg="Black"},
58-
SniprunFloatingWinOk = {fg="#66eeff",ctermfg="Cyan"},
59-
SniprunVirtualTextErr = {bg="#881515",fg="#000000",ctermbg="DarkRed",ctermfg="Black"},
60-
SniprunFloatingWinErr = {fg="#881515",ctermfg="DarkRed"},
56+
SniprunVirtualTextOk = { default = true, bg="#66eeff", fg="#000000", ctermbg="Cyan", ctermfg="Black" },
57+
SniprunFloatingWinOk = { default = true, fg="#66eeff", ctermfg="Cyan" },
58+
SniprunVirtualTextErr = { default = true, bg="#881515", fg="#000000", ctermbg="DarkRed", ctermfg="Black" },
59+
SniprunFloatingWinErr = { default = true, fg="#881515", ctermfg="DarkRed" },
6160
},
6261

6362
-- 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)
9291
error(string.format('[Sniprun] Key %s does not exist in config values',key))
9392
return
9493
end
95-
if key == 'snipruncolors' then
96-
M.custom_highlight = true
97-
end
9894
if key == 'live_mode_toggle' and opts[key] == 'enable' then
9995
require('sniprun.live_mode')
10096
end
10197
end
10298

99+
-- Replace default highlights with custom ones rather than merging them together.
100+
M.config_values.snipruncolors = vim.tbl_extend("force", M.config_values.snipruncolors, opts.snipruncolors or {})
101+
103102
-- merge user config into default config values
104103
M.config_values = vim.tbl_deep_extend("force", M.config_values, opts)
105104

@@ -115,16 +114,15 @@ end
115114

116115

117116
local highlight = function(group, styles)
118-
local gui = styles.gui and 'gui='..styles.gui or 'gui=NONE'
119-
local sp = styles.sp and 'guisp='..styles.sp or 'guisp=NONE'
120-
local fg = styles.fg and 'guifg='..styles.fg or 'guifg=NONE'
121-
local bg = styles.bg and 'guibg='..styles.bg or 'guibg=NONE'
122-
local ctermbg = styles.ctermbg and 'ctermbg='..styles.ctermbg or 'ctermbg=NONE'
123-
local ctermfg = styles.ctermfg and 'ctermfg='..styles.ctermfg or 'ctermfg=NONE'
124-
-- This somehow works for default highlighting. with or even without cterm colors
125-
-- hacky way tho.Still I think better than !hlexists
126-
vim.cmd('highlight '..group..' '..gui..' '..sp..' '..fg..' '..bg..' '..ctermbg..' '..ctermfg)
127-
vim.api.nvim_command('autocmd ColorScheme * highlight '..group..' '..gui..' '..sp..' '..fg..' '..bg..' '..ctermbg..' '..ctermfg)
117+
-- Maintain compatibility with the previous way of setting highlights.
118+
local attrs = {}
119+
if styles.gui then
120+
for val in vim.gsplit(styles.gui, ",", { plain = true }) do
121+
attrs[val] = true
122+
end
123+
end
124+
125+
vim.api.nvim_set_hl(0, group, vim.tbl_extend("force", attrs, styles))
128126
end
129127

130128

@@ -135,26 +133,9 @@ end
135133

136134

137135
function M.setup_highlights()
138-
local colors_table = M.config_values["snipruncolors"]
139-
if M.custom_highlight then
140-
vim.cmd('augroup snip_highlights')
141-
vim.cmd('autocmd!')
142-
for group, styles in pairs(colors_table) do
143-
-- print('setting up for '..group,'with style :','bg :',styles.bg,'fg :',styles.fg)
144-
highlight(group, styles)
145-
end
146-
vim.cmd('augroup END')
147-
else
148-
for group, styles in pairs(colors_table) do
149-
local gui = styles.gui and 'gui='..styles.gui or 'gui=NONE'
150-
local sp = styles.sp and 'guisp='..styles.sp or 'guisp=NONE'
151-
local fg = styles.fg and 'guifg='..styles.fg or 'guifg=NONE'
152-
local bg = styles.bg and 'guibg='..styles.bg or 'guibg=NONE'
153-
local ctermbg = styles.ctermbg and 'ctermbg='..styles.ctermbg or 'ctermbg=NONE'
154-
local ctermfg = styles.ctermfg and 'ctermfg='..styles.ctermfg or 'ctermfg=NONE'
155-
156-
vim.cmd("if !hlexists('"..group.."') \n hi "..group.." "..gui.." "..sp.." "..fg.." "..bg.." "..ctermbg.." "..ctermfg)
157-
end
136+
local snipruncolors = M.config_values.snipruncolors
137+
for group, styles in pairs(snipruncolors) do
138+
highlight(group, styles)
158139
end
159140
end
160141

@@ -208,6 +189,7 @@ end
208189
function M.start()
209190
if M.job_id ~= nil then return end
210191
M.job_id = vim.fn.jobstart({ M.config_values.binary_path }, { rpc = true })
192+
M.setup_highlights() -- some configurations break highlights (lunarvim/lazy for example)
211193
end
212194

213195
function M.notify(method, ...)

ressources/init_repl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
# this script takes 3 (or more) args.
44
# $1 is a path to a working directory

ressources/launcher_repl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
\cat $1 > $2

ressources/sync_repl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
working_dir="$1/fifo_repl"
33
echo "sync requested" >> $working_dir/log
44

src/display.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,13 @@ use std::str::FromStr;
77
use std::sync::{Arc, Mutex};
88
use unindent::Unindent;
99

10-
#[derive(Clone, Copy, Debug, Ord, PartialOrd)]
10+
#[derive(Clone, Copy, Debug, Ord, PartialOrd, Eq, PartialEq)]
1111
pub enum DisplayFilter {
1212
OnlyOk,
1313
OnlyErr,
1414
Both,
1515
}
1616

17-
// abusing a little the system
18-
impl PartialEq for DisplayFilter {
19-
fn eq(&self, other: &Self) -> bool {
20-
match self {
21-
Both => true,
22-
OnlyOk => !matches!(other, OnlyErr),
23-
OnlyErr => !matches!(other, OnlyOk),
24-
}
25-
}
26-
}
27-
impl Eq for DisplayFilter {}
28-
2917
use DisplayFilter::*;
3018

3119
#[derive(Clone, Debug, Ord, PartialOrd, PartialEq, Eq)]
@@ -85,16 +73,16 @@ impl fmt::Display for DisplayFilter {
8573
impl fmt::Display for DisplayType {
8674
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8775
let name = match &self {
88-
DisplayType::Classic(f) => "Classic".to_string() + &f.to_string(),
89-
DisplayType::VirtualText(f) => "VirtualText".to_string() + &f.to_string(),
90-
DisplayType::Terminal(f) => "Terminal".to_string() + &f.to_string(),
91-
DisplayType::TerminalWithCode(f) => "TerminalWithCode".to_string() + &f.to_string(),
92-
DisplayType::LongTempFloatingWindow(f) => {
93-
"LongTempFloatingWindow".to_string() + &f.to_string()
76+
DisplayType::Classic(filter) => "Classic".to_string() + &filter.to_string(),
77+
DisplayType::VirtualText(filter) => "VirtualText".to_string() + &filter.to_string(),
78+
DisplayType::Terminal(filter) => "Terminal".to_string() + &filter.to_string(),
79+
DisplayType::TerminalWithCode(filter) => "TerminalWithCode".to_string() + &filter.to_string(),
80+
DisplayType::LongTempFloatingWindow(filter) => {
81+
"LongTempFloatingWindow".to_string() + &filter.to_string()
9482
}
95-
DisplayType::TempFloatingWindow(f) => "TempFloatingWindow".to_string() + &f.to_string(),
96-
DisplayType::Api(f) => "Api".to_string() + &f.to_string(),
97-
DisplayType::NvimNotify(f) => "NvimNotify".to_string() + &f.to_string(),
83+
DisplayType::TempFloatingWindow(filter) => "TempFloatingWindow".to_string() + &filter.to_string(),
84+
DisplayType::Api(filter) => "Api".to_string() + &filter.to_string(),
85+
DisplayType::NvimNotify(filter) => "NvimNotify".to_string() + &filter.to_string(),
9886
};
9987
write!(f, "{}", name)
10088
}

0 commit comments

Comments
 (0)