diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-03-21 00:31:53 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-03-21 00:31:53 -0500 |
commit | 0297b0a14b7b0ff7cbdcda7c967e095089ce65cd (patch) | |
tree | 86c590b0841461e2995eb3a3a17d363637ada395 /src/ios.rs | |
parent | e2a09fb5c6d822cf46a28ca371a7c426994e31c8 (diff) | |
download | rust-term-0297b0a14b7b0ff7cbdcda7c967e095089ce65cd.tar.gz rust-term-0297b0a14b7b0ff7cbdcda7c967e095089ce65cd.zip |
abstract this out
Diffstat (limited to 'src/ios.rs')
-rw-r--r-- | src/ios.rs | 21 |
1 files changed, 5 insertions, 16 deletions
@@ -1,4 +1,5 @@ use core::libc::{c_int,c_uint}; +use util::guard; pub fn cooked () -> int { unsafe { c::cooked() as int } @@ -17,8 +18,10 @@ pub fn echo (enable: bool) -> int { } pub fn preserve<T> (body: &fn () -> T) -> T { - let _guard = PreserveTermios(); - body() + let orig = unsafe { c::get() }; + do guard(|| { unsafe { c::set(orig) } }) { + body() + } } pub fn isatty() -> bool { @@ -36,20 +39,6 @@ pub fn size() -> (uint, uint) { enum struct_termios {} -struct PreserveTermios { - priv state: *struct_termios, -} - -fn PreserveTermios () -> ~PreserveTermios { - ~PreserveTermios { state: unsafe { c::get() } } -} - -impl Drop for PreserveTermios { - fn finalize (&self) { - unsafe { c::set(self.state) } - } -} - #[link_name = "termios_wrapper"] extern mod c { fn cooked () -> c_int; |