I’m stuck on Stage #EI0
This stemmed from #RH7 . I tried pwd just to verify
Here are my logs:
remote: [tester::#EI0] Running tests for Stage #EI0 (Navigation - The pwd builtin)
remote: [tester::#EI0] Running ./your_program.sh
remote: [your-program] $ type pwdj
remote: [tester::#EI0] ^ Line does not match expected value.
remote: [tester::#EI0] Expected: "$ type pwd"
remote: [tester::#EI0] Received: "$ type pwdj"
remote: [tester::#EI0] Assertion failed.
remote: [tester::#EI0] Test failed
And here’s a snippet of my relevant code when I press enter.
I have no idea from where the extra ‘j’ is coming from.
This runs perfectly fine locally.
I am using Crossterm and here’s my complete solution: GitHub - sandipndev-space/shell-rust
KeyCode::Enter => {
print!("\r\n");
io::stdout().flush()?;
let shell_line = line.trim_end();
if !shell_line.is_empty() {
history::add_entry(shell_line.to_string());
run_shell_line(shell_line)?;
}
line.clear();
// Drain any pending input bytes
while event::poll(std::time::Duration::from_millis(0))? {
if let Event::Key(_) = event::read()? {}
}
print_prompt(&mut stdout, &line)?;
}
I FIXED IT MYSELF
Apparently the tester uses Control + J instead of Enter to test.
Codecrafters should add this to docs.
1 Like
Hey @sandipndev , looks like crossterm maps newline (0xA) to Ctrl+J in raw mode:
event
}
})
}),
}
}
}
b'\r' => Ok(Some(InternalEvent::Event(Event::Key(
KeyCode::Enter.into(),
)))),
// Issue #371: \n = 0xA, which is also the keycode for Ctrl+J. The only reason we get
// newlines as input is because the terminal converts \r into \n for us. When we
// enter raw mode, we disable that, so \n no longer has any meaning - it's better to
// use Ctrl+J. Waiting to handle it here means it gets picked up later
b'\n' if !crate::terminal::sys::is_raw_mode_enabled() => Ok(Some(InternalEvent::Event(
Event::Key(KeyCode::Enter.into()),
))),
b'\t' => Ok(Some(InternalEvent::Event(Event::Key(KeyCode::Tab.into())))),
b'\x7F' => Ok(Some(InternalEvent::Event(Event::Key(
KeyCode::Backspace.into(),
)))),
// newlines as input is because the terminal converts \r into \n for us. When we
// enter raw mode, we disable that, so \n no longer has any meaning - it's better to
// use Ctrl+J. Waiting to handle it here means it gets picked up later
b'\n' if !crate::terminal::sys::is_raw_mode_enabled() => Ok(Some(InternalEvent::Event(
Event::Key(KeyCode::Enter.into()),
))),
b'\t' => Ok(Some(InternalEvent::Event(Event::Key(KeyCode::Tab.into())))),
b'\x7F' => Ok(Some(InternalEvent::Event(Event::Key(
KeyCode::Backspace.into(),
)))),
c @ b'\x01'..=b'\x1A' => Ok(Some(InternalEvent::Event(Event::Key(KeyEvent::new(
KeyCode::Char((c - 0x1 + b'a') as char),
KeyModifiers::CONTROL,
))))),
c @ b'\x1C'..=b'\x1F' => Ok(Some(InternalEvent::Event(Event::Key(KeyEvent::new(
KeyCode::Char((c - 0x1C + b'4') as char),
KeyModifiers::CONTROL,
))))),
b'\0' => Ok(Some(InternalEvent::Event(Event::Key(KeyEvent::new(
KeyCode::Char(' '),
KeyModifiers::CONTROL,
1 Like
Ohhh than’s a great find. Thanks - it was me who complected it that means!
1 Like