Skip to content

Commit 1094d99

Browse files
committed
Merge branch 'v0.2-beta' into 'main'
V0.2.40 beta See merge request mech-lang/notebook!4
2 parents 4a0fec6 + b85cb46 commit 1094d99

File tree

8 files changed

+46
-547
lines changed

8 files changed

+46
-547
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test:cargo:
22
script:
33
- rustup show
4-
- rustup default nightly-2024-10-31
4+
- rustup default nightly-2025-01-15
55
- cargo build

Cargo.toml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mech-notebook"
3-
version = "0.2.22"
3+
version = "0.2.40"
44
authors = ["Corey Montella <corey@mech-lang.org>"]
55
description = "Gui notebook interface for the Mech programming language."
66
documentation = "http://docs.mech-lang.org"
@@ -11,22 +11,16 @@ categories = ["science::robotics", "science", "game-engines", "web-programming"]
1111
license = "Apache-2.0"
1212
readme = "README.md"
1313
edition = "2021"
14-
rust-version = "1.80"
14+
rust-version = "1.84"
1515

1616
[dependencies]
17-
mech-core = "0.2.22"
18-
mech-syntax = "0.2.22"
19-
mech-interpreter = "0.2.22"
20-
egui = "0.29.1"
21-
#egui_extras = { version = "0.28.1"}
22-
eframe = "0.29.1"
23-
24-
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
25-
env_logger = "0.11.5"
17+
mech = {version="0.2.40"}
18+
egui = "0.31.1"
19+
eframe = "0.31.1"
2620

2721
[build-dependencies]
2822
winres = "0.1.12"
2923

3024
[package.metadata.winres]
3125
OriginalFilename = "MECH.EXE"
32-
LegalCopyright = "Copyright © 2024"
26+
LegalCopyright = "Copyright © 2025"

build.rs

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/app.rs

Lines changed: 0 additions & 108 deletions
This file was deleted.

src/bin/mech-notebook.rs

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,30 @@
22
#![allow(rustdoc::missing_crate_level_docs)] // it's an example
33

44
use eframe::egui::*;
5-
use mech_core::*;
6-
use mech_syntax::parser;
7-
use mech_interpreter::*;
5+
use mech::*;
86
use mech_notebook::*;
97
use std::sync::Arc;
108

119
const VERSION: &str = env!("CARGO_PKG_VERSION");
1210

1311
fn main() -> eframe::Result {
14-
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
15-
1612
let icon = icon::load_icon();
1713

18-
1914
let options = eframe::NativeOptions {
20-
viewport: egui::ViewportBuilder::default().with_inner_size([1024.0, 768.0]).with_icon(Arc::new(icon)),
21-
..Default::default()
15+
viewport: egui::ViewportBuilder::default().with_inner_size([1024.0, 768.0]).with_icon(Arc::new(icon)),
16+
..Default::default()
2217
};
2318

24-
// Our application state:
25-
let mut terminal_input = String::new();
19+
let mut input = String::new();
2620
let mut terminal_output = String::new();
2721
let mut text_edit_focus_id = egui::Id::new("terminal_input");
28-
let mut intrp = Interpreter::new();
22+
23+
let id = hash_str("mech-notebook");
24+
let mut intrp = Interpreter::new(id);
25+
let mut repl = MechRepl::from(intrp);
26+
2927
let mut scroll_to_bottom = false;
3028
terminal_output.push_str(&format!("Mech v{}\n",VERSION));
31-
3229
eframe::run_simple_native("Mech Terminal", options, move |ctx, _frame| {
3330

3431
let mut visuals = egui::Visuals::dark();
@@ -38,7 +35,7 @@ fn main() -> eframe::Result {
3835

3936

4037
let mut fonts = FontDefinitions::default();
41-
fonts.font_data.insert("FiraCode-Regular".to_owned(),FontData::from_static(include_bytes!("../../fonts/FiraCode-Regular.ttf")));
38+
fonts.font_data.insert("FiraCode-Regular".to_owned(),Arc::new(FontData::from_static(include_bytes!("../../fonts/FiraCode-Regular.ttf"))));
4239
fonts.families.get_mut(&FontFamily::Proportional).unwrap().insert(0, "FiraCode-Regular".to_owned());
4340
ctx.set_fonts(fonts);
4441

@@ -60,31 +57,43 @@ fn main() -> eframe::Result {
6057
ui.horizontal(|ui| {
6158
ui.label(">:");
6259
let response = ui.add(
63-
egui::TextEdit::singleline(&mut terminal_input)
60+
egui::TextEdit::singleline(&mut input)
6461
.id(text_edit_focus_id)
6562
.frame(false)
6663
);
67-
6864
if response.lost_focus() && ctx.input(|i| i.key_pressed(egui::Key::Enter)) {
69-
terminal_output.push_str(&format!(">: {}\n", terminal_input));
70-
match parser::parse(&terminal_input) {
71-
Ok(tree) => {
72-
let result = intrp.interpret(&tree);
73-
let out_str = match result {
74-
Ok(r) => format!("{}\n",r.pretty_print()),
75-
Err(err) => format!("{:?}", err),
76-
};
77-
terminal_output.push_str(&out_str);
78-
scroll_to_bottom = true;
65+
terminal_output.push_str(&format!(">: {}\n", input));
66+
if input.chars().nth(0) == Some(':') {
67+
match MechRepl::parse_repl_command(&input.as_str()) {
68+
Ok((_, repl_command)) => {
69+
match repl.execute_repl_command(repl_command) {
70+
Ok(output) => {
71+
terminal_output.push_str(&format!("{}\n", output));
72+
}
73+
Err(err) => {
74+
terminal_output.push_str(&format!("{:?}\n", err));
75+
}
76+
}
77+
}
78+
_ => todo!(),
7979
}
80-
Err(err) => {
81-
80+
} else if input.trim() == "" {
81+
//continue;
82+
} else {
83+
let cmd = ReplCommand::Code(vec![("repl".to_string(),MechSourceCode::String(input.clone()))]);
84+
match repl.execute_repl_command(cmd) {
85+
Ok(output) => {
86+
terminal_output.push_str(&format!("{}\n", output));
87+
}
88+
Err(err) => {
89+
terminal_output.push_str(&format!("{:?}\n", err));
90+
}
8291
}
8392
}
84-
terminal_input.clear();
93+
input.clear();
8594
}
8695
response.request_focus();
8796
});
8897
});
8998
})
90-
}
99+
}

0 commit comments

Comments
 (0)