Skip to content

Commit a2daff9

Browse files
committed
newline_before_comment on web & cli
1 parent f05ea77 commit a2daff9

File tree

6 files changed

+43
-14
lines changed

6 files changed

+43
-14
lines changed

Cargo.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[package]
22
name = "svg2gcode-cli"
3-
version = "0.0.11"
3+
version = "0.0.12"
44
authors = ["Sameer Puri <[email protected]>"]
55
edition = "2021"
66
description = "Command line interface for svg2gcode"
77
repository = "https://github.com/sameer/svg2gcode"
88
license = "MIT"
99

1010
[dependencies]
11-
svg2gcode = { version = "0.2.2", features = ["serde"]}
11+
svg2gcode = { version = "0.2.3", features = ["serde"]}
1212
env_logger = { version = "0", default-features = false, features = ["atty", "termcolor", "humantime"] }
1313
log = "0"
1414
g-code = "0.4.2"

cli/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ struct Opt {
7979
///
8080
/// Useful for streaming g-code
8181
checksums: Option<bool>,
82+
#[structopt(long)]
83+
/// Add a newline character before each comment
84+
///
85+
/// Workaround for parsers that don't accept comments on the same line
86+
newline_before_comment: Option<bool>,
8287
}
8388

8489
fn main() -> io::Result<()> {
@@ -149,6 +154,10 @@ fn main() -> io::Result<()> {
149154
settings.postprocess.checksums = checksums;
150155
}
151156

157+
if let Some(newline_before_comment) = opt.newline_before_comment {
158+
settings.postprocess.newline_before_comment = newline_before_comment;
159+
}
160+
152161
settings
153162
};
154163

@@ -296,6 +305,7 @@ fn main() -> io::Result<()> {
296305
FormatOptions {
297306
line_numbers: settings.postprocess.line_numbers,
298307
checksums: settings.postprocess.checksums,
308+
newline_before_comment: settings.postprocess.newline_before_comment,
299309
..Default::default()
300310
},
301311
std::io::stdout(),

web/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "svg2gcode-web"
3-
version = "0.0.11"
3+
version = "0.0.12"
44
authors = ["Sameer Puri <[email protected]>"]
55
edition = "2021"
66
description = "Convert vector graphics to g-code for pen plotters, laser engravers, and other CNC machines"
@@ -10,7 +10,7 @@ license = "MIT"
1010

1111
[dependencies]
1212
wasm-bindgen = "0.2"
13-
svg2gcode = { version = "0.2.2", features = ["serde"] }
13+
svg2gcode = { version = "0.2.3", features = ["serde"] }
1414
roxmltree = "0.19"
1515
g-code = "0.4.2"
1616
codespan-reporting = "0.11"

web/src/forms/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ pub fn settings_form() -> Html {
7777
form.line_numbers = event.target_unchecked_into::<HtmlInputElement>().checked();
7878
});
7979

80+
let on_newline_before_comment_change =
81+
form_dispatch.reduce_mut_callback_with(|form, event: Event| {
82+
form.newline_before_comment =
83+
event.target_unchecked_into::<HtmlInputElement>().checked();
84+
});
85+
8086
let save_onclick = {
8187
let close_ref = close_ref.clone();
8288
let form_state = form_state.clone();
@@ -170,6 +176,16 @@ pub fn settings_form() -> Html {
170176
/>
171177
</FormGroup>
172178
</div>
179+
<div class="column col-6 col-sm-12">
180+
<FormGroup>
181+
<Checkbox
182+
label="Newline before comments"
183+
desc="Workaround for parsers that don't accept comments on the same line"
184+
checked={form_state.newline_before_comment}
185+
onchange={on_newline_before_comment_change}
186+
/>
187+
</FormGroup>
188+
</div>
173189
</div>
174190
)}
175191
footer={

web/src/state.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct FormState {
2121
pub end_sequence: Option<Result<String, String>>,
2222
pub checksums: bool,
2323
pub line_numbers: bool,
24+
pub newline_before_comment: bool,
2425
}
2526

2627
impl Default for FormState {
@@ -80,6 +81,7 @@ impl<'a> TryInto<Settings> for &'a FormState {
8081
postprocess: PostprocessConfig {
8182
checksums: self.checksums,
8283
line_numbers: self.line_numbers,
84+
newline_before_comment: self.newline_before_comment,
8385
},
8486
})
8587
}
@@ -105,6 +107,7 @@ impl From<&Settings> for FormState {
105107
end_sequence: settings.machine.end_sequence.clone().map(Ok),
106108
checksums: settings.postprocess.checksums,
107109
line_numbers: settings.postprocess.line_numbers,
110+
newline_before_comment: settings.postprocess.newline_before_comment,
108111
}
109112
}
110113
}

0 commit comments

Comments
 (0)