Skip to content

Commit

Permalink
Fix Ctrl+D extra keypress (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielzgtg authored Jan 12, 2025
1 parent f70656f commit a966613
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ pub(super) fn run_tty(output_mode: OutputMode) -> std::io::Result<()> {
println!("Type .help for help.");

let prompt = SQLPrompt {};
let mut is_exit_cmd = false;
let mut prev_was_ctrl_c = false;
let mut scratch = String::with_capacity(1024);

loop {
let sig = line_editor.read_line(&prompt);
match sig {
Ok(Signal::Success(buffer)) => {
is_exit_cmd = false;
prev_was_ctrl_c = false;
match buffer.as_str() {
special_cmd if buffer.starts_with('.') => {
let cmd: PolarsCommand = special_cmd
Expand Down Expand Up @@ -194,15 +194,18 @@ pub(super) fn run_tty(output_mode: OutputMode) -> std::io::Result<()> {
},
}
},
Ok(Signal::CtrlD) | Ok(Signal::CtrlC) => {
if is_exit_cmd {
Ok(Signal::CtrlC) => {
if prev_was_ctrl_c {
break;
} else {
is_exit_cmd = true;
prev_was_ctrl_c = true;
}
},
Ok(Signal::CtrlD) => {
break;
},
_ => {
is_exit_cmd = false;
prev_was_ctrl_c = false;
},
}
}
Expand Down

0 comments on commit a966613

Please sign in to comment.