Skip to content

Commit

Permalink
feat: poc windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Oct 18, 2016
1 parent 8cbeed9 commit 4f6e1a8
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/tty/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ use super::{Width, Height};
/// Note that this returns the size of the actual command window, and
/// not the overall size of the command window buffer
pub fn terminal_size() -> Option<(Width, Height)> {
if let Some((_, csbi)) = get_csbi() {
let w: Width = Width((csbi.srWindow.Right - csbi.srWindow.Left) as u16);
let h: Height = Height((csbi.srWindow.Bottom - csbi.srWindow.Top) as u16);
Some((w, h))
} else {
None
}
}

fn move_cursor_up(n: usize) -> String {

This comment has been minimized.

Copy link
@nabijaczleweli

nabijaczleweli Oct 19, 2016

Contributor

Access doesn't match with unix?

This comment has been minimized.

Copy link
@a8m

a8m Oct 19, 2016

Author Owner

Can you expand more on what you mean by this?

This comment has been minimized.

Copy link
@nabijaczleweli

nabijaczleweli Oct 19, 2016

Contributor

It's not pub, while it is in "unix.rs"

This comment has been minimized.

Copy link
@a8m

a8m Oct 19, 2016

Author Owner

Oh! I see.
Thanks @nabijaczleweli !!

use self::kernel32::SetConsoleCursorPosition;
use self::winapi::COORD;
if let Some((hand, csbi)) = get_csbi() {
unsafe {
SetConsoleCursorPosition(hand, COORD {
X: 0 as i16,
Y: csbi.dwCursorPosition.Y as i16 - n,
});
}
}
"".to_string()
}

fn get_csbi() -> Option<(self::winapi::HANDLE, self::winapi::CONSOLE_SCREEN_BUFFER_INFO)> {
use self::winapi::HANDLE;
use self::kernel32::{GetStdHandle, GetConsoleScreenBufferInfo};
use self::winapi::STD_OUTPUT_HANDLE;
Expand All @@ -28,12 +52,8 @@ pub fn terminal_size() -> Option<(Width, Height)> {
},
dwMaximumWindowSize: zc,
};
let success: bool = unsafe { GetConsoleScreenBufferInfo(hand, &mut csbi) != 0 };
if success {
let w: Width = Width((csbi.srWindow.Right - csbi.srWindow.Left) as u16);
let h: Height = Height((csbi.srWindow.Bottom - csbi.srWindow.Top) as u16);
Some((w, h))
} else {
None
match unsafe { GetConsoleScreenBufferInfo(hand, &mut csbi) } {
0 => None,
_ => Some((hand, csbi)),
}
}

0 comments on commit 4f6e1a8

Please sign in to comment.