This commit is contained in:
2026-01-23 11:37:13 -07:00
parent 2076c42c80
commit 1923bbe674
2 changed files with 12 additions and 24 deletions

View File

@@ -81,7 +81,7 @@ impl Grid {
/// Save file to `path` as a csv. Path with have `csv` appended to it if it /// Save file to `path` as a csv. Path with have `csv` appended to it if it
/// does not already have the extension. /// does not already have the extension.
pub fn save_to(&mut self, path: impl Into<PathBuf>) -> std::io::Result<()> { pub fn save_to(&mut self, path: impl Into<PathBuf>) -> std::io::Result<()> {
let path = path.into(); let mut path = path.into();
let resolve_values; let resolve_values;
@@ -94,13 +94,15 @@ impl Grid {
resolve_values = false; resolve_values = false;
} }
_ => { _ => {
resolve_values = false; // File as an extension but isn't ours.
// path.add_extension(CUSTOM_EXT); // Save as csv-like
resolve_values = true;
} }
}, },
None => { None => {
// File has no extension. Save it as our file type
resolve_values = false; resolve_values = false;
// path.add_extension(CUSTOM_EXT); path.add_extension(CUSTOM_EXT);
} }
} }
@@ -543,8 +545,8 @@ fn saving_neoscim() {
assert_eq!(cell.escaped_csv_string(), "=A10^2"); assert_eq!(cell.escaped_csv_string(), "=A10^2");
// set saving the file // set saving the file
let filename= "/tmp/file.neoscim"; let filename = format!("/tmp/file.{CUSTOM_EXT}");
app.grid.save_to(filename).expect("This will only work on linux systems"); app.grid.save_to(&filename).expect("This will only work on linux systems");
let mut file = fs::OpenOptions::new().read(true).open(filename).expect("Just wrote the file"); let mut file = fs::OpenOptions::new().read(true).open(filename).expect("Just wrote the file");
let mut buf = String::new(); let mut buf = String::new();
file.read_to_string(&mut buf).expect("Just opened the file"); file.read_to_string(&mut buf).expect("Just opened the file");

View File

@@ -70,25 +70,11 @@ impl Mode {
"w" => { "w" => {
// first try the passed argument as file // first try the passed argument as file
if let Some(arg) = args.get(1) { if let Some(arg) = args.get(1) {
let mut path: PathBuf = arg.into(); let path: PathBuf = arg.into();
match path.extension() {
Some(s) => {
match s.to_str() {
// leave the file alone, it already has
// a valid extension
Some(CSV_EXT) | Some(CUSTOM_EXT) => {}
_ => {
path.add_extension(CUSTOM_EXT);
}
}
}
None => {
path.add_extension(CUSTOM_EXT);
}
};
// TODO Check if the file exists, but the program wasn't opened with it. We might be accidentally overwriting something else. // TODO Check if the file we are writing to exists, since
// let mut file = fs::OpenOptions::new().write(true).append(false).truncate(true).create(true).open(path)?; // this code path already knows that we are writing to a new file.
// We might be accidentally overwriting something else.
if let Err(e) = app.grid.save_to(&path) { if let Err(e) = app.grid.save_to(&path) {
app.msg = StatusMessage::error(format!("{e}")); app.msg = StatusMessage::error(format!("{e}"));