diff --git a/flake.nix b/flake.nix index ea2e7c7..522a229 100644 --- a/flake.nix +++ b/flake.nix @@ -32,12 +32,20 @@ name = "isolated-nix${postfix}"; paths = [nixDrv]; nativeBuildInputs = [pkgs.makeWrapper]; - postBuild = '' - wrapProgram $out/bin/nix${postfix} \ - --set NIX_CONF_DIR /dev/null \ - --set NIX_USER_CONF_FILES /dev/null \ - --unset NIX_CONFIG - ''; + postBuild = + '' + wrapProgram $out/bin/nix${postfix} \ + --set NIX_CONF_DIR /dev/null \ + --set NIX_USER_CONF_FILES /dev/null \ + '' + + + # Serves as a test for handling early repl warnings + '' + --set NIX_CONFIG " + intentionally-non-existent-option_a = 1 + intentionally-non-existent-option_b = 1 + " + ''; meta.mainProgram = "nix${postfix}"; }; diff --git a/src/app/state.rs b/src/app/state.rs index 30f6319..c15c686 100644 --- a/src/app/state.rs +++ b/src/app/state.rs @@ -137,9 +137,7 @@ impl State { } ReachedEnd => self.next_query(&id)?, UnexpectedCharacter => { - let mut line = cl_progress.progress().to_owned(); - line.push(ch); - session_live.expecting = ReplSessionExpecting::UnexpectedLine { line }; + session_live.expecting = ReplSessionExpecting::UnexpectedLine; vec![] } } @@ -161,9 +159,7 @@ impl State { }; } UnexpectedCharacter => { - let mut line = cl_progress.progress().to_owned(); - line.push(ch); - session_live.expecting = ReplSessionExpecting::UnexpectedLine { line }; + session_live.expecting = ReplSessionExpecting::UnexpectedLine; } }; vec![] @@ -201,11 +197,11 @@ impl State { self.next_query(&id)? } - ReplSessionExpecting::UnexpectedLine { line } => { - line.push(ch); - + ReplSessionExpecting::UnexpectedLine => { if ch == '\n' { - bail!("{id}: unexepcted line: {line}"); + session_live.expecting = ReplSessionExpecting::ClearlineBeforeInitialPrompt { + cl_progress: ClearLineProgress::new(), + }; } vec![] @@ -379,11 +375,6 @@ impl ClearLineProgress { fn new() -> Self { Self(CLEAR_LINE.chars().enumerate().peekable()) } - - fn progress(&mut self) -> &'static str { - let &(i, _) = self.0.peek().unwrap(); - &CLEAR_LINE[..i] - } } #[derive(Debug, Clone)] @@ -392,17 +383,3 @@ enum ClearLineProgressStatus { ReachedEnd, UnexpectedCharacter, } - -#[cfg(test)] -mod test { - use pretty_assertions::assert_eq; - - use super::ClearLineProgress; - - #[test] - fn clear_line_progress() { - let mut cl_progress = ClearLineProgress::new(); - let progress = cl_progress.progress(); - assert_eq!(progress, ""); - } -} diff --git a/src/app/state/repl_state.rs b/src/app/state/repl_state.rs index 37208eb..e8077e3 100644 --- a/src/app/state/repl_state.rs +++ b/src/app/state/repl_state.rs @@ -57,9 +57,7 @@ pub(crate) enum ReplSessionExpecting { acc: String, expected_result: ExpectedResult, }, - UnexpectedLine { - line: String, - }, + UnexpectedLine, } impl ReplSessionLive {