Skip to content

Latest commit

 

History

History
97 lines (69 loc) · 2.75 KB

File metadata and controls

97 lines (69 loc) · 2.75 KB

How data in nushell gets printed out via the repl

First off we will note how to print the Block that the parser returns...

  • Add these two lines of code in the file nu-cli/src/util.rs in the eval_source method right after the parse command.
use log::info;
info!("{:?}",block.pipelines);
result = pipeline_data.print(engine_state, stack, false, false);

Printing in nu-protocol

As noted above everything starts with the call to eval_source inside the nu-cli repl loop.

} else if !s.trim().is_empty() {
    info!("eval source: {}", s);

    eval_source(
        engine_state,
        stack,
        s.as_bytes(),
        &format!("entry #{}", entry_num),
        PipelineData::empty(),
    );
}

// On quick running commands everything gets printed from nu_protocol first
// prior to this next line of code firing off...
info!("after eval source and after nu-protocol printing...");
let cmd_duration = start_time.elapsed();

So once eval_source is called it then goes into nu-protocol pipeline_data and there are one of two scenarios which can happen as noted in the eval_source method...

  • pub fn print
  • pub fn print_if_stream

Examples of stream commands include:

  • ls
  • open some csv file

If its not one of these streaming commands then a simple print gets called...

  • This shows table is the main default command of how data gets printed.
  • The table command uses the nu-table crate which calls into tabled.

If you don't want to see the output via table or print_if_stream

simply run one of these commands

$nu | get os-info | debug -r
1 + 3
help if

These are the key points in the code where everything happens...

rg eval_source
rg eval_file
rg evaluate_file
rg write_all_and_flush
rg "print\("

To see how all of this works and/or to add in some debugging / info! lines do this...

in nu-protocol Cargo.toml add this line

log = "0.4"

Then go ahead and add in all of your debugging lines

info!("table hit 03");