Skip to content
Snippets Groups Projects
Commit cb085b6e authored by Katsu Kawakami's avatar Katsu Kawakami Committed by kkawakam
Browse files

Remove custom paths to tty modules

Instead of using custom path to module in lib.rs, load modules for different tty
platforms in tty/mod.rs
parent c4317f5b
No related branches found
No related tags found
No related merge requests found
......@@ -29,15 +29,7 @@ mod kill_ring;
pub mod line_buffer;
mod char_iter;
// Depending on the platform, load the correct
// tty modules
#[cfg(unix)]
#[path = "tty/unix.rs"] mod tty;
#[cfg(windows)]
#[path = "tty/windows.rs"] mod tty;
#[path = "tty/common.rs"] mod tty_common;
mod tty;
use std::fmt;
use std::io::{self, Write};
......@@ -48,7 +40,7 @@ use std::sync;
use std::sync::atomic;
use nix::sys::signal;
use encode_unicode::CharExt;
use tty_common::Terminal;
use tty::Terminal;
use completion::Completer;
use consts::{KeyPress, char_to_key_press};
use history::History;
......@@ -642,7 +634,7 @@ fn escape_sequence<R: io::Read>(chars: &mut char_iter::Chars<R>) -> Result<KeyPr
/// It will also handle special inputs in an appropriate fashion
/// (e.g., C-c will exit readline)
#[cfg_attr(feature="clippy", allow(cyclomatic_complexity))]
fn readline_edit<T: tty_common::Terminal>(prompt: &str,
fn readline_edit<T: tty::Terminal>(prompt: &str,
history: &mut History,
completer: Option<&Completer>,
kill_ring: &mut KillRing,
......@@ -908,8 +900,8 @@ impl<'completer> Editor<'completer> {
// if the number of columns is stored here, we need a SIGWINCH handler...
let editor = Editor {
unsupported_term: tty::is_unsupported_term(),
stdin_isatty: tty_common::is_a_tty(libc::STDIN_FILENO),
stdout_isatty: tty_common::is_a_tty(libc::STDOUT_FILENO),
stdin_isatty: tty::is_a_tty(libc::STDIN_FILENO),
stdout_isatty: tty::is_a_tty(libc::STDOUT_FILENO),
history: History::new(),
completer: None,
kill_ring: KillRing::new(60),
......
......@@ -2,6 +2,16 @@
extern crate libc;
use super::Result;
// If on Windows platform import Windows TTY module
// and re-export into mod.rs scope
#[cfg(windows)] mod windows;
#[cfg(windows)] pub use self::windows::*;
// If on Unix platform import Unix TTY module
// and re-export into mod.rs scope
#[cfg(unix)] mod unix;
#[cfg(unix)] pub use self::unix::*;
/// Trait that should be for each TTY/Terminal on various platforms
/// (e.g. unix & windows)
pub trait Terminal {
......
......@@ -4,10 +4,9 @@ extern crate libc;
use std;
use nix::sys::termios;
use nix::errno::Errno;
use super::Result;
use super::tty_common;
use super::error;
use tty_common::Terminal;
use super::Terminal;
use ::Result;
use ::error;
/// Unsupported Terminals that don't support RAW mode
static UNSUPPORTED_TERM: [&'static str; 3] = ["dumb", "cons25", "emacs"];
......@@ -71,12 +70,12 @@ pub struct UnixTerminal {
original_termios: Option<termios::Termios>
}
impl tty_common::Terminal for UnixTerminal {
impl Terminal for UnixTerminal {
/// Enable raw mode for the TERM
fn enable_raw_mode(&mut self) -> Result<()> {
use nix::sys::termios::{BRKINT, CS8, ECHO, ICANON, ICRNL, IEXTEN, INPCK, ISIG, ISTRIP, IXON,
OPOST, VMIN, VTIME};
if !tty_common::is_a_tty(libc::STDIN_FILENO) {
if !super::is_a_tty(libc::STDIN_FILENO) {
return Err(error::ReadlineError::from_errno(Errno::ENOTTY));
}
let original_termios = try!(termios::tcgetattr(libc::STDIN_FILENO));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment