@ -7,6 +7,8 @@ mod prompt;
use line ::Line ;
use prompt ::Prompt ;
use std ::fs ::File ;
use std ::io ::{ Read , Seek , SeekFrom } ;
use windows ::Win32 ::{
Foundation ::{ CloseHandle , HANDLE } ,
System ::Console ,
@ -190,6 +192,38 @@ fn eval(line: String) -> Result<()> {
return Ok ( ( ) ) ;
}
}
"tail" = > {
if parts . len ( ) > 1 {
let fname = parts [ 1 ] ;
let stdout = stdout_handle ( ) ? ;
match File ::options ( ) . read ( true ) . open ( fname ) {
Ok ( mut f ) = > {
_ = f . seek ( SeekFrom ::End ( 0 ) ) ;
let mut one_byte : [ u8 ; 1 ] = [ 0 ; 1 ] ;
let mut buf : Vec < u8 > = vec! [ ] ;
loop {
match f . read ( & mut one_byte ) {
Ok ( n ) = > {
if n = = 1 {
buf . push ( one_byte [ 0 ] ) ;
if let Ok ( s ) = std ::str ::from_utf8 ( & buf ) {
unsafe {
Error ::check ( Console ::WriteConsoleA ( stdout , s . as_bytes ( ) , None , None ) ) ? ;
}
buf . clear ( ) ;
}
}
} ,
Err ( _ ) = > { } ,
}
}
}
Err ( e ) = > { println! ( "failed to open file: {}" , e ) ; }
}
} else {
println! ( "need a file name" ) ;
}
}
"echo" = > {
let rest : Vec < & str > = parts [ 1 .. ] . to_vec ( ) ;
println! ( "{:?}" , rest ) ;
@ -237,8 +271,10 @@ fn main() -> Result<()> {
prompt . print ( ) ? ;
loop {
// debug!("----------------------------------------");
match input . next ( ) ? {
input ::Event ::Key ( event ) = > {
debug ! ( "{}" , event ) ;
if event . down {
continue ;
}
@ -280,6 +316,7 @@ fn main() -> Result<()> {
}
if event . ctrl & & event . code = = key ::D {
debug ! ( "ctrl-d" ) ;
unsafe {
CloseHandle ( stdout ) ;
}
@ -287,6 +324,7 @@ fn main() -> Result<()> {
}
if event . ctrl & & event . code = = key ::J {
debug ! ( "ctrl-j" ) ;
unsafe {
// red bullet
let text = "\x1b[31m\u{2022}\x1b[0m" ;
@ -322,7 +360,7 @@ fn main() -> Result<()> {
continue ;
}
debug! ( "Unhandled Keyboard Event: {:?}" , event . code ) ;
warn! ( "‽ {}" , event ) ;
}
input ::Event ::Left = > {
if line . back ( ) {