Skip to content

Commit

Permalink
add padding and preserve order
Browse files Browse the repository at this point in the history
  • Loading branch information
micielski committed Jul 5, 2024
1 parent 1e6b8b7 commit 17cafec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion rm-config/src/main_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn default_refresh() -> u64 {
5
}

#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Serialize, Deserialize, Hash, PartialEq, Eq)]
pub enum Header {
Name,
SizeWhenDone,
Expand All @@ -61,6 +61,7 @@ pub enum Header {
DownloadRate,
UploadRate,
DownloadDir,
Padding,
}

impl Header {
Expand All @@ -73,6 +74,7 @@ impl Header {
Header::DownloadRate => Constraint::Length(12),
Header::UploadRate => Constraint::Length(12),
Header::DownloadDir => Constraint::Max(70),
Header::Padding => Constraint::Length(2),
}
}

Expand All @@ -85,6 +87,7 @@ impl Header {
Header::DownloadRate => "Download",
Header::UploadRate => "Upload",
Header::DownloadDir => "Directory",
Header::Padding => "",
}
}
}
Expand Down
1 change: 1 addition & 0 deletions rm-main/src/ui/tabs/torrents/rustmission_torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl RustmissionTorrent {
Header::DownloadRate => Line::from(download_speed_format(&self.download_speed)),
Header::UploadRate => Line::from(upload_speed_format(&self.upload_speed)),
Header::DownloadDir => Line::from(self.download_dir.as_str()),
Header::Padding => Line::raw(""),
}
};
cells.push(cell);
Expand Down
12 changes: 9 additions & 3 deletions rm-main/src/ui/tabs/torrents/table_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
use ratatui::{prelude::*, widgets::Row};
use rm_config::main_config::Header;
use std::{
collections::BTreeMap,
collections::HashMap,
sync::{Arc, Mutex},
};

Expand Down Expand Up @@ -117,7 +117,7 @@ impl TableManager {
return Self::default_widths(&headers);
}

let mut map = BTreeMap::new();
let mut map = HashMap::new();

for header in headers {
map.insert(header, header.default_constraint());
Expand Down Expand Up @@ -155,6 +155,12 @@ impl TableManager {
}
}

map.values().cloned().collect()
let mut constraints = vec![];

for header in headers {
constraints.push(map.remove(header).expect("this header exists"))
}

constraints
}
}

0 comments on commit 17cafec

Please sign in to comment.