Skip to content

Commit 586efad

Browse files
ChrisDentondjc
authored andcommitted
Remove redundant as_handle helper
windows-sys has long ago switched to matching the standard library's HANDLE type
1 parent be20e85 commit 586efad

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

src/windows_term/mod.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ pub(crate) use self::colors::*;
3636

3737
pub(crate) const DEFAULT_WIDTH: u16 = 79;
3838

39-
pub(crate) fn as_handle(term: &Term) -> HANDLE {
40-
// convert between windows_sys::Win32::Foundation::HANDLE and std::os::windows::raw::HANDLE
41-
term.as_raw_handle() as HANDLE
42-
}
43-
4439
pub(crate) fn is_a_terminal(out: &Term) -> bool {
4540
let (fd, others) = match out.target() {
4641
TermTarget::Stdout => (STD_OUTPUT_HANDLE, [STD_INPUT_HANDLE, STD_ERROR_HANDLE]),
@@ -196,7 +191,7 @@ pub(crate) fn move_cursor_to(out: &Term, x: usize, y: usize) -> io::Result<()> {
196191
if out.is_msys_tty {
197192
return common_term::move_cursor_to(out, x, y);
198193
}
199-
if let Some((hand, _)) = get_console_screen_buffer_info(as_handle(out)) {
194+
if let Some((hand, _)) = get_console_screen_buffer_info(out.as_raw_handle()) {
200195
unsafe {
201196
SetConsoleCursorPosition(
202197
hand,
@@ -215,7 +210,7 @@ pub(crate) fn move_cursor_up(out: &Term, n: usize) -> io::Result<()> {
215210
return common_term::move_cursor_up(out, n);
216211
}
217212

218-
if let Some((_, csbi)) = get_console_screen_buffer_info(as_handle(out)) {
213+
if let Some((_, csbi)) = get_console_screen_buffer_info(out.as_raw_handle()) {
219214
move_cursor_to(out, 0, csbi.dwCursorPosition.Y as usize - n)?;
220215
}
221216
Ok(())
@@ -226,7 +221,7 @@ pub(crate) fn move_cursor_down(out: &Term, n: usize) -> io::Result<()> {
226221
return common_term::move_cursor_down(out, n);
227222
}
228223

229-
if let Some((_, csbi)) = get_console_screen_buffer_info(as_handle(out)) {
224+
if let Some((_, csbi)) = get_console_screen_buffer_info(out.as_raw_handle()) {
230225
move_cursor_to(out, 0, csbi.dwCursorPosition.Y as usize + n)?;
231226
}
232227
Ok(())
@@ -237,7 +232,7 @@ pub(crate) fn move_cursor_left(out: &Term, n: usize) -> io::Result<()> {
237232
return common_term::move_cursor_left(out, n);
238233
}
239234

240-
if let Some((_, csbi)) = get_console_screen_buffer_info(as_handle(out)) {
235+
if let Some((_, csbi)) = get_console_screen_buffer_info(out.as_raw_handle()) {
241236
move_cursor_to(
242237
out,
243238
csbi.dwCursorPosition.X as usize - n,
@@ -252,7 +247,7 @@ pub(crate) fn move_cursor_right(out: &Term, n: usize) -> io::Result<()> {
252247
return common_term::move_cursor_right(out, n);
253248
}
254249

255-
if let Some((_, csbi)) = get_console_screen_buffer_info(as_handle(out)) {
250+
if let Some((_, csbi)) = get_console_screen_buffer_info(out.as_raw_handle()) {
256251
move_cursor_to(
257252
out,
258253
csbi.dwCursorPosition.X as usize + n,
@@ -266,7 +261,7 @@ pub(crate) fn clear_line(out: &Term) -> io::Result<()> {
266261
if out.is_msys_tty {
267262
return common_term::clear_line(out);
268263
}
269-
if let Some((hand, csbi)) = get_console_screen_buffer_info(as_handle(out)) {
264+
if let Some((hand, csbi)) = get_console_screen_buffer_info(out.as_raw_handle()) {
270265
unsafe {
271266
let width = csbi.srWindow.Right - csbi.srWindow.Left;
272267
let pos = COORD {
@@ -286,7 +281,7 @@ pub(crate) fn clear_chars(out: &Term, n: usize) -> io::Result<()> {
286281
if out.is_msys_tty {
287282
return common_term::clear_chars(out, n);
288283
}
289-
if let Some((hand, csbi)) = get_console_screen_buffer_info(as_handle(out)) {
284+
if let Some((hand, csbi)) = get_console_screen_buffer_info(out.as_raw_handle()) {
290285
unsafe {
291286
let width = cmp::min(csbi.dwCursorPosition.X, n as i16);
292287
let pos = COORD {
@@ -306,7 +301,7 @@ pub(crate) fn clear_screen(out: &Term) -> io::Result<()> {
306301
if out.is_msys_tty {
307302
return common_term::clear_screen(out);
308303
}
309-
if let Some((hand, csbi)) = get_console_screen_buffer_info(as_handle(out)) {
304+
if let Some((hand, csbi)) = get_console_screen_buffer_info(out.as_raw_handle()) {
310305
unsafe {
311306
let cells = csbi.dwSize.X as u32 * csbi.dwSize.Y as u32; // as u32, or else this causes stack overflows.
312307
let pos = COORD { X: 0, Y: 0 };
@@ -323,7 +318,7 @@ pub(crate) fn clear_to_end_of_screen(out: &Term) -> io::Result<()> {
323318
if out.is_msys_tty {
324319
return common_term::clear_to_end_of_screen(out);
325320
}
326-
if let Some((hand, csbi)) = get_console_screen_buffer_info(as_handle(out)) {
321+
if let Some((hand, csbi)) = get_console_screen_buffer_info(out.as_raw_handle()) {
327322
unsafe {
328323
let bottom = csbi.srWindow.Right as u32 * csbi.srWindow.Bottom as u32;
329324
let cells = bottom - (csbi.dwCursorPosition.X as u32 * csbi.dwCursorPosition.Y as u32); // as u32, or else this causes stack overflows.
@@ -344,7 +339,7 @@ pub(crate) fn show_cursor(out: &Term) -> io::Result<()> {
344339
if out.is_msys_tty {
345340
return common_term::show_cursor(out);
346341
}
347-
if let Some((hand, mut cci)) = get_console_cursor_info(as_handle(out)) {
342+
if let Some((hand, mut cci)) = get_console_cursor_info(out.as_raw_handle()) {
348343
unsafe {
349344
cci.bVisible = 1;
350345
SetConsoleCursorInfo(hand, &cci);
@@ -357,7 +352,7 @@ pub(crate) fn hide_cursor(out: &Term) -> io::Result<()> {
357352
if out.is_msys_tty {
358353
return common_term::hide_cursor(out);
359354
}
360-
if let Some((hand, mut cci)) = get_console_cursor_info(as_handle(out)) {
355+
if let Some((hand, mut cci)) = get_console_cursor_info(out.as_raw_handle()) {
361356
unsafe {
362357
cci.bVisible = 0;
363358
SetConsoleCursorInfo(hand, &cci);

0 commit comments

Comments
 (0)