From 81a2bbd5e8edb90d13afd22e1aab3aece6fbeebe Mon Sep 17 00:00:00 2001 From: cadwgan0 <58019185+cadwgan0@users.noreply.github.com> Date: Wed, 8 Jan 2020 07:32:15 -0500 Subject: [PATCH] TUI peer sort order (#3184) * alternative tui ordering when values equal * use closure and Ordering .then chain to clean code --- src/bin/tui/peers.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/bin/tui/peers.rs b/src/bin/tui/peers.rs index 6e42c8aac..890244f01 100644 --- a/src/bin/tui/peers.rs +++ b/src/bin/tui/peers.rs @@ -103,14 +103,19 @@ impl TableViewItem for PeerStats { curr_sum.cmp(&other_sum) }; + let sort_by_addr = || self.addr.cmp(&other.addr); + match column { - PeerColumn::Address => self.addr.cmp(&other.addr), - PeerColumn::State => self.state.cmp(&other.state), - PeerColumn::UsedBandwidth => cmp_used_bandwidth(&self, &other), - PeerColumn::TotalDifficulty => self.total_difficulty.cmp(&other.total_difficulty), - PeerColumn::Direction => self.direction.cmp(&other.direction), - PeerColumn::Version => self.version.cmp(&other.version), - PeerColumn::UserAgent => self.user_agent.cmp(&other.user_agent), + PeerColumn::Address => sort_by_addr(), + PeerColumn::State => self.state.cmp(&other.state).then(sort_by_addr()), + PeerColumn::UsedBandwidth => cmp_used_bandwidth(&self, &other).then(sort_by_addr()), + PeerColumn::TotalDifficulty => self + .total_difficulty + .cmp(&other.total_difficulty) + .then(sort_by_addr()), + PeerColumn::Direction => self.direction.cmp(&other.direction).then(sort_by_addr()), + PeerColumn::Version => self.version.cmp(&other.version).then(sort_by_addr()), + PeerColumn::UserAgent => self.user_agent.cmp(&other.user_agent).then(sort_by_addr()), } } }