From 672b0c5c98477c903535d9c7966b934af177e9d4 Mon Sep 17 00:00:00 2001 From: Tal <83217276+talwat@users.noreply.github.com> Date: Sat, 28 Sep 2024 01:06:39 +0200 Subject: [PATCH] feat: handle ctrl+c --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/player/ui.rs | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c24f645..262f3df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -982,7 +982,7 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "lowfi" -version = "1.0.1" +version = "1.0.2" dependencies = [ "Inflector", "arc-swap", diff --git a/Cargo.toml b/Cargo.toml index eb68f3e..ea71aac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lowfi" -version = "1.0.1" +version = "1.0.2" edition = "2021" description = "An extremely simple lofi player." license = "MIT" diff --git a/src/player/ui.rs b/src/player/ui.rs index a0717a1..e04103e 100644 --- a/src/player/ui.rs +++ b/src/player/ui.rs @@ -7,7 +7,7 @@ use crate::tracks::TrackInfo; use super::Player; use crossterm::{ cursor::{Hide, MoveToColumn, MoveUp, Show}, - event, + event::{self, KeyCode, KeyModifiers}, style::{Print, Stylize}, terminal::{self, Clear, ClearType}, }; @@ -143,11 +143,17 @@ pub async fn start(queue: Arc, sender: Sender) -> eyre::Result continue; }; - let event::KeyCode::Char(code) = event.code else { + let KeyCode::Char(code) = event.code else { continue; }; match code { + 'c' => { + // Handles Ctrl+C. + if event.modifiers == KeyModifiers::CONTROL { + break; + } + } 'q' => { break; }