|
1 | 1 | use console::{Console, ConsoleTextKind}; |
2 | 2 | use crossbeam_channel::{Receiver, Sender}; |
3 | 3 | use ctrlc; |
| 4 | +use getch::Getch; |
4 | 5 | use memmap::Mmap; |
5 | 6 | use pipeline::{Pipeline, PipelineInfo}; |
6 | 7 | use pipeline_matcher::PathMatch; |
7 | 8 | use std::fs::{self, File}; |
8 | | -use std::io; |
9 | 9 | use std::io::{Error, Write}; |
10 | 10 | use std::ops::Deref; |
11 | 11 | use std::time::{Duration, Instant}; |
@@ -113,38 +113,24 @@ impl PipelineReplacer { |
113 | 113 | "Replace keyword? ( Yes[Y], No[N], All[A], Quit[Q] ):", |
114 | 114 | ); |
115 | 115 | self.console.flush(); |
116 | | - let mut buf = String::new(); |
117 | | - io::stdin().read_line(&mut buf).unwrap(); |
118 | | - match buf.trim().to_lowercase().as_ref() { |
119 | | - "y" => { |
| 116 | + let getch = Getch::new(); |
| 117 | + let key = getch.getch()?; |
| 118 | + let key = char::from(key); |
| 119 | + self.console.write(ConsoleTextKind::Other, &format!("{}\n", key)); |
| 120 | + match key.to_ascii_lowercase() { |
| 121 | + 'y' => { |
120 | 122 | do_replace = true; |
121 | 123 | break; |
122 | 124 | } |
123 | | - "yes" => { |
124 | | - do_replace = true; |
125 | | - break; |
126 | | - } |
127 | | - "n" => { |
128 | | - do_replace = false; |
129 | | - break; |
130 | | - } |
131 | | - "no" => { |
| 125 | + 'n' => { |
132 | 126 | do_replace = false; |
133 | 127 | break; |
134 | 128 | } |
135 | | - "a" => { |
| 129 | + 'a' => { |
136 | 130 | self.all_replace = true; |
137 | 131 | break; |
138 | 132 | } |
139 | | - "all" => { |
140 | | - self.all_replace = true; |
141 | | - break; |
142 | | - } |
143 | | - "q" => { |
144 | | - let _ = tmpfile.close(); |
145 | | - exit(0, &mut self.console); |
146 | | - } |
147 | | - "quit" => { |
| 133 | + 'q' => { |
148 | 134 | let _ = tmpfile.close(); |
149 | 135 | exit(0, &mut self.console); |
150 | 136 | } |
|
0 commit comments