Skip to content

Commit 2e41e88

Browse files
committed
0.7.0
1 parent 15ecfc4 commit 2e41e88

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

src/repl.rs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,10 +1345,10 @@ impl ReplState {
13451345
_ => XMode::Verbose,
13461346
};
13471347
}
1348-
if let Some(v) = cfg.get("precision") {
1349-
if let Ok(n) = v.parse::<u32>() {
1350-
state.precision = Some(n.min(32));
1351-
}
1348+
if let Some(v) = cfg.get("precision")
1349+
&& let Ok(n) = v.parse::<u32>()
1350+
{
1351+
state.precision = Some(n.min(32));
13521352
}
13531353
if let Some(v) = cfg.get("numbered_prompts") {
13541354
state.numbered_prompts = matches!(v.to_lowercase().as_str(), "on" | "true" | "1");
@@ -1391,17 +1391,17 @@ impl ReplState {
13911391
}
13921392

13931393
// Shell escape :!! (capture) and :! (inherit)
1394-
if command.starts_with("!!") {
1395-
let shell_cmd = command[2..].trim_start();
1394+
if let Some(stripped) = command.strip_prefix("!!") {
1395+
let shell_cmd = stripped.trim_start();
13961396
if shell_cmd.is_empty() {
13971397
println!("usage: :!! <cmd>");
13981398
} else {
13991399
run_shell(shell_cmd, true);
14001400
}
14011401
return Ok(false);
14021402
}
1403-
if command.starts_with('!') {
1404-
let shell_cmd = command[1..].trim_start();
1403+
if let Some(stripped) = command.strip_prefix('!') {
1404+
let shell_cmd = stripped.trim_start();
14051405
if shell_cmd.is_empty() {
14061406
println!("usage: :! <cmd>");
14071407
} else {
@@ -1598,10 +1598,8 @@ impl ReplState {
15981598
);
15991599
}
16001600
}
1601-
} else {
1602-
if let Ok(cwd) = std::env::current_dir() {
1603-
println!("{}", cwd.display());
1604-
}
1601+
} else if let Ok(cwd) = std::env::current_dir() {
1602+
println!("{}", cwd.display());
16051603
}
16061604
return Ok(false);
16071605
}
@@ -1681,7 +1679,7 @@ impl ReplState {
16811679
let path = parts
16821680
.next()
16831681
.map(PathBuf::from)
1684-
.or_else(|| std::env::current_dir().ok().map(PathBuf::from));
1682+
.or_else(|| std::env::current_dir().ok());
16851683
if let Some(p) = path {
16861684
if p.is_absolute() {
16871685
self.bookmarks.insert(name.to_string(), p.clone());
@@ -2126,20 +2124,18 @@ impl ReplState {
21262124
path.display()
21272125
);
21282126
}
2127+
} else if selected.is_empty() {
2128+
println!("\x1b[2m(no history)\x1b[0m");
21292129
} else {
2130-
if selected.is_empty() {
2131-
println!("\x1b[2m(no history)\x1b[0m");
2132-
} else {
2133-
for (num, entry) in selected {
2134-
let first_line = entry.lines().next().unwrap_or(entry.as_str());
2135-
let is_multiline = entry.contains('\n');
2136-
if is_multiline {
2137-
println!(
2138-
"\x1b[2m[{num:>4}]\x1b[0m {first_line} \x1b[2m(...)\x1b[0m"
2139-
);
2140-
} else {
2141-
println!("\x1b[2m[{num:>4}]\x1b[0m {entry}");
2142-
}
2130+
for (num, entry) in selected {
2131+
let first_line = entry.lines().next().unwrap_or(entry.as_str());
2132+
let is_multiline = entry.contains('\n');
2133+
if is_multiline {
2134+
println!(
2135+
"\x1b[2m[{num:>4}]\x1b[0m {first_line} \x1b[2m(...)\x1b[0m"
2136+
);
2137+
} else {
2138+
println!("\x1b[2m[{num:>4}]\x1b[0m {entry}");
21432139
}
21442140
}
21452141
}
@@ -2794,10 +2790,10 @@ fn run_shell(cmd: &str, capture: bool) {
27942790
Ok(out) => {
27952791
let _ = std::io::stdout().write_all(&out.stdout);
27962792
let _ = std::io::stderr().write_all(&out.stderr);
2797-
if let Some(code) = out.status.code() {
2798-
if code != 0 {
2799-
println!("\x1b[2m[exit {code}]\x1b[0m");
2800-
}
2793+
if let Some(code) = out.status.code()
2794+
&& code != 0
2795+
{
2796+
println!("\x1b[2m[exit {code}]\x1b[0m");
28012797
}
28022798
}
28032799
Err(e) => {

tests/repl_meta_commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn repl_history_f_file() {
187187
.and_then(|mut f| f.read_to_string(&mut buf))
188188
.is_ok()
189189
{
190-
assert!(buf.is_empty() || buf.contains('\n') || buf.len() > 0);
190+
assert!(buf.is_empty() || buf.contains('\n'));
191191
}
192192
let _ = std::fs::remove_file(&file);
193193
}

0 commit comments

Comments
 (0)