Skip to content

Commit

Permalink
Added colour configuration to split dividers
Browse files Browse the repository at this point in the history
  • Loading branch information
curlpipe committed Nov 28, 2024
1 parent c2063f5 commit f7b5e00
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 4 deletions.
3 changes: 3 additions & 0 deletions config/.oxrc
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ colors.tab_inactive_bg = {59, 59, 84}
colors.tab_active_fg = {255, 255, 255}
colors.tab_active_bg = {41, 41, 61}

colors.split_bg = {41, 41, 61}
colors.split_fg = {59, 59, 84}

colors.info_fg = {99, 162, 255}
colors.info_bg = {41, 41, 61}
colors.warning_fg = {255, 182, 99}
Expand Down
3 changes: 3 additions & 0 deletions plugins/themes/default16.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ colors.tab_inactive_fg = white
colors.tab_active_bg = darkblue
colors.tab_active_fg = white

colors.split_bg = black
colors.split_fg = darkblue

colors.info_bg = black
colors.info_fg = cyan
colors.warning_bg = black
Expand Down
3 changes: 3 additions & 0 deletions plugins/themes/galaxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ colors.tab_inactive_fg = white
colors.tab_active_bg = grey2
colors.tab_active_fg = purple

colors.split_bg = black
colors.split_fg = purple

colors.info_bg = black
colors.info_fg = darkblue
colors.warning_bg = black
Expand Down
3 changes: 3 additions & 0 deletions plugins/themes/omni.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ colors.tab_inactive_fg = foreground
colors.tab_active_bg = background
colors.tab_active_fg = pink

colors.split_bg = background
colors.split_fg = white

colors.info_bg = background
colors.info_fg = cyan
colors.warning_bg = background
Expand Down
3 changes: 3 additions & 0 deletions plugins/themes/transparent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
colors.editor_bg = 'transparent'
colors.line_number_bg = 'transparent'

colors.split_bg = 'transparent'
colors.split_fg = 15

colors.info_bg = 'transparent'
colors.warning_bg = 'transparent'
colors.error_bg = 'transparent'
3 changes: 3 additions & 0 deletions plugins/themes/tropical.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ colors.tab_inactive_fg = white
colors.tab_active_bg = grey2
colors.tab_active_fg = orange

colors.split_bg = black
colors.split_fg = orange

colors.info_bg = black
colors.info_fg = darkblue
colors.warning_bg = black
Expand Down
16 changes: 16 additions & 0 deletions src/config/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub struct Colors {
pub tab_inactive_fg: Color,
pub tab_inactive_bg: Color,

pub split_bg: Color,
pub split_fg: Color,

pub info_bg: Color,
pub info_fg: Color,
pub warning_bg: Color,
Expand Down Expand Up @@ -54,6 +57,9 @@ impl Default for Colors {
tab_inactive_fg: Color::Rgb(255, 255, 255),
tab_inactive_bg: Color::Rgb(59, 59, 84),

split_bg: Color::Rgb(41, 41, 61),
split_fg: Color::Rgb(255, 255, 255),

info_bg: Color::Rgb(41, 41, 61),
info_fg: Color::Rgb(99, 162, 255),
warning_bg: Color::Rgb(41, 41, 61),
Expand Down Expand Up @@ -93,6 +99,8 @@ impl LuaUserData for Colors {
fields.add_field_method_get("tab_inactive_bg", |env, this| {
Ok(this.tab_inactive_bg.to_lua(env))
});
fields.add_field_method_get("split_bg", |env, this| Ok(this.split_bg.to_lua(env)));
fields.add_field_method_get("split_fg", |env, this| Ok(this.split_fg.to_lua(env)));
fields.add_field_method_get("error_bg", |env, this| Ok(this.error_bg.to_lua(env)));
fields.add_field_method_get("error_fg", |env, this| Ok(this.error_fg.to_lua(env)));
fields.add_field_method_get("warning_bg", |env, this| Ok(this.warning_bg.to_lua(env)));
Expand Down Expand Up @@ -149,6 +157,14 @@ impl LuaUserData for Colors {
this.tab_inactive_bg = Color::from_lua(value);
Ok(())
});
fields.add_field_method_set("split_fg", |_, this, value| {
this.split_fg = Color::from_lua(value);
Ok(())
});
fields.add_field_method_set("split_bg", |_, this, value| {
this.split_bg = Color::from_lua(value);
Ok(())
});
fields.add_field_method_set("error_bg", |_, this, value| {
this.error_bg = Color::from_lua(value);
Ok(())
Expand Down
9 changes: 5 additions & 4 deletions src/editor/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ impl Editor {
#[allow(clippy::similar_names)]
pub fn render_line(&mut self, y: usize, size: Size, lua: &Lua) -> Result<String> {
let tab_line_enabled = config!(self.config, tab_line).enabled;
let editor_bg = Bg(config!(self.config, colors).editor_bg.to_color()?);
let editor_fg = Fg(config!(self.config, colors).editor_fg.to_color()?);
let split_bg = Bg(config!(self.config, colors).split_bg.to_color()?);
let split_fg = Fg(config!(self.config, colors).split_fg.to_color()?);
let mut result = String::new();
let fcs = FileLayout::line(y, &self.render_cache.span);
// Accounted for is used to detect gaps in lines (which should be filled with vertical bars)
Expand All @@ -68,7 +68,7 @@ impl Editor {
if range.start != accounted_for {
// Discontinuity detected, fill with vertical bar!
let fill_length = range.start.saturating_sub(accounted_for);
result += &format!("{editor_bg}{editor_fg}");
result += &format!("{split_bg}{split_fg}");
for at in 0..fill_length.saturating_sub(1) {
let empty_below = FileLayout::is_empty_at(
y.saturating_add(1),
Expand Down Expand Up @@ -112,7 +112,7 @@ impl Editor {
if c == fcs.len().saturating_sub(1) {
accounted_for = range.end;
} else {
result += &format!("{editor_bg}{editor_fg}");
result += &format!("{split_bg}{split_fg}");
result += if fcs[c + 1].2.start == range.end + 1 {
// There is no vertical bar after this part
"│"
Expand All @@ -127,6 +127,7 @@ impl Editor {
if size.w != accounted_for {
// Discontinuity detected at the end, fill with vertical bar!
let fill_length = (size.w + 1).saturating_sub(accounted_for);
result += &format!("{split_bg}{split_fg}");
for at in 0..fill_length {
let empty_below = FileLayout::is_empty_at(
y.saturating_add(1),
Expand Down

0 comments on commit f7b5e00

Please sign in to comment.