| 1 | sequence!( |
| 2 | /// Switches to the alternate buffer. |
| 3 | /// |
| 4 | /// Use the [`SwitchBufferToNormal`](struct.SwitchBufferToNormal.html) sequence to switch |
| 5 | /// back to the normal buffer. |
| 6 | /// |
| 7 | /// # Examples |
| 8 | /// |
| 9 | /// ```no_run |
| 10 | /// use std::io::{stdout, Write}; |
| 11 | /// use anes::{SwitchBufferToAlternate, SwitchBufferToNormal}; |
| 12 | /// |
| 13 | /// let mut stdout = stdout(); |
| 14 | /// write!(stdout, "{}", SwitchBufferToAlternate); |
| 15 | /// // Your app on alternate screen |
| 16 | /// write!(stdout, "{}", SwitchBufferToNormal); |
| 17 | /// ``` |
| 18 | struct SwitchBufferToAlternate => csi!("?1049h" ) |
| 19 | ); |
| 20 | |
| 21 | sequence!( |
| 22 | /// Switches to the normal buffer. |
| 23 | /// |
| 24 | /// # Examples |
| 25 | /// |
| 26 | /// ```no_run |
| 27 | /// use std::io::{stdout, Write}; |
| 28 | /// use anes::{SwitchBufferToAlternate, SwitchBufferToNormal}; |
| 29 | /// |
| 30 | /// let mut stdout = stdout(); |
| 31 | /// write!(stdout, "{}", SwitchBufferToAlternate); |
| 32 | /// // Your app on alternate screen |
| 33 | /// write!(stdout, "{}", SwitchBufferToNormal); |
| 34 | /// ``` |
| 35 | struct SwitchBufferToNormal => csi!("?1049l" ) |
| 36 | ); |
| 37 | |
| 38 | sequence!( |
| 39 | /// Scrolls up by the given number of rows. |
| 40 | /// |
| 41 | /// # Examples |
| 42 | /// |
| 43 | /// ```no_run |
| 44 | /// use std::io::{stdout, Write}; |
| 45 | /// use anes::ScrollBufferUp; |
| 46 | /// |
| 47 | /// let mut stdout = stdout(); |
| 48 | /// // Scroll up by 5 lines |
| 49 | /// write!(stdout, "{}", ScrollBufferUp(5)); |
| 50 | /// ``` |
| 51 | struct ScrollBufferUp(u16) => |
| 52 | |this, f| write!(f, csi!("{}S" ), this.0) |
| 53 | ); |
| 54 | |
| 55 | sequence!( |
| 56 | /// Scrolls down by the given number of rows. |
| 57 | /// |
| 58 | /// # Examples |
| 59 | /// |
| 60 | /// ```no_run |
| 61 | /// use std::io::{stdout, Write}; |
| 62 | /// use anes::ScrollBufferDown; |
| 63 | /// |
| 64 | /// let mut stdout = stdout(); |
| 65 | /// // Scroll down by 10 lines |
| 66 | /// write!(stdout, "{}", ScrollBufferDown(10)); |
| 67 | /// ``` |
| 68 | struct ScrollBufferDown(u16) => |
| 69 | |this, f| write!(f, csi!("{}T" ), this.0) |
| 70 | ); |
| 71 | |
| 72 | sequence!( |
| 73 | /// Clears part of the line. |
| 74 | /// |
| 75 | /// # Examples |
| 76 | /// |
| 77 | /// ```no_run |
| 78 | /// use std::io::{stdout, Write}; |
| 79 | /// use anes::ClearLine; |
| 80 | /// |
| 81 | /// let mut stdout = stdout(); |
| 82 | /// // Clear the whole line |
| 83 | /// write!(stdout, "{}", ClearLine::All); |
| 84 | /// ``` |
| 85 | enum ClearLine { |
| 86 | /// Clears from the cursor position to end of the line. |
| 87 | Right => csi!("K" ), |
| 88 | /// Clears from the cursor position to beginning of the line. |
| 89 | Left => csi!("1K" ), |
| 90 | /// Clears the whole line. |
| 91 | All => csi!("2K" ), |
| 92 | } |
| 93 | ); |
| 94 | |
| 95 | sequence!( |
| 96 | /// Clears part of the buffer. |
| 97 | /// |
| 98 | /// # Examples |
| 99 | /// |
| 100 | /// ```no_run |
| 101 | /// use std::io::{stdout, Write}; |
| 102 | /// use anes::ClearBuffer; |
| 103 | /// |
| 104 | /// let mut stdout = stdout(); |
| 105 | /// // Clear the entire buffer |
| 106 | /// write!(stdout, "{}", ClearBuffer::All); |
| 107 | /// ``` |
| 108 | enum ClearBuffer { |
| 109 | /// Clears from the cursor position to end of the screen. |
| 110 | Below => csi!("J" ), |
| 111 | /// Clears from the cursor position to beginning of the screen. |
| 112 | Above => csi!("1J" ), |
| 113 | /// Clears the entire buffer. |
| 114 | All => csi!("2J" ), |
| 115 | /// Clears the entire buffer and all saved lines in the scrollback buffer. |
| 116 | SavedLines => csi!("3J" ), |
| 117 | } |
| 118 | ); |
| 119 | |
| 120 | #[cfg (test)] |
| 121 | test_sequences!( |
| 122 | switch_buffer_to_alternate( |
| 123 | SwitchBufferToAlternate => " \x1B[?1049h" , |
| 124 | ), |
| 125 | switch_buffer_to_main( |
| 126 | SwitchBufferToNormal => " \x1B[?1049l" , |
| 127 | ), |
| 128 | scroll_buffer_up( |
| 129 | ScrollBufferUp(10) => " \x1B[10S" , |
| 130 | ), |
| 131 | scroll_buffer_down( |
| 132 | ScrollBufferDown(10) => " \x1B[10T" , |
| 133 | ), |
| 134 | clear_line( |
| 135 | ClearLine::Right => " \x1B[K" , |
| 136 | ClearLine::Left => " \x1B[1K" , |
| 137 | ClearLine::All => " \x1B[2K" , |
| 138 | ), |
| 139 | clear_buffer( |
| 140 | ClearBuffer::Below => " \x1B[J" , |
| 141 | ClearBuffer::Above => " \x1B[1J" , |
| 142 | ClearBuffer::All => " \x1B[2J" , |
| 143 | ClearBuffer::SavedLines => " \x1B[3J" , |
| 144 | ), |
| 145 | ); |
| 146 | |