Skip to content

Commit

Permalink
Merge pull request #132 from sachaos/use-stable-only
Browse files Browse the repository at this point in the history
Remove intersperse
  • Loading branch information
sachaos authored Aug 21, 2024
2 parents 5b57c22 + f0e8358 commit 7069ce9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
toolchain: stable

target: ${{ matrix.target }}

Expand All @@ -78,7 +78,7 @@ jobs:

use-cross: ${{ matrix.use-cross }}

toolchain: nightly
toolchain: stable

args: --release --target ${{ matrix.target }}

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@nightly
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run tests
run: cargo test --all-features --workspace
Expand All @@ -27,7 +27,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@nightly
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- uses: Swatinem/rust-cache@v2
Expand All @@ -41,7 +41,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@nightly
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
Expand All @@ -55,7 +55,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@nightly
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Check documentation
env:
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly"
channel = "stable"
58 changes: 45 additions & 13 deletions src/components/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ fn keys_str(
) -> Vec<Span> {
keybindings.get(&(mode, action.clone())).map_or_else(
|| vec![Span::from("None")],
|keys| {
keys.iter()
.map(|keys| {
let mut s = String::new();
for key in keys {
s.push('<');
s.push_str(&display_key(key));
s.push('>');
}
Span::styled(s, Style::default().fg(Color::Yellow))
})
.intersperse(Span::from(", "))
.collect()
|keys_list| {
let mut spans = Vec::new();
for (i, keys) in keys_list.iter().enumerate() {
let mut s = String::new();
for key in keys {
s.push('<');
s.push_str(&display_key(key));
s.push('>');
}
spans.push(Span::styled(s, Style::default().fg(Color::Yellow)));
if i < keys_list.len() - 1 {
spans.push(Span::from(", "));
}
}
spans
},
)
}
Expand Down Expand Up @@ -396,3 +398,33 @@ fn get_action_keys(keybindings: KeyBindings) -> HashMap<(Mode, String), Vec<Vec<
});
action_keys
}

#[cfg(test)]
mod tests {
use super::*;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use std::collections::HashMap;

#[test]
fn test_keys_str() {
let mut keybindings = HashMap::new();
let mode = Mode::All;
let action = String::from("action");
let key_event1 = KeyEvent::from(KeyCode::Char('a'));
let key_event2 = KeyEvent::from(KeyCode::Char('b'));
let key_event3 = KeyEvent::from(KeyCode::Char('c'));
keybindings.insert(
(mode, action.clone()),
vec![vec![key_event1], vec![key_event2, key_event3]],
);

let result = keys_str(&keybindings, mode, action);

let expected_output = vec![
Span::styled("<a>", Style::default().fg(Color::Yellow)),
Span::from(", "),
Span::styled("<b><c>", Style::default().fg(Color::Yellow)),
];
assert_eq!(result, expected_output);
}
}
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]
#![feature(iter_intersperse)]

pub mod action;
pub mod app;
Expand Down

0 comments on commit 7069ce9

Please sign in to comment.