char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
1738b3c
main
1use std:: convert:: Infallible ; 2use std:: io::{ self , IsTerminal }; 3use std:: rc:: Rc ; 4use std:: time:: Instant ; 5 6use avril_core::{ Extension , Op }; 7 8use avril_ext_stdio:: Stdio ; 9 10/// Whether inspected values written to this stream should be colored. 11pub fn colors ( stderr : bool ) ->bool { 12let terminal =if stderr{ 13 io:: stderr (). is_terminal () 14} else { 15 io:: stdout (). is_terminal () 16}; 17 terminal && std:: env:: var_os ( "NO_COLOR" ). is_none_or ( |value| value. is_empty ()) 18} 19 20pub fn init ( stdio : Rc < Stdio >) ->Extension { 21let clear = stdio. clone (); 22let start =Instant :: now (); 23Extension { 24name : "ext:console" , 25dependencies : & [], 26ops : vec! [ 27Op :: new ( "op_console_print" , move |( stderr, text): ( bool , String ) |{ 28 stdio. ( stderr, text) 29}), 30Op :: new ( "op_console_clear" , move |_: () |{ 31if io:: stdout (). is_terminal () { 32 clear. ( false , "\x1b[1;1H\x1b[0J" . into ()) ?; 33} 34Ok ::< _ , io:: Error >(()) 35}), 36Op :: new ( "op_console_colors" , |stderr : bool |{ 37Ok ::< _ , Infallible >( colors ( stderr)) 38}), 39Op :: new ( "op_console_now" , move |_: () |{ 40Ok ::< _ , io:: Error >( start. elapsed (). as_secs_f64 () * 1000.0 ) 41}), 42], 43modules : & [ 44( 45"ext:console/main.js" , 46include_str! ( concat! ( env! ( "OUT_DIR" ), "/main.js" )), 47), 48( 49"ext:console/inspect.js" , 50include_str! ( concat! ( env! ( "OUT_DIR" ), "/inspect.js" )), 51), 52( 53"ext:console/format.js" , 54include_str! ( concat! ( env! ( "OUT_DIR" ), "/format.js" )), 55), 56( 57"ext:console/table.js" , 58include_str! ( concat! ( env! ( "OUT_DIR" ), "/table.js" )), 59), 60], 61entry_point : Some ( "ext:console/main.js" ), 62} 63}