@@ -330,20 +330,25 @@ fn with_str_reader<T>(s: ~str, f: fn(reader) -> T) -> T {
330
330
// Writing
331
331
enum fileflag { append, create, truncate, no_flag, }
332
332
333
+ // What type of writer are we?
334
+ enum writer_type { screen, file }
335
+
333
336
// FIXME (#2004): Seekable really should be orthogonal.
334
337
// FIXME (#2004): eventually u64
335
338
iface writer {
336
339
fn write( v: & [ const u8] ) ;
337
340
fn seek ( int , seek_style ) ;
338
341
fn tell ( ) -> uint ;
339
342
fn flush ( ) -> int ;
343
+ fn get_type ( ) -> writer_type ;
340
344
}
341
345
342
346
impl < T : writer , C > of writer for { base : T , cleanup : C } {
343
347
fn write ( bs : & [ const u8 ] ) { self . base . write ( bs) ; }
344
348
fn seek ( off : int , style : seek_style ) { self . base . seek ( off, style) ; }
345
349
fn tell ( ) -> uint { self . base . tell ( ) }
346
350
fn flush ( ) -> int { self . base . flush ( ) }
351
+ fn get_type ( ) -> writer_type { file }
347
352
}
348
353
349
354
impl of writer for * libc:: FILE {
@@ -364,6 +369,13 @@ impl of writer for *libc::FILE {
364
369
}
365
370
fn tell ( ) -> uint { libc:: ftell ( self ) as uint }
366
371
fn flush ( ) -> int { libc:: fflush ( self ) as int }
372
+ fn get_type ( ) -> writer_type {
373
+ let fd = libc:: fileno ( self ) ;
374
+ if libc:: isatty ( fd) == 0 {
375
+ ret file;
376
+ }
377
+ ret screen;
378
+ }
367
379
}
368
380
369
381
fn FILE_writer ( f : * libc:: FILE , cleanup : bool ) -> writer {
@@ -399,6 +411,9 @@ impl of writer for fd_t {
399
411
fail;
400
412
}
401
413
fn flush ( ) -> int { 0 }
414
+ fn get_type ( ) -> writer_type {
415
+ if libc:: isatty ( self ) == 0 { file } else { screen }
416
+ }
402
417
}
403
418
404
419
class fd_res {
@@ -646,6 +661,7 @@ impl of writer for mem_buffer {
646
661
}
647
662
fn tell() -> uint { self.pos }
648
663
fn flush() -> int { 0 }
664
+ fn get_type() -> writer_type { ret file }
649
665
}
650
666
651
667
fn mem_buffer() -> mem_buffer {
0 commit comments