Skip to content

Commit

Permalink
fix: restore line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Akmadan23 committed Mar 14, 2024
1 parent 59b6ae5 commit 11a4c70
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 25 deletions.
5 changes: 1 addition & 4 deletions src/config/clean/theme/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub struct AppStyle {
pub fg: style::Color,
pub bg: style::Color,
pub prefix: String,
pub prefix_width: usize,
pub modifier: style::Modifier,
}

Expand All @@ -22,9 +21,8 @@ impl AppStyle {
self.fg = fg;
self
}
pub fn set_prefix(mut self, prefix: String, prefix_width: usize) -> Self {
pub fn set_prefix(mut self, prefix: String) -> Self {
self.prefix = prefix;
self.prefix_width = prefix_width;
self
}

Expand All @@ -44,7 +42,6 @@ impl std::default::Default for AppStyle {
fg: default_color(),
bg: default_color(),
prefix: String::new(),
prefix_width: 0,
modifier: style::Modifier::empty(),
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/config/raw/theme/style.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use colors_transform::{Color, Rgb};
use ratatui::style::{self, Style};
use serde::Deserialize;
use unicode_width::UnicodeWidthStr;

use crate::config::clean::theme::style::AppStyle;

Expand Down Expand Up @@ -111,8 +110,6 @@ impl AppStyleRaw {
pub fn to_style_theme(&self) -> AppStyle {
let bg = Self::str_to_color(self.bg.as_str());
let fg = Self::str_to_color(self.fg.as_str());
let prefix = self.prefix.clone();
let prefix_width = prefix.width();

let mut modifier = style::Modifier::empty();
if self.bold {
Expand All @@ -128,7 +125,7 @@ impl AppStyleRaw {
AppStyle::default()
.set_fg(fg)
.set_bg(bg)
.set_prefix(prefix, prefix_width)
.set_prefix(self.prefix.clone())
.insert(modifier)
}

Expand Down
7 changes: 2 additions & 5 deletions src/ui/widgets/tui_dirlist_detailed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ impl<'a> Widget for TuiDirListDetailed<'a> {

buf.set_string(x, y + i as u16, space_fill.as_str(), style);

let (prefix, prefix_width) = style::entry_prefix(entry);
let mut prefix = prefix.to_string();
let mut prefix = style::entry_prefix(entry).to_string();
let line_number_prefix = match line_num_style {
LineNumberStyle::None => "".to_string(),
_ if ix == curr_index => format!("{:<1$} ", curr_index + 1, max_index_length),
Expand All @@ -118,7 +117,6 @@ impl<'a> Widget for TuiDirListDetailed<'a> {
self.tab_display_options.linemode,
drawing_width - 1,
&prefix,
prefix_width,
);
});
}
Expand All @@ -135,7 +133,6 @@ fn get_entry_size_string(entry: &JoshutoDirEntry) -> String {
}
}

#[allow(clippy::too_many_arguments)]
fn print_entry(
config: &AppConfig,
buf: &mut Buffer,
Expand All @@ -145,7 +142,6 @@ fn print_entry(
linemode: LineMode,
drawing_width: usize,
prefix: &str,
prefix_width: usize,
) {
let symlink_string = match entry.metadata.link_type() {
LinkType::Normal => "",
Expand Down Expand Up @@ -185,6 +181,7 @@ fn print_entry(
);

// draw prefix first
let prefix_width = prefix.width();
buf.set_stringn(x, y, prefix, prefix_width, Style::default());
let x = x + prefix_width as u16;

Expand Down
18 changes: 6 additions & 12 deletions src/util/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,14 @@ pub fn entry_style(config: &AppConfig, entry: &JoshutoDirEntry) -> Style {
}
}

pub fn entry_prefix(entry: &JoshutoDirEntry) -> (&str, usize) {
pub fn entry_prefix(entry: &JoshutoDirEntry) -> &str {
if entry.is_visual_mode_selected() {
return (
THEME_T.visual_mode_selection.prefix.as_str(),
THEME_T.visual_mode_selection.prefix_width,
);
}
if entry.is_permanent_selected() {
return (
THEME_T.selection.prefix.as_str(),
THEME_T.selection.prefix_width,
);
&THEME_T.visual_mode_selection.prefix
} else if entry.is_permanent_selected() {
&THEME_T.selection.prefix
} else {
""
}
("", 0)
}

fn default_style(
Expand Down

0 comments on commit 11a4c70

Please sign in to comment.