-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for arbitrary file descriptors on unix
- Loading branch information
1 parent
4d48e58
commit e48ce23
Showing
4 changed files
with
80 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use rustyline::{Behavior, Config, Editor, Result}; | ||
use std::fs::OpenOptions; | ||
use std::io; | ||
|
||
fn main() -> Result<()> { | ||
#![cfg(all(unix, not(target_arch = "wasm32")))] | ||
{ | ||
use std::os::unix::io::IntoRawFd; | ||
|
||
let mut path = String::new(); | ||
io::stdin().read_line(&mut path)?; | ||
let terminal = OpenOptions::new() | ||
.read(true) | ||
.write(true) | ||
.open(path.trim())?; | ||
let terminal_fd = terminal.into_raw_fd(); | ||
let config = Config::builder() | ||
.behavior(Behavior::ArbitraryFileDescriptors { | ||
output: terminal_fd, | ||
input: terminal_fd, | ||
}) | ||
.build(); | ||
let mut rl = Editor::<()>::with_config(config); | ||
loop { | ||
let line = rl.readline("> ")?; | ||
println!("Line: {}", line); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters