Skip to content

Commit

Permalink
Add failing example with regex
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-h-chamberlain committed Apr 12, 2022
1 parent 40db202 commit 329a7a5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ctru-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ futures = "0.3"
time = "0.3.7"
tokio = { version = "1.16", features = ["rt", "time", "sync", "macros"] }
cfg-if = "1.0.0"
lazy_static = "1.4.0"
regex = "1.5.5"

[features]
default = ["romfs"]
Expand Down
41 changes: 41 additions & 0 deletions ctru-rs/examples/regex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use ctru::console::Console;
use ctru::gfx::Gfx;
use ctru::services::apt::Apt;
use ctru::services::hid::{Hid, KeyPad};

use regex::Regex;

fn main() {
ctru::init();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let _console = Console::init(gfx.bottom_screen.borrow_mut());

let re = Regex::new(r"(?P<key>.+)=(?P<value>.+)").unwrap();

for m in ["K1=V1", "no match", "X=Y"] {
if let Some(m) = re.captures(m) {
println!(
"Key = {key:?}, value = {value:?}",
key = m.name("key"),
value = m.name("value")
);
}
}

let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller");
while apt.main_loop() {
//Scan all the inputs. This should be done once for each frame
hid.scan_input();

if hid.keys_down().contains(KeyPad::KEY_START) {
break;
}
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();

// Wait for VBlank
gfx.wait_for_vblank();
}
}

0 comments on commit 329a7a5

Please sign in to comment.