From 2729e77838b2312054251d95fe162e1ee7d092d1 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Sun, 8 Apr 2018 22:51:51 -0700 Subject: [PATCH] Ncurses backend: write mouse command to /dev/tty --- src/backend/curses/n.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/backend/curses/n.rs b/src/backend/curses/n.rs index 3c5225c..c0d8833 100644 --- a/src/backend/curses/n.rs +++ b/src/backend/curses/n.rs @@ -8,6 +8,8 @@ use libc; use std::cell::{Cell, RefCell}; use std::collections::HashMap; use std::ffi::CString; +use std::fs::File; +use std::io; use std::io::{stdout, Write}; use theme::{Color, ColorPair, Effect}; use utf8; @@ -23,6 +25,13 @@ pub struct Backend { event_queue: Vec, } +fn write_to_tty(bytes: &[u8]) -> io::Result<()> { + let mut tty_output = + File::create("/dev/tty").expect("cursive can only run with a tty"); + tty_output.write_all(bytes)?; + Ok(()) +} + impl Backend { pub fn init() -> Box { // Change the locale. @@ -60,7 +69,7 @@ impl Backend { // This asks the terminal to provide us with mouse drag events // (Mouse move when a button is pressed). // Replacing 1002 with 1003 would give us ANY mouse move. - print!("\x1B[?1002h"); + write_to_tty(b"\x1B[?1002h").unwrap(); stdout().flush().expect("could not flush stdout"); let c = Backend { @@ -216,7 +225,7 @@ impl backend::Backend for Backend { } fn finish(&mut self) { - print!("\x1B[?1002l"); + write_to_tty(b"\x1B[?1002l").unwrap(); stdout().flush().expect("could not flush stdout"); ncurses::endwin(); }