Skip to content

Commit 6382220

Browse files
Remove 'Press any key to exit' in basic-rs and basic-cpp templates (#4468)
The basic-rs and basic-cpp templates say "Press any key to exit..." but stdin is line-buffered in cooked mode, so `read(&mut [0u8])` actually blocks until Enter is pressed. Adding a real "any key" handler would require a terminal crate dependency (crossterm, termion, etc.) which is heavy for a starter template. Instead, change the message to "Press Enter to exit..." and use `read_line()` to match the actual behavior. Also removes the unused `Read` import. Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com> Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
1 parent ebea9a4 commit 6382220

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

templates/basic-cpp/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod module_bindings;
22
use module_bindings::*;
33
use std::env;
4-
use std::io::{self, Read};
54

65
use spacetimedb_sdk::{DbContext, Table};
76

@@ -40,7 +39,8 @@ fn main() {
4039
println!("New person: {}", person.name);
4140
});
4241

43-
println!("Press any key to exit...");
44-
45-
let _ = io::stdin().read(&mut [0u8]).unwrap();
42+
// Keep the main thread alive so the connection stays open
43+
loop {
44+
std::thread::sleep(std::time::Duration::from_secs(1));
45+
}
4646
}

templates/basic-rs/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod module_bindings;
22
use module_bindings::*;
33
use std::env;
4-
use std::io::{self, Read};
54

65
use spacetimedb_sdk::{DbContext, Table};
76

@@ -40,7 +39,8 @@ fn main() {
4039
println!("New person: {}", person.name);
4140
});
4241

43-
println!("Press any key to exit...");
44-
45-
let _ = io::stdin().read(&mut [0u8]).unwrap();
42+
// Keep the main thread alive so the connection stays open
43+
loop {
44+
std::thread::sleep(std::time::Duration::from_secs(1));
45+
}
4646
}

0 commit comments

Comments
 (0)