Skip to content

Commit

Permalink
Handle ctrl+c/v/x properly + add bell
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Mar 21, 2024
1 parent 0a30970 commit 876c858
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

Binary file added assets/sounds/bell.wav
Binary file not shown.
2 changes: 2 additions & 0 deletions crates/term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ serde.workspace = true

luminol-core.workspace = true
luminol-components.workspace = true
luminol-macros.workspace = true
luminol-audio.workspace = true
color-eyre.workspace = true

strum.workspace = true
Expand Down
1 change: 0 additions & 1 deletion crates/term/src/backends/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ impl super::Backend for Process {

fn send(&mut self, bytes: impl Into<std::borrow::Cow<'static, [u8]>>) {
let bytes = bytes.into();
println!("{:?}", bytes);
self.notifier.notify(bytes);
}

Expand Down
1 change: 0 additions & 1 deletion crates/term/src/widget/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ pub fn key_to_codes(
modifiers: egui::Modifiers,
term_mode: TermMode,
) -> Option<&'static [u8]> {
println!("{key:?} {modifiers:?}");
key_binding! {
key, modifiers, term_mode;
// ANY
Expand Down
39 changes: 36 additions & 3 deletions crates/term/src/widget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,14 @@ where
match event {
Event::Title(title) => self.title = title,
Event::ResetTitle => "Luminol Terminal".clone_into(&mut self.title),
Event::Bell => {}
Event::Bell => {
let bell = luminol_macros::include_asset!("assets/sounds/bell.wav");
let cursor = std::io::Cursor::new(bell);
update_state
.audio
.play_from_file(cursor, false, 25, 100, luminol_audio::Source::SE)
.unwrap();
}
_ => {}
}
}
Expand Down Expand Up @@ -349,15 +356,19 @@ where
fn process_egui_events(
&mut self,
events: Vec<egui::Event>,
modifiers: egui::Modifiers,
mut modifiers: egui::Modifiers,
response_pos: egui::Pos2,
galley: &egui::Galley,
) {
// i have no idea how CMD works on mac. nor do i have a machine to test it with
// but without this it messes up the key conversion
modifiers.command = false;

let term_mode = self.backend.with_term(|term| *term.mode());
let mut term_modified = false;
for event in events {
match event {
egui::Event::Paste(text) | egui::Event::Text(text) => {
egui::Event::Text(text) => {
self.backend.send(text.into_bytes());
term_modified = true;
}
Expand Down Expand Up @@ -396,6 +407,28 @@ where
term_modified = true;
}
}
egui::Event::Paste(text) => {
if let Some(bytes) = keys::key_to_codes(egui::Key::V, modifiers, term_mode) {
self.backend.send(bytes);
}

if modifiers.shift {
self.backend.send(text.into_bytes());
}
term_modified = true;
}
egui::Event::Copy => {
if let Some(bytes) = keys::key_to_codes(egui::Key::C, modifiers, term_mode) {
self.backend.send(bytes);
}
term_modified = true;
}
egui::Event::Cut => {
if let Some(bytes) = keys::key_to_codes(egui::Key::X, modifiers, term_mode) {
self.backend.send(bytes);
}
term_modified = true;
}
egui::Event::Key {
key, pressed: true, ..
} => {
Expand Down

0 comments on commit 876c858

Please sign in to comment.