basic file handling #7

Merged
mars merged 5 commits from emma/breed:main into main 2023-04-12 21:13:39 +00:00
Contributor
No description provided.
emma added 1 commit 2023-04-12 05:22:53 +00:00
emma added 1 commit 2023-04-12 15:52:29 +00:00
emma added 1 commit 2023-04-12 15:55:45 +00:00
emma requested review from mars 2023-04-12 15:56:08 +00:00
mars requested changes 2023-04-12 16:27:07 +00:00
mars left a comment
Owner

Very, very, very good in general but I had some questions.

Very, very, very good in general but I had some questions.
src/main.rs Outdated
@ -326,12 +335,60 @@ impl State {
}
}
fn write_buffer(&mut self, file: OsString) -> std::result::Result<(), String> {
Owner

This is a very good function, but can we make this function return std::io::Result<()> instead? I think that displaying the error as a string should be the job of whatever command is saving the file.

This is a very good function, but can we make this function return `std::io::Result<()>` instead? I think that displaying the error as a string should be the job of whatever command is saving the file.
emma marked this conversation as resolved
@ -334,0 +361,4 @@
None => return Ok(()),
};
for command in commands.clone().iter() {
Owner

I don't think that splitting up commands into chars before processing like this is the right approach. For example, q! would be treated as two separate commands despite it performing a different operation than q.

I think if we were going to add commands like q! or wq than those should be matched on the corresponding branches. Making write_buffer() as a separate function definitely makes doing that easier, so that was the right call.

I don't think that splitting up commands into chars before processing like this is the right approach. For example, `q!` would be treated as two separate commands despite it performing a different operation than `q`. I think if we were going to add commands like `q!` or `wq` than those should be matched on the corresponding branches. Making `write_buffer()` as a separate function definitely makes doing that easier, so that was the right call.
Author
Contributor

I was planning on making the Iterator peekable, so we could do:

'q' => {
	if commands.peek() == '!' { self.no_save = true; }
	else { self.no_save = false; }
    self.quit = true;
},
I was planning on making the Iterator peekable, so we could do: ```rs 'q' => { if commands.peek() == '!' { self.no_save = true; } else { self.no_save = false; } self.quit = true; }, ```
Author
Contributor

or more likely matching the !, but idk if that would be good or not

or more likely `match`ing the `!`, but idk if that would be good or not
Owner

I think it's much more straight-forward just to match the strings.

I think it's much more straight-forward just to match the strings.
Author
Contributor

Probably. I’ll try that out

Probably. I’ll try that out
@ -334,0 +363,4 @@
for command in commands.clone().iter() {
match command {
'q' => self.quit = true,
Owner

If "q" is given multiple command parts, it still quits without issuing a warning. I'm not sure if this should exit silently even when given more arguments than expected. What do you think?

Edit: how we decide to do this now will help us handle argc differences in the future.

If "q" is given multiple command parts, it still quits without issuing a warning. I'm not sure if this should exit silently even when given more arguments than expected. What do you think? Edit: how we decide to do this now will help us handle argc differences in the future.
Author
Contributor

It definitely should not exit silently, it should error, stating that :q doesn’t take arguments (on its own).

It definitely should not exit silently, it should error, stating that `:q` doesn’t take arguments (on its own).
@ -334,0 +370,4 @@
if let Some(part) = self.file.clone() {
handle = part;
} else {
handle = match command_parts.get(1) {
Owner

Same kind of deal here; what if there is more than one argument?

Same kind of deal here; what if there is more than one argument?
emma added 1 commit 2023-04-12 16:44:46 +00:00
emma added 1 commit 2023-04-12 16:59:01 +00:00
mars merged commit aa013fc422 into main 2023-04-12 21:13:39 +00:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mars/breed#7
No description provided.