MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / handle_pagination_input

Method handle_pagination_input

crates/gitql-cli/src/printer/table_printer.rs:139–186  ·  view source on GitHub ↗
(
        &self,
        current_page: usize,
        number_of_pages: usize,
    )

Source from the content-addressed store, hash-verified

137 }
138
139 fn handle_pagination_input(
140 &self,
141 current_page: usize,
142 number_of_pages: usize,
143 ) -> PaginationInput {
144 loop {
145 if current_page < 2 {
146 println!("Enter 'n' for next page, or 'q' to quit:");
147 } else if current_page == number_of_pages {
148 println!("'p' for previous page, or 'q' to quit:");
149 } else {
150 println!("Enter 'n' for next page, 'p' for previous page, or 'q' to quit:");
151 }
152
153 std::io::Write::flush(&mut std::io::stdout()).expect("flush failed!");
154
155 let mut line = String::new();
156 std::io::stdin()
157 .read_line(&mut line)
158 .expect("Failed to read input");
159
160 let input = line.trim();
161 if input == "q" || input == "n" || input == "p" {
162 match input {
163 "n" => {
164 if current_page < number_of_pages {
165 return PaginationInput::NextPage;
166 } else {
167 println!("Already on the last page");
168 continue;
169 }
170 }
171 "p" => {
172 if current_page > 1 {
173 return PaginationInput::PreviousPage;
174 } else {
175 println!("Already on the first page");
176 continue;
177 }
178 }
179 "q" => return PaginationInput::Quit,
180 _ => unreachable!(),
181 }
182 }
183
184 println!("Invalid input");
185 }
186 }
187}

Callers 1

printMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected