Skip to content

Commit

Permalink
newline_before_comment on web & cli
Browse files Browse the repository at this point in the history
  • Loading branch information
sameer committed Apr 8, 2024
1 parent f05ea77 commit a2daff9
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "svg2gcode-cli"
version = "0.0.11"
version = "0.0.12"
authors = ["Sameer Puri <[email protected]>"]
edition = "2021"
description = "Command line interface for svg2gcode"
repository = "https://github.com/sameer/svg2gcode"
license = "MIT"

[dependencies]
svg2gcode = { version = "0.2.2", features = ["serde"]}
svg2gcode = { version = "0.2.3", features = ["serde"]}
env_logger = { version = "0", default-features = false, features = ["atty", "termcolor", "humantime"] }
log = "0"
g-code = "0.4.2"
Expand Down
10 changes: 10 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ struct Opt {
///
/// Useful for streaming g-code
checksums: Option<bool>,
#[structopt(long)]
/// Add a newline character before each comment
///
/// Workaround for parsers that don't accept comments on the same line
newline_before_comment: Option<bool>,
}

fn main() -> io::Result<()> {
Expand Down Expand Up @@ -149,6 +154,10 @@ fn main() -> io::Result<()> {
settings.postprocess.checksums = checksums;
}

if let Some(newline_before_comment) = opt.newline_before_comment {
settings.postprocess.newline_before_comment = newline_before_comment;
}

settings
};

Expand Down Expand Up @@ -296,6 +305,7 @@ fn main() -> io::Result<()> {
FormatOptions {
line_numbers: settings.postprocess.line_numbers,
checksums: settings.postprocess.checksums,
newline_before_comment: settings.postprocess.newline_before_comment,
..Default::default()
},
std::io::stdout(),
Expand Down
4 changes: 2 additions & 2 deletions web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "svg2gcode-web"
version = "0.0.11"
version = "0.0.12"
authors = ["Sameer Puri <[email protected]>"]
edition = "2021"
description = "Convert vector graphics to g-code for pen plotters, laser engravers, and other CNC machines"
Expand All @@ -10,7 +10,7 @@ license = "MIT"

[dependencies]
wasm-bindgen = "0.2"
svg2gcode = { version = "0.2.2", features = ["serde"] }
svg2gcode = { version = "0.2.3", features = ["serde"] }
roxmltree = "0.19"
g-code = "0.4.2"
codespan-reporting = "0.11"
Expand Down
16 changes: 16 additions & 0 deletions web/src/forms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ pub fn settings_form() -> Html {
form.line_numbers = event.target_unchecked_into::<HtmlInputElement>().checked();
});

let on_newline_before_comment_change =
form_dispatch.reduce_mut_callback_with(|form, event: Event| {
form.newline_before_comment =
event.target_unchecked_into::<HtmlInputElement>().checked();
});

let save_onclick = {
let close_ref = close_ref.clone();
let form_state = form_state.clone();
Expand Down Expand Up @@ -170,6 +176,16 @@ pub fn settings_form() -> Html {
/>
</FormGroup>
</div>
<div class="column col-6 col-sm-12">
<FormGroup>
<Checkbox
label="Newline before comments"
desc="Workaround for parsers that don't accept comments on the same line"
checked={form_state.newline_before_comment}
onchange={on_newline_before_comment_change}
/>
</FormGroup>
</div>
</div>
)}
footer={
Expand Down
3 changes: 3 additions & 0 deletions web/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct FormState {
pub end_sequence: Option<Result<String, String>>,
pub checksums: bool,
pub line_numbers: bool,
pub newline_before_comment: bool,
}

impl Default for FormState {
Expand Down Expand Up @@ -80,6 +81,7 @@ impl<'a> TryInto<Settings> for &'a FormState {
postprocess: PostprocessConfig {
checksums: self.checksums,
line_numbers: self.line_numbers,
newline_before_comment: self.newline_before_comment,
},
})
}
Expand All @@ -105,6 +107,7 @@ impl From<&Settings> for FormState {
end_sequence: settings.machine.end_sequence.clone().map(Ok),
checksums: settings.postprocess.checksums,
line_numbers: settings.postprocess.line_numbers,
newline_before_comment: settings.postprocess.newline_before_comment,
}
}
}
Expand Down

0 comments on commit a2daff9

Please sign in to comment.