Skip to content

Commit

Permalink
Merge pull request #281 from michaelb/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
michaelb authored Mar 24, 2024
2 parents 0079f9c + 4a89b1c commit 97daa50
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 73 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.3.12
- More universally-working shebang in scripts
- 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
- Scripts use \cat instead of /bin/cat (courtesy of @GaetanLepage)
Expand Down
2 changes: 1 addition & 1 deletion 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.3.11"
version = "1.3.12"
authors = ["michaelb <[email protected]>"]
rust-version = "1.65"
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion doc/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -x
set -e

Expand Down
9 changes: 5 additions & 4 deletions doc/sources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 20 additions & 38 deletions lua/sniprun.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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


Expand All @@ -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

Expand Down Expand Up @@ -208,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, ...)
Expand Down
2 changes: 1 addition & 1 deletion ressources/init_repl.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ressources/launcher_repl.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
#!/usr/bin/env bash
\cat $1 > $2
2 changes: 1 addition & 1 deletion ressources/sync_repl.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
working_dir="$1/fifo_repl"
echo "sync requested" >> $working_dir/log

Expand Down
32 changes: 10 additions & 22 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/Julia_original/init_repl.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/Mathematica_original/init_repl.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
working_dir=$1
if [ -z "$working_dir" ]; then
exit 1
Expand Down
2 changes: 1 addition & 1 deletion src/interpreters/Mathematica_original/launcher.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
#!/usr/bin/env bash
cat $1 > $2

0 comments on commit 97daa50

Please sign in to comment.