Skip to content

Commit

Permalink
Enter raw mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Flenker committed Mar 31, 2024
1 parent b00c98d commit 0d30c3d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
crossterm = "0.27.0"

This comment has been minimized.

Copy link
@pflenker

pflenker Mar 31, 2024

Owner

This was added when we ran cargo add and specifies the version of crossterm we want to use. Now this looks like we're setting it to 0.27.0, but Cargo uses Semantic Versioning and considers changes to the right-most version number to be non-breaking. If crossterm released 0.27.1 tomorrow, cargo would still install it with this configuration.

3 changes: 3 additions & 0 deletions src/main.rs
@@ -1,10 +1,13 @@
use std::io::{self, Read};
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};

This comment has been minimized.

Copy link
@pflenker

pflenker Mar 31, 2024

Owner

Here, we import our new dependencies the same way we imported the io stuff before.

This comment has been minimized.

Copy link
@sweet2honey

sweet2honey Apr 18, 2024

I found than disable_raw_mode is missing in the blog content.

This comment has been minimized.

Copy link
@pflenker

pflenker Apr 18, 2024

Owner

Thanks, I fixed it now.


fn main() {
enable_raw_mode().unwrap();

This comment has been minimized.

Copy link
@pflenker

pflenker Mar 31, 2024

Owner

We enter raw mode with this method. Bear with me, unwrap() will be explained later!

for b in io::stdin().bytes() {
let c = b.unwrap() as char;
println!("{}", c);
if c == 'q' {
disable_raw_mode().unwrap();

This comment has been minimized.

Copy link
@pflenker

pflenker Mar 31, 2024

Owner

Here we disable raw mode again.
The way it's implemented right now, we only disable raw mode if we exit using q, and we do not disable it if we exit in any other way, which will mess with your terminal. Play around with it to see how much it's going to be messed up.
We'll refactor this soon, though.

Just exit and open your terminal again to get back to sanity.

break;
}
}
Expand Down

0 comments on commit 0d30c3d

Please sign in to comment.