1 use std::io::{self, stdout, Write}; 2 3 use crossterm::{terminal::*, ExecutableCommand}; 4 5 use super::ui::uicore::DEF_STYLE; 6 7 pub struct TermManager; 8 9 #[allow(dead_code)] 10 impl TermManager { init_term() -> io::Result<()>11 pub fn init_term() -> io::Result<()> { 12 DEF_STYLE.read().unwrap().set_content_style()?; 13 Self::clear_all() 14 } 15 16 #[inline] disable_line_warp() -> io::Result<()>17 pub fn disable_line_warp() -> io::Result<()> { 18 stdout().execute(DisableLineWrap).unwrap().flush() 19 } 20 21 #[inline] enable_line_warp() -> io::Result<()>22 pub fn enable_line_warp() -> io::Result<()> { 23 stdout().execute(EnableLineWrap).unwrap().flush() 24 } 25 26 #[inline] leave_alternate_screen() -> io::Result<()>27 pub fn leave_alternate_screen() -> io::Result<()> { 28 stdout().execute(LeaveAlternateScreen).unwrap().flush() 29 } 30 31 #[inline] enter_alternate_screen() -> io::Result<()>32 pub fn enter_alternate_screen() -> io::Result<()> { 33 stdout().execute(EnterAlternateScreen).unwrap().flush() 34 } 35 36 #[inline] scroll_up(lines: u16) -> io::Result<()>37 pub fn scroll_up(lines: u16) -> io::Result<()> { 38 stdout().execute(ScrollUp(lines)).unwrap().flush() 39 } 40 41 #[inline] scroll_down(lines: u16) -> io::Result<()>42 pub fn scroll_down(lines: u16) -> io::Result<()> { 43 stdout().execute(ScrollDown(lines)).unwrap().flush() 44 } 45 46 #[inline] clear_all() -> io::Result<()>47 pub fn clear_all() -> io::Result<()> { 48 stdout().execute(Clear(ClearType::All)).unwrap().flush() 49 } 50 51 #[inline] clear_purge() -> io::Result<()>52 pub fn clear_purge() -> io::Result<()> { 53 stdout().execute(Clear(ClearType::Purge)).unwrap().flush() 54 } 55 56 #[inline] clear_under_cursor() -> io::Result<()>57 pub fn clear_under_cursor() -> io::Result<()> { 58 stdout() 59 .execute(Clear(ClearType::FromCursorDown)) 60 .unwrap() 61 .flush() 62 } 63 64 #[inline] clear_up_cursor() -> io::Result<()>65 pub fn clear_up_cursor() -> io::Result<()> { 66 stdout() 67 .execute(Clear(ClearType::FromCursorUp)) 68 .unwrap() 69 .flush() 70 } 71 72 #[inline] clear_current_line() -> io::Result<()>73 pub fn clear_current_line() -> io::Result<()> { 74 stdout() 75 .execute(Clear(ClearType::CurrentLine)) 76 .unwrap() 77 .flush() 78 } 79 80 #[inline] clear_until_new_line() -> io::Result<()>81 pub fn clear_until_new_line() -> io::Result<()> { 82 stdout() 83 .execute(Clear(ClearType::UntilNewLine)) 84 .unwrap() 85 .flush() 86 } 87 } 88