Skip to content

Commit 7a7b0f3

Browse files
committed
---
yaml --- r: 71967 b: refs/heads/dist-snap c: c2b1534 h: refs/heads/master i: 71965: 2db907e 71963: c38e07f 71959: 4c61849 71951: 85f6573 71935: 1bbe313 v: v3
1 parent 767c02e commit 7a7b0f3

File tree

3 files changed

+49
-35
lines changed

3 files changed

+49
-35
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: b50030718cf28f2a5a81857a26b57442734fe854
10-
refs/heads/dist-snap: d57aaae02525f6e3c7a051fed94966dbbad5e7cf
10+
refs/heads/dist-snap: c2b15345c7aa150212c4121de94e693b3117d618
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librust/rust.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ static commands: &'static [Command<'static>] = &[
6767
usage_line: "build an executable, and run it",
6868
usage_full: UsgStr(
6969
"The run command is an shortcut for the command line \n\
70-
\"rustc <filename> -o <filestem>~ && ./<filestem>~ [<arguments>...]\".\
71-
\n\nUsage:\trust run <filename> [<arguments>...]"
70+
\"rustc <filename> -o <filestem>~ && ./<filestem>~\".\
71+
\n\nUsage:\trust run <filename>"
7272
)
7373
},
7474
Command{
@@ -169,14 +169,14 @@ fn cmd_test(args: &[~str]) -> ValidUsage {
169169

170170
fn cmd_run(args: &[~str]) -> ValidUsage {
171171
match args {
172-
[filename, ..prog_args] => {
172+
[filename] => {
173173
let exec = Path(filename).filestem().unwrap() + "~";
174174
if run::run_program("rustc", [
175175
filename.to_owned(),
176176
~"-o",
177177
exec.to_owned()
178178
]) == 0 {
179-
run::run_program(~"./"+exec, prog_args);
179+
run::run_program(~"./"+exec, []);
180180
}
181181
Valid
182182
}

branches/dist-snap/src/librusti/rusti.rc

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extern mod rustc(vers = "0.7-pre");
2929
extern mod syntax(vers = "0.7-pre");
3030

3131
use core::*;
32-
use core::io::WriterUtil;
32+
use core::io::{ReaderUtil, WriterUtil};
3333
use rustc::driver::{driver, session};
3434
use syntax::{ast, diagnostic};
3535
use syntax::ast_util::*;
@@ -241,23 +241,29 @@ fn compile_crate(src_filename: ~str, binary: ~str) -> Option<bool> {
241241

242242
/// Tries to get a line from rl after outputting a prompt. Returns
243243
/// None if no input was read (e.g. EOF was reached).
244-
fn get_line(prompt: ~str) -> Option<~str> {
245-
let result = unsafe { rl::read(prompt) };
244+
fn get_line(use_rl: bool, prompt: ~str) -> Option<~str> {
245+
if use_rl {
246+
let result = unsafe { rl::read(prompt) };
246247

247-
if result.is_none() {
248-
return None;
248+
match result {
249+
None => None,
250+
Some(line) => {
251+
unsafe { rl::add_history(line) };
252+
Some(line)
253+
}
254+
}
255+
} else {
256+
if io::stdin().eof() {
257+
None
258+
} else {
259+
Some(io::stdin().read_line())
260+
}
249261
}
250-
251-
let line = result.get();
252-
253-
unsafe { rl::add_history(line) };
254-
255-
return Some(line);
256262
}
257263

258264
/// Run a command, e.g. :clear, :exit, etc.
259265
fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
260-
cmd: ~str, args: ~[~str]) -> CmdAction {
266+
cmd: ~str, args: ~[~str], use_rl: bool) -> CmdAction {
261267
let mut action = action_none;
262268
match cmd {
263269
~"exit" => repl.running = false,
@@ -313,7 +319,7 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
313319
let mut multiline_cmd = ~"";
314320
let mut end_multiline = false;
315321
while (!end_multiline) {
316-
match get_line(~"rusti| ") {
322+
match get_line(use_rl, ~"rusti| ") {
317323
None => fail!(~"unterminated multiline command :{ .. :}"),
318324
Some(line) => {
319325
if str::trim(line) == ~":}" {
@@ -333,7 +339,8 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
333339

334340
/// Executes a line of input, which may either be rust code or a
335341
/// :command. Returns a new Repl if it has changed.
336-
fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str)
342+
fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str,
343+
use_rl: bool)
337344
-> Option<Repl> {
338345
if line.starts_with(~":") {
339346
let full = line.substr(1, line.len() - 1);
@@ -349,11 +356,11 @@ fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str)
349356
vec::slice(split, 1, len).to_vec()
350357
} else { ~[] };
351358

352-
match run_cmd(repl, in, out, cmd, args) {
359+
match run_cmd(repl, in, out, cmd, args, use_rl) {
353360
action_none => { }
354361
action_run_line(multiline_cmd) => {
355362
if !multiline_cmd.is_empty() {
356-
return run_line(repl, in, out, multiline_cmd);
363+
return run_line(repl, in, out, multiline_cmd, use_rl);
357364
}
358365
}
359366
}
@@ -386,30 +393,37 @@ pub fn main() {
386393
stmts: ~""
387394
};
388395

389-
io::println("WARNING: The Rust REPL is experimental and may be");
390-
io::println("unstable. If you encounter problems, please use the");
391-
io::println("compiler instead.");
392-
393-
unsafe {
394-
do rl::complete |line, suggest| {
395-
if line.starts_with(":") {
396-
suggest(~":clear");
397-
suggest(~":exit");
398-
suggest(~":help");
399-
suggest(~":load");
396+
let istty = unsafe { libc::isatty(libc::STDIN_FILENO as i32) } != 0;
397+
398+
// only print this stuff if the user is actually typing into rusti
399+
if istty {
400+
io::println("WARNING: The Rust REPL is experimental and may be");
401+
io::println("unstable. If you encounter problems, please use the");
402+
io::println("compiler instead.");
403+
404+
unsafe {
405+
do rl::complete |line, suggest| {
406+
if line.starts_with(":") {
407+
suggest(~":clear");
408+
suggest(~":exit");
409+
suggest(~":help");
410+
suggest(~":load");
411+
}
400412
}
401413
}
402414
}
403415

404416
while repl.running {
405-
match get_line(repl.prompt) {
417+
match get_line(istty, repl.prompt) {
406418
None => break,
407419
Some(line) => {
408420
if line.is_empty() {
409-
io::println(~"()");
421+
if istty {
422+
io::println(~"()");
423+
}
410424
loop;
411425
}
412-
match run_line(&mut repl, in, out, line) {
426+
match run_line(&mut repl, in, out, line, istty) {
413427
Some(new_repl) => repl = new_repl,
414428
None => { }
415429
}

0 commit comments

Comments
 (0)