summaryrefslogtreecommitdiffstats
path: root/winpty
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2019-03-30 16:48:36 +0000
committerGitHub <noreply@github.com>2019-03-30 16:48:36 +0000
commitcfd025b5289bc305470a96657868c982a2b13bc2 (patch)
tree093b9105c881e28b909e031c46d2054016b643b3 /winpty
parent91aa683bcd060b2ac2f621a388a6448f564d0537 (diff)
Add rustfmt style guidev0.3.0-rc1
Diffstat (limited to 'winpty')
-rw-r--r--winpty/build.rs6
-rw-r--r--winpty/src/windows.rs161
2 files changed, 76 insertions, 91 deletions
diff --git a/winpty/build.rs b/winpty/build.rs
index 90d81803..0ab379b8 100644
--- a/winpty/build.rs
+++ b/winpty/build.rs
@@ -5,8 +5,10 @@ fn main() {
// The working directory for `cargo test` is in the deps folder, not the debug/release root
if cfg!(test) && Path::new("target").exists() {
#[cfg(debug_assertions)]
- copy("../assets/windows/x86_64/winpty-agent.exe", "target/debug/deps/winpty-agent.exe").unwrap();
+ copy("../assets/windows/x86_64/winpty-agent.exe", "target/debug/deps/winpty-agent.exe")
+ .unwrap();
#[cfg(not(debug_assertions))]
- copy("../assets/windows/x86_64/winpty-agent.exe", "target/release/deps/winpty-agent.exe").unwrap();
+ copy("../assets/windows/x86_64/winpty-agent.exe", "target/release/deps/winpty-agent.exe")
+ .unwrap();
}
}
diff --git a/winpty/src/windows.rs b/winpty/src/windows.rs
index 03a91a76..064db2da 100644
--- a/winpty/src/windows.rs
+++ b/winpty/src/windows.rs
@@ -1,9 +1,9 @@
use std::error::Error;
use std::fmt::{self, Display, Formatter};
-use std::path::PathBuf;
-use std::result::Result;
use std::os::windows::io::RawHandle;
+use std::path::PathBuf;
use std::ptr::{null, null_mut};
+use std::result::Result;
use winpty_sys::*;
@@ -166,10 +166,7 @@ impl<'a, 'b> Winpty<'a> {
pub fn conin_name(&mut self) -> PathBuf {
unsafe {
let raw = winpty_conin_name(self.0);
- PathBuf::from(&String::from_utf16_lossy(std::slice::from_raw_parts(
- raw,
- wcslen(raw),
- )))
+ PathBuf::from(&String::from_utf16_lossy(std::slice::from_raw_parts(raw, wcslen(raw))))
}
}
@@ -178,10 +175,7 @@ impl<'a, 'b> Winpty<'a> {
pub fn conout_name(&mut self) -> PathBuf {
unsafe {
let raw = winpty_conout_name(self.0);
- PathBuf::from(&String::from_utf16_lossy(std::slice::from_raw_parts(
- raw,
- wcslen(raw),
- )))
+ PathBuf::from(&String::from_utf16_lossy(std::slice::from_raw_parts(raw, wcslen(raw))))
}
}
@@ -191,10 +185,7 @@ impl<'a, 'b> Winpty<'a> {
pub fn conerr_name(&mut self) -> PathBuf {
unsafe {
let raw = winpty_conerr_name(self.0);
- PathBuf::from(&String::from_utf16_lossy(std::slice::from_raw_parts(
- raw,
- wcslen(raw),
- )))
+ PathBuf::from(&String::from_utf16_lossy(std::slice::from_raw_parts(raw, wcslen(raw))))
}
}
@@ -227,7 +218,12 @@ impl<'a, 'b> Winpty<'a> {
let mut process_list = Vec::with_capacity(count);
unsafe {
- let len = winpty_get_console_process_list(self.0, process_list.as_mut_ptr(), count as i32, &mut err) as usize;
+ let len = winpty_get_console_process_list(
+ self.0,
+ process_list.as_mut_ptr(),
+ count as i32,
+ &mut err,
+ ) as usize;
process_list.set_len(len);
}
@@ -246,10 +242,7 @@ impl<'a, 'b> Winpty<'a> {
/// (https://blogs.msdn.microsoft.com/oldnewthing/20110107-00/?p=11803)
// TODO: Support getting the process and thread handle of the spawned process (Not the agent)
// TODO: Support returning the error from CreateProcess
- pub fn spawn(
- &mut self,
- cfg: &SpawnConfig,
- ) -> Result<(), Err> {
+ pub fn spawn(&mut self, cfg: &SpawnConfig) -> Result<(), Err> {
let mut err = null_mut() as *mut winpty_error_t;
unsafe {
@@ -261,7 +254,9 @@ impl<'a, 'b> Winpty<'a> {
null_mut(), // Create process error
&mut err,
);
- if ok == 0 { return Ok(());}
+ if ok == 0 {
+ return Ok(());
+ }
}
if let Some(err) = check_err(err) {
@@ -354,80 +349,70 @@ mod tests {
#[test]
// Test that we can start a process in winpty
fn spawn_process() {
- let mut winpty = Winpty::open(
- &Config::new(ConfigFlags::empty()).expect("failed to create config")
- ).expect("failed to create winpty instance");
-
- winpty.spawn(
- &SpawnConfig::new(
- SpawnFlags::empty(),
- None,
- Some("cmd"),
- None,
- None
- ).expect("failed to create spawn config")
- ).unwrap();
+ let mut winpty =
+ Winpty::open(&Config::new(ConfigFlags::empty()).expect("failed to create config"))
+ .expect("failed to create winpty instance");
+
+ winpty
+ .spawn(
+ &SpawnConfig::new(SpawnFlags::empty(), None, Some("cmd"), None, None)
+ .expect("failed to create spawn config"),
+ )
+ .unwrap();
}
#[test]
// Test that pipes connected before winpty is spawned can be connected to
fn valid_pipe_connect_before() {
- let mut winpty = Winpty::open(
- &Config::new(ConfigFlags::empty()).expect("failed to create config")
- ).expect("failed to create winpty instance");
+ let mut winpty =
+ Winpty::open(&Config::new(ConfigFlags::empty()).expect("failed to create config"))
+ .expect("failed to create winpty instance");
// Check we can connect to both pipes
- PipeClient::connect_ms(winpty.conout_name(), 1000).expect("failed to connect to conout pipe");
+ PipeClient::connect_ms(winpty.conout_name(), 1000)
+ .expect("failed to connect to conout pipe");
PipeClient::connect_ms(winpty.conin_name(), 1000).expect("failed to connect to conin pipe");
- winpty.spawn(
- &SpawnConfig::new(
- SpawnFlags::empty(),
- None,
- Some("cmd"),
- None,
- None
- ).expect("failed to create spawn config")
- ).unwrap();
+ winpty
+ .spawn(
+ &SpawnConfig::new(SpawnFlags::empty(), None, Some("cmd"), None, None)
+ .expect("failed to create spawn config"),
+ )
+ .unwrap();
}
#[test]
// Test that pipes connected after winpty is spawned can be connected to
fn valid_pipe_connect_after() {
- let mut winpty = Winpty::open(
- &Config::new(ConfigFlags::empty()).expect("failed to create config")
- ).expect("failed to create winpty instance");
-
- winpty.spawn(
- &SpawnConfig::new(
- SpawnFlags::empty(),
- None,
- Some("cmd"),
- None,
- None
- ).expect("failed to create spawn config")
- ).unwrap();
+ let mut winpty =
+ Winpty::open(&Config::new(ConfigFlags::empty()).expect("failed to create config"))
+ .expect("failed to create winpty instance");
+
+ winpty
+ .spawn(
+ &SpawnConfig::new(SpawnFlags::empty(), None, Some("cmd"), None, None)
+ .expect("failed to create spawn config"),
+ )
+ .unwrap();
// Check we can connect to both pipes
- PipeClient::connect_ms(winpty.conout_name(), 1000).expect("failed to connect to conout pipe");
+ PipeClient::connect_ms(winpty.conout_name(), 1000)
+ .expect("failed to connect to conout pipe");
PipeClient::connect_ms(winpty.conin_name(), 1000).expect("failed to connect to conin pipe");
}
#[test]
fn resize() {
- let mut winpty = Winpty::open(
- &Config::new(ConfigFlags::empty()).expect("failed to create config")
- ).expect("failed to create winpty instance");
-
- winpty.spawn(
- &SpawnConfig::new(
- SpawnFlags::empty(),
- None,
- Some("cmd"),
- None,
- None
- ).expect("failed to create spawn config")
- ).unwrap();
+ let mut winpty =
+ Winpty::open(&Config::new(ConfigFlags::empty()).expect("failed to create config"))
+ .expect("failed to create winpty instance");
+
+ winpty
+ .spawn(
+ &SpawnConfig::new(SpawnFlags::empty(), None, Some("cmd"), None, None)
+ .expect("failed to create spawn config"),
+ )
+ .unwrap();
winpty.set_size(1, 1).unwrap();
}
@@ -436,21 +421,19 @@ mod tests {
#[ignore]
// Test that each id returned by cosole_process_list points to an actual process
fn console_process_list_valid() {
- let mut winpty = Winpty::open(
- &Config::new(ConfigFlags::empty()).expect("failed to create config")
- ).expect("failed to create winpty instance");
-
- winpty.spawn(
- &SpawnConfig::new(
- SpawnFlags::empty(),
- None,
- Some("cmd"),
- None,
- None
- ).expect("failed to create spawn config")
- ).unwrap();
-
- let processes = winpty.console_process_list(1000).expect("failed to get console process list");
+ let mut winpty =
+ Winpty::open(&Config::new(ConfigFlags::empty()).expect("failed to create config"))
+ .expect("failed to create winpty instance");
+
+ winpty
+ .spawn(
+ &SpawnConfig::new(SpawnFlags::empty(), None, Some("cmd"), None, None)
+ .expect("failed to create spawn config"),
+ )
+ .unwrap();
+
+ let processes =
+ winpty.console_process_list(1000).expect("failed to get console process list");
// Check that each id is valid
processes.iter().for_each(|id| {
@@ -458,7 +441,7 @@ mod tests {
OpenProcess(
READ_CONTROL, // permissions
false as i32, // inheret
- *id as u32
+ *id as u32,
)
};
assert!(!handle.is_null());