Skip to content

Commit

Permalink
feat: ignore pre-prompt repl warnings
Browse files Browse the repository at this point in the history
Co-authored-by: kurogeek <[email protected]>
Co-authored-by: furioncycle <[email protected]>
Co-authored-by: warren2k <[email protected]>
  • Loading branch information
4 people committed Aug 10, 2024
1 parent 2a5ed84 commit 367389a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 38 deletions.
20 changes: 14 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
};

Expand Down
35 changes: 6 additions & 29 deletions src/app/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![]
}
}
Expand All @@ -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![]
Expand Down Expand Up @@ -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![]
Expand Down Expand Up @@ -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)]
Expand All @@ -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, "");
}
}
4 changes: 1 addition & 3 deletions src/app/state/repl_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ pub(crate) enum ReplSessionExpecting {
acc: String,
expected_result: ExpectedResult,
},
UnexpectedLine {
line: String,
},
UnexpectedLine,
}

impl ReplSessionLive {
Expand Down

0 comments on commit 367389a

Please sign in to comment.