pub tty: bool
}
-enum AdequateTerminal<'a> {
- NoColor(Box<Writer+'a>),
- Color(Box<Terminal<Box<Writer+'a>>+'a>)
+enum AdequateTerminal {
+ NoColor(Box<Writer+'static>),
+ Color(Box<Terminal<Box<Writer+'static>>+'static>)
}
-pub struct Shell<'a> {
- terminal: AdequateTerminal<'a>,
+pub struct Shell {
+ terminal: AdequateTerminal,
config: ShellConfig
}
-pub struct MultiShell<'a> {
- out: Shell<'a>,
- err: Shell<'a>,
+pub struct MultiShell {
+ out: Shell,
+ err: Shell,
verbose: bool
}
pub type Callback<'a> = |&mut MultiShell|:'a -> IoResult<()>;
-impl<'a> MultiShell<'a> {
- pub fn new(out: Shell<'a>, err: Shell<'a>, verbose: bool) -> MultiShell<'a> {
+impl MultiShell {
+ pub fn new(out: Shell, err: Shell, verbose: bool) -> MultiShell {
MultiShell { out: out, err: err, verbose: verbose }
}
- pub fn out(&mut self) -> &mut Shell<'a> {
+ pub fn out(&mut self) -> &mut Shell {
&mut self.out
}
- pub fn err(&mut self) -> &mut Shell<'a> {
+ pub fn err(&mut self) -> &mut Shell {
&mut self.err
}
}
}
-pub type ShellCallback<'a> = |&mut Shell<'a>|:'a -> IoResult<()>;
+pub type ShellCallback<'a> = |&mut Shell|:'a -> IoResult<()>;
-impl<'a> Shell<'a> {
- pub fn create(out: Box<Writer+'a>, config: ShellConfig) -> Shell<'a> {
+impl Shell {
+ pub fn create(out: Box<Writer+'static>, config: ShellConfig) -> Shell {
if config.tty && config.color {
- let term: Option<term::TerminfoTerminal<Box<Writer+'a>>> = Terminal::new(out);
+ let term: Option<term::TerminfoTerminal<Box<Writer+'static>>> = Terminal::new(out);
term.map(|t| Shell {
- terminal: Color(box t as Box<Terminal<Box<Writer+'a>>>),
+ terminal: Color(box t as Box<Terminal<Box<Writer+'static>>>),
config: config
}).unwrap_or_else(|| {
- Shell { terminal: NoColor(box stderr() as Box<Writer+'a>), config: config }
+ Shell { terminal: NoColor(box stderr() as Box<Writer+'static>), config: config }
})
} else {
Shell { terminal: NoColor(out), config: config }
}
}
-impl<'a> Terminal<Box<Writer+'a>> for Shell<'a> {
- fn new(out: Box<Writer+'a>) -> Option<Shell<'a>> {
+impl Terminal<Box<Writer+'static>> for Shell {
+ fn new(out: Box<Writer+'static>) -> Option<Shell> {
Some(Shell {
terminal: NoColor(out),
config: ShellConfig {
}
}
- fn unwrap(self) -> Box<Writer+'a> {
+ fn unwrap(self) -> Box<Writer+'static> {
fail!("Can't unwrap a Shell");
}
- fn get_ref<'b>(&'b self) -> &'b Box<Writer+'a> {
+ fn get_ref<'b>(&'b self) -> &'b Box<Writer+'static> {
match self.terminal {
Color(ref c) => c.get_ref(),
NoColor(ref w) => w
}
}
- fn get_mut<'b>(&'b mut self) -> &'b mut Box<Writer+'a> {
+ fn get_mut<'b>(&'b mut self) -> &'b mut Box<Writer+'static> {
match self.terminal {
Color(ref mut c) => c.get_mut(),
NoColor(ref mut w) => w
}
}
-impl<'a> Writer for Shell<'a> {
+impl Writer for Shell {
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
match self.terminal {
Color(ref mut c) => c.write(buf),
}
}
-pub fn shell(verbose: bool) -> MultiShell<'static> {
+pub fn shell(verbose: bool) -> MultiShell {
let tty = stderr_raw().isatty();
let stderr = box stderr() as Box<Writer>;
pub struct CompileOptions<'a> {
pub update: bool,
pub env: &'a str,
- pub shell: &'a mut MultiShell<'a>,
+ pub shell: &'a mut MultiShell,
pub jobs: Option<uint>,
pub target: Option<&'a str>,
pub dev_deps: bool,
pub struct Config<'a> {
home_path: Path,
- shell: &'a mut MultiShell<'a>,
+ shell: &'a mut MultiShell,
jobs: uint,
target: Option<String>,
linker: Option<String>,
}
fn expand_bar(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
- -> Box<MacResult> {
+ -> Box<MacResult + 'static> {
MacExpr::new(quote_expr!(cx, 1i))
}
"#);
}
fn expand_bar(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
- -> Box<MacResult> {
+ -> Box<MacResult + 'static> {
MacExpr::new(quote_expr!(cx, baz::baz()))
}
"#);
-use support::{ResultTest,Tap,shell_writes};
+use std::io::{MemWriter, IoResult, ChanReader, ChanWriter};
+
+use term::{Terminal, TerminfoTerminal, color};
use hamcrest::{assert_that};
-use std::io::{MemWriter, BufWriter, IoResult};
+
+use support::{ResultTest, Tap, shell_writes};
use cargo::core::shell::{Shell,ShellConfig};
-use term::{Terminal,TerminfoTerminal,color};
fn setup() {
}
-fn writer(buf: &mut [u8]) -> Box<Writer> {
- box BufWriter::new(buf) as Box<Writer>
+fn io_channel() -> (Box<Writer + 'static>, Box<Reader + 'static>) {
+ let (tx, rx) = channel();
+ (box ChanWriter::new(tx), box ChanReader::new(rx))
}
test!(non_tty {
let config = ShellConfig { color: true, verbose: true, tty: false };
- let mut buf: Vec<u8> = Vec::from_elem(9, 0 as u8);
+ let (tx, mut rx) = io_channel();
- Shell::create(writer(buf.as_mut_slice()), config).tap(|shell| {
+ Shell::create(tx, config).tap(|shell| {
shell.say("Hey Alex", color::RED).assert();
- assert_that(buf.as_slice(), shell_writes("Hey Alex\n"));
});
+ assert_that(rx.read_to_end().unwrap().as_slice(),
+ shell_writes("Hey Alex\n"));
})
test!(color_explicitly_disabled {
let config = ShellConfig { color: false, verbose: true, tty: true };
- let mut buf: Vec<u8> = Vec::from_elem(9, 0 as u8);
+ let (tx, mut rx) = io_channel();
- Shell::create(writer(buf.as_mut_slice()), config).tap(|shell| {
+ Shell::create(tx, config).tap(|shell| {
shell.say("Hey Alex", color::RED).assert();
- assert_that(buf.as_slice(), shell_writes("Hey Alex\n"));
});
+ assert_that(rx.read_to_end().unwrap().as_slice(),
+ shell_writes("Hey Alex\n"));
})
test!(colored_shell {
let term: Option<TerminfoTerminal<MemWriter>> =
Terminal::new(MemWriter::new());
if term.is_none() { return }
+ let (tx, mut rx) = io_channel();
let config = ShellConfig { color: true, verbose: true, tty: true };
- let mut buf: Vec<u8> = Vec::from_elem(100, 0 as u8);
- Shell::create(writer(buf.as_mut_slice()), config).tap(|shell| {
+ Shell::create(tx, config).tap(|shell| {
shell.say("Hey Alex", color::RED).assert();
- let buf = buf.as_slice().slice_to(buf.iter().position(|a| *a == 0).unwrap());
- assert_that(buf, shell_writes(colored_output("Hey Alex\n",
- color::RED).assert()));
});
+ assert_that(rx.read_to_end().unwrap().as_slice(),
+ shell_writes(colored_output("Hey Alex\n",
+ color::RED).assert()));
})
fn colored_output<S: Str>(string: S, color: color::Color) -> IoResult<String> {