Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,28 @@ impl ConfigEnum for raur::SearchBy {

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SortMode {
Auto,
BottomUp,
TopDown,
}

impl ConfigEnum for SortMode {
const VALUE_LOOKUP: ConfigEnumValues<Self> =
&[("bottomup", Self::BottomUp), ("topdown", Self::TopDown)];
const VALUE_LOOKUP: ConfigEnumValues<Self> = &[
("auto", Self::Auto),
("bottomup", Self::BottomUp),
("topdown", Self::TopDown),
];
}

impl SortMode {
pub fn is_top_down(self, interactive: bool) -> bool {
match (self, interactive) {
(SortMode::TopDown, _) => true,
(SortMode::BottomUp, _) => false,
(SortMode::Auto, true) => false,
(SortMode::Auto, false) => true,
}
}
}

bitflags! {
Expand Down Expand Up @@ -431,7 +446,7 @@ pub struct Config {
#[default(raur::SearchBy::NameDesc)]
pub search_by: raur::SearchBy,
pub limit: usize,
#[default(SortMode::TopDown)]
#[default(SortMode::Auto)]
pub sort_mode: SortMode,
#[default(Mode::empty())]
pub mode: Mode,
Expand Down Expand Up @@ -1041,6 +1056,7 @@ then initialise it with:
match key {
"SkipReview" => self.skip_review = true,
"BottomUp" => self.sort_mode = SortMode::BottomUp,
"TopDown" => self.sort_mode = SortMode::TopDown,
"AurOnly" => self.mode = Mode::AUR,
"PkgbuildsOnly" => self.mode = Mode::PKGBUILD,
"RepoOnly" => self.mode = Mode::REPO,
Expand Down
4 changes: 2 additions & 2 deletions src/download.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::config::{Colors, Config, SortMode, YesNoAll};
use crate::config::{Colors, Config, YesNoAll};
use crate::exec::has_command;
use crate::fmt::print_indent;
use crate::util::is_arch_repo;
Expand Down Expand Up @@ -480,7 +480,7 @@ pub async fn show_comments(config: &mut Config) -> Result<i32> {

let iter = titles.zip(comments).collect::<Vec<_>>();

if config.sort_mode == SortMode::TopDown {
if config.sort_mode.is_top_down(false) {
for (title, comment) in iter.into_iter() {
print_indent(c.bold, 0, 0, config.cols, " ", title.split_whitespace());

Expand Down
8 changes: 4 additions & 4 deletions src/search.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::Path;

use crate::config::Config;
use crate::config::SortBy;
use crate::config::{Config, SortMode};
use crate::fmt::{color_repo, link_str, print_indent};
use crate::util::{input, is_arch_repo, NumberMenu};
use crate::{info, printtr};
Expand Down Expand Up @@ -53,7 +53,7 @@ pub async fn search(config: &Config) -> Result<i32> {
}
};

if config.sort_mode == SortMode::TopDown {
if config.sort_mode.is_top_down(false) {
for pkg in &repo_pkgs {
print_alpm_pkg(config, pkg, quiet);
}
Expand Down Expand Up @@ -515,7 +515,7 @@ pub fn interactive_menu(
all_pkgs.insert(0, pkg);
}

if config.sort_mode == SortMode::TopDown {
if config.sort_mode.is_top_down(true) {
for (n, pkg) in all_pkgs.iter().enumerate() {
print_any_pkg(config, n, pad, pkg)
}
Expand All @@ -538,7 +538,7 @@ pub fn interactive_menu(
let menu = NumberMenu::new(&input);
let mut pkgs = Vec::new();

if config.sort_mode == SortMode::TopDown {
if config.sort_mode.is_top_down(true) {
for (n, pkg) in all_pkgs.iter().enumerate() {
if menu.contains(n + 1, "") {
match pkg {
Expand Down