on master help sign in
Handle switch from crossterm::Result to io::Result
546c8caMichael Davis
helix-term/src/application.rs+4−7
@@ -288,7 +288,7 @@ impl Application {
288
288
289 pub async fn event_loop<S>(&mut self, input_stream: &mut S)
289 pub async fn event_loop<S>(&mut self, input_stream: &mut S)
290 where
290 where
291− S: Stream<Item = crossterm::Result<crossterm::event::Event>> + Unpin,
291+ S: Stream<Item = std::io::Result<crossterm::event::Event>> + Unpin,
292 {
292 {
293 self.render().await;
293 self.render().await;
294
294
@@ -301,7 +301,7 @@ impl Application {
301
301
302 pub async fn event_loop_until_idle<S>(&mut self, input_stream: &mut S) -> bool
302 pub async fn event_loop_until_idle<S>(&mut self, input_stream: &mut S) -> bool
303 where
303 where
304− S: Stream<Item = crossterm::Result<crossterm::event::Event>> + Unpin,
304+ S: Stream<Item = std::io::Result<crossterm::event::Event>> + Unpin,
305 {
305 {
306 loop {
306 loop {
307 if self.editor.should_close() {
307 if self.editor.should_close() {
@@ -615,10 +615,7 @@ impl Application {
615 false
615 false
616 }
616 }
617
617
618− pub async fn handle_terminal_events(
618+ pub async fn handle_terminal_events(&mut self, event: std::io::Result<CrosstermEvent>) {
619− &mut self,
620− event: Result<CrosstermEvent, crossterm::ErrorKind>,
621− ) {
622 let mut cx = crate::compositor::Context {
619 let mut cx = crate::compositor::Context {
623 editor: &mut self.editor,
620 editor: &mut self.editor,
624 jobs: &mut self.jobs,
621 jobs: &mut self.jobs,
@@ -1159,7 +1156,7 @@ impl Application {
1159
1156
1160 pub async fn run<S>(&mut self, input_stream: &mut S) -> Result<i32, Error>
1157 pub async fn run<S>(&mut self, input_stream: &mut S) -> Result<i32, Error>
1161 where
1158 where
1162− S: Stream<Item = crossterm::Result<crossterm::event::Event>> + Unpin,
1159+ S: Stream<Item = std::io::Result<crossterm::event::Event>> + Unpin,
1163 {
1160 {
1164 self.claim_term().await?;
1161 self.claim_term().await?;
1165
1162
helix-tui/src/backend/crossterm.rs+27−31
@@ -201,7 +201,7 @@ where
201 for (x, y, cell) in content {
201 for (x, y, cell) in content {
202 // Move the cursor if the previous location was not (x - 1, y)
202 // Move the cursor if the previous location was not (x - 1, y)
203 if !matches!(last_pos, Some(p) if x == p.0 + 1 && y == p.1) {
203 if !matches!(last_pos, Some(p) if x == p.0 + 1 && y == p.1) {
204− map_error(queue!(self.buffer, MoveTo(x, y)))?;
204+ queue!(self.buffer, MoveTo(x, y))?;
205 }
205 }
206 last_pos = Some((x, y));
206 last_pos = Some((x, y));
207 if cell.modifier != modifier {
207 if cell.modifier != modifier {
@@ -214,12 +214,12 @@ where
214 }
214 }
215 if cell.fg != fg {
215 if cell.fg != fg {
216 let color = CColor::from(cell.fg);
216 let color = CColor::from(cell.fg);
217− map_error(queue!(self.buffer, SetForegroundColor(color)))?;
217+ queue!(self.buffer, SetForegroundColor(color))?;
218 fg = cell.fg;
218 fg = cell.fg;
219 }
219 }
220 if cell.bg != bg {
220 if cell.bg != bg {
221 let color = CColor::from(cell.bg);
221 let color = CColor::from(cell.bg);
222− map_error(queue!(self.buffer, SetBackgroundColor(color)))?;
222+ queue!(self.buffer, SetBackgroundColor(color))?;
223 bg = cell.bg;
223 bg = cell.bg;
224 }
224 }
225
225
@@ -227,7 +227,7 @@ where
227 if self.capabilities.has_extended_underlines {
227 if self.capabilities.has_extended_underlines {
228 if cell.underline_color != underline_color {
228 if cell.underline_color != underline_color {
229 let color = CColor::from(cell.underline_color);
229 let color = CColor::from(cell.underline_color);
230− map_error(queue!(self.buffer, SetUnderlineColor(color)))?;
230+ queue!(self.buffer, SetUnderlineColor(color))?;
231 underline_color = cell.underline_color;
231 underline_color = cell.underline_color;
232 }
232 }
233 } else {
233 } else {
@@ -239,24 +239,24 @@ where
239
239
240 if new_underline_style != underline_style {
240 if new_underline_style != underline_style {
241 let attr = CAttribute::from(new_underline_style);
241 let attr = CAttribute::from(new_underline_style);
242− map_error(queue!(self.buffer, SetAttribute(attr)))?;
242+ queue!(self.buffer, SetAttribute(attr))?;
243 underline_style = new_underline_style;
243 underline_style = new_underline_style;
244 }
244 }
245
245
246− map_error(queue!(self.buffer, Print(&cell.symbol)))?;
246+ queue!(self.buffer, Print(&cell.symbol))?;
247 }
247 }
248
248
249− map_error(queue!(
249+ queue!(
250 self.buffer,
250 self.buffer,
251 SetUnderlineColor(CColor::Reset),
251 SetUnderlineColor(CColor::Reset),
252 SetForegroundColor(CColor::Reset),
252 SetForegroundColor(CColor::Reset),
253 SetBackgroundColor(CColor::Reset),
253 SetBackgroundColor(CColor::Reset),
254 SetAttribute(CAttribute::Reset)
254 SetAttribute(CAttribute::Reset)
255− ))
255+ )
256 }
256 }
257
257
258 fn hide_cursor(&mut self) -> io::Result<()> {
258 fn hide_cursor(&mut self) -> io::Result<()> {
259− map_error(execute!(self.buffer, Hide))
259+ execute!(self.buffer, Hide)
260 }
260 }
261
261
262 fn show_cursor(&mut self, kind: CursorKind) -> io::Result<()> {
262 fn show_cursor(&mut self, kind: CursorKind) -> io::Result<()> {
@@ -266,7 +266,7 @@ where
266 CursorKind::Underline => SetCursorStyle::SteadyUnderScore,
266 CursorKind::Underline => SetCursorStyle::SteadyUnderScore,
267 CursorKind::Hidden => unreachable!(),
267 CursorKind::Hidden => unreachable!(),
268 };
268 };
269− map_error(execute!(self.buffer, Show, shape))
269+ execute!(self.buffer, Show, shape)
270 }
270 }
271
271
272 fn get_cursor(&mut self) -> io::Result<(u16, u16)> {
272 fn get_cursor(&mut self) -> io::Result<(u16, u16)> {
@@ -275,11 +275,11 @@ where
275 }
275 }
276
276
277 fn set_cursor(&mut self, x: u16, y: u16) -> io::Result<()> {
277 fn set_cursor(&mut self, x: u16, y: u16) -> io::Result<()> {
278− map_error(execute!(self.buffer, MoveTo(x, y)))
278+ execute!(self.buffer, MoveTo(x, y))
279 }
279 }
280
280
281 fn clear(&mut self) -> io::Result<()> {
281 fn clear(&mut self) -> io::Result<()> {
282− map_error(execute!(self.buffer, Clear(ClearType::All)))
282+ execute!(self.buffer, Clear(ClearType::All))
283 }
283 }
284
284
285 fn size(&self) -> io::Result<Rect> {
285 fn size(&self) -> io::Result<Rect> {
@@ -294,10 +294,6 @@ where
294 }
294 }
295}
295}
296
296
297−fn map_error(error: crossterm::Result<()>) -> io::Result<()> {
298− error.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))
299−}
300−
301#[derive(Debug)]
297#[derive(Debug)]
302struct ModifierDiff {
298struct ModifierDiff {
303 pub from: Modifier,
299 pub from: Modifier,
@@ -312,48 +308,48 @@ impl ModifierDiff {
312 //use crossterm::Attribute;
308 //use crossterm::Attribute;
313 let removed = self.from - self.to;
309 let removed = self.from - self.to;
314 if removed.contains(Modifier::REVERSED) {
310 if removed.contains(Modifier::REVERSED) {
315− map_error(queue!(w, SetAttribute(CAttribute::NoReverse)))?;
311+ queue!(w, SetAttribute(CAttribute::NoReverse))?;
316 }
312 }
317 if removed.contains(Modifier::BOLD) {
313 if removed.contains(Modifier::BOLD) {
318− map_error(queue!(w, SetAttribute(CAttribute::NormalIntensity)))?;
314+ queue!(w, SetAttribute(CAttribute::NormalIntensity))?;
319 if self.to.contains(Modifier::DIM) {
315 if self.to.contains(Modifier::DIM) {
320− map_error(queue!(w, SetAttribute(CAttribute::Dim)))?;
316+ queue!(w, SetAttribute(CAttribute::Dim))?;
321 }
317 }
322 }
318 }
323 if removed.contains(Modifier::ITALIC) {
319 if removed.contains(Modifier::ITALIC) {
324− map_error(queue!(w, SetAttribute(CAttribute::NoItalic)))?;
320+ queue!(w, SetAttribute(CAttribute::NoItalic))?;
325 }
321 }
326 if removed.contains(Modifier::DIM) {
322 if removed.contains(Modifier::DIM) {
327− map_error(queue!(w, SetAttribute(CAttribute::NormalIntensity)))?;
323+ queue!(w, SetAttribute(CAttribute::NormalIntensity))?;
328 }
324 }
329 if removed.contains(Modifier::CROSSED_OUT) {
325 if removed.contains(Modifier::CROSSED_OUT) {
330− map_error(queue!(w, SetAttribute(CAttribute::NotCrossedOut)))?;
326+ queue!(w, SetAttribute(CAttribute::NotCrossedOut))?;
331 }
327 }
332 if removed.contains(Modifier::SLOW_BLINK) || removed.contains(Modifier::RAPID_BLINK) {
328 if removed.contains(Modifier::SLOW_BLINK) || removed.contains(Modifier::RAPID_BLINK) {
333− map_error(queue!(w, SetAttribute(CAttribute::NoBlink)))?;
329+ queue!(w, SetAttribute(CAttribute::NoBlink))?;
334 }
330 }
335
331
336 let added = self.to - self.from;
332 let added = self.to - self.from;
337 if added.contains(Modifier::REVERSED) {
333 if added.contains(Modifier::REVERSED) {
338− map_error(queue!(w, SetAttribute(CAttribute::Reverse)))?;
334+ queue!(w, SetAttribute(CAttribute::Reverse))?;
339 }
335 }
340 if added.contains(Modifier::BOLD) {
336 if added.contains(Modifier::BOLD) {
341− map_error(queue!(w, SetAttribute(CAttribute::Bold)))?;
337+ queue!(w, SetAttribute(CAttribute::Bold))?;
342 }
338 }
343 if added.contains(Modifier::ITALIC) {
339 if added.contains(Modifier::ITALIC) {
344− map_error(queue!(w, SetAttribute(CAttribute::Italic)))?;
340+ queue!(w, SetAttribute(CAttribute::Italic))?;
345 }
341 }
346 if added.contains(Modifier::DIM) {
342 if added.contains(Modifier::DIM) {
347− map_error(queue!(w, SetAttribute(CAttribute::Dim)))?;
343+ queue!(w, SetAttribute(CAttribute::Dim))?;
348 }
344 }
349 if added.contains(Modifier::CROSSED_OUT) {
345 if added.contains(Modifier::CROSSED_OUT) {
350− map_error(queue!(w, SetAttribute(CAttribute::CrossedOut)))?;
346+ queue!(w, SetAttribute(CAttribute::CrossedOut))?;
351 }
347 }
352 if added.contains(Modifier::SLOW_BLINK) {
348 if added.contains(Modifier::SLOW_BLINK) {
353− map_error(queue!(w, SetAttribute(CAttribute::SlowBlink)))?;
349+ queue!(w, SetAttribute(CAttribute::SlowBlink))?;
354 }
350 }
355 if added.contains(Modifier::RAPID_BLINK) {
351 if added.contains(Modifier::RAPID_BLINK) {
356− map_error(queue!(w, SetAttribute(CAttribute::RapidBlink)))?;
352+ queue!(w, SetAttribute(CAttribute::RapidBlink))?;
357 }
353 }
358
354
359 Ok(())
355 Ok(())
@@ -407,7 +403,7 @@ impl Command for SetUnderlineColor {
407 }
403 }
408
404
409 #[cfg(windows)]
405 #[cfg(windows)]
410− fn execute_winapi(&self) -> crossterm::Result<()> {
406+ fn execute_winapi(&self) -> io::Result<()> {
411 Err(std::io::Error::new(
407 Err(std::io::Error::new(
412 std::io::ErrorKind::Other,
408 std::io::ErrorKind::Other,
413 "SetUnderlineColor not supported by winapi.",
409 "SetUnderlineColor not supported by winapi.",