use std::{io, io::Write};
use termion::get_tty;
use crate::error;
use std::io::BufRead;
pub fn position() -> error::Result<(u16, u16)> {
let mut tty = get_tty().unwrap();
let stdin = io::stdin();
tty.write_all(b"\x1B[6n").unwrap();
tty.flush().unwrap();
stdin.lock().read_until(b'[', &mut vec![]).unwrap();
let mut rows = vec![];
stdin.lock().read_until(b';', &mut rows).unwrap();
let mut cols = vec![];
stdin.lock().read_until(b'R', &mut cols).unwrap();
rows.pop();
cols.pop();
let rows = String::from_utf8(rows).unwrap().parse::<u16>().unwrap();
let cols = String::from_utf8(cols).unwrap().parse::<u16>().unwrap();
Ok((cols - 1, rows - 1))
}