init
This commit is contained in:
commit
88b05d196f
6 changed files with 4013 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
3929
Cargo.lock
generated
Normal file
3929
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "cs-project"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
cxx = "1.0.135"
|
||||
eframe = { version = "0.30.0", features = ["wgpu"] }
|
||||
tracing = { version = "0.1.41", features = ["release_max_level_info"] }
|
||||
tracing-subscriber = "0.3.19"
|
43
src/app.rs
Normal file
43
src/app.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
use eframe::egui::{Context, TextEdit, Ui};
|
||||
use eframe::{egui, Frame};
|
||||
use eframe::egui::WidgetType::TextEdit;
|
||||
|
||||
pub struct App {
|
||||
prompt: String,
|
||||
output: String,
|
||||
evaluated: String,
|
||||
}
|
||||
|
||||
impl Default for App {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
prompt: String::new(),
|
||||
output: String::new(),
|
||||
evaluated: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for App {
|
||||
fn update(&mut self, ctx: &Context, frame: &mut Frame) {
|
||||
egui::TopBottomPanel::top("top").show(ctx, |ui| {
|
||||
// TODO: get cursor position from multiline
|
||||
TextEdit::multiline(&mut self.prompt).show(ui);
|
||||
TextEdit::singleline(&mut self.output).show(ui);
|
||||
});
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
|
||||
});
|
||||
// reevaluate if prompt changes
|
||||
if self.evaluated != self.prompt {
|
||||
self.evaluated = self.prompt.clone();
|
||||
self.output = crate::qalculate::eval(self.prompt.clone());
|
||||
}
|
||||
}
|
||||
|
||||
fn btn(&mut self, ui: &mut Ui, label: String, expr: String) {
|
||||
if ui.button(label).clicked() {
|
||||
// TODO: insert expr at cursor position in prompt
|
||||
}
|
||||
}
|
||||
}
|
20
src/main.rs
Normal file
20
src/main.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use eframe::egui;
|
||||
use crate::app::App;
|
||||
|
||||
mod app;
|
||||
mod qalculate;
|
||||
|
||||
fn main() {
|
||||
tracing_subscriber::fmt().with_max_level(tracing::Level::TRACE).init();
|
||||
let no = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default().with_inner_size([600.0, 400.0]),
|
||||
..Default::default()
|
||||
};
|
||||
eframe::run_native(
|
||||
"YAHH",
|
||||
no,
|
||||
Box::new(|cc| {
|
||||
Ok(Box::<App>::default())
|
||||
})
|
||||
).unwrap()
|
||||
}
|
10
src/qalculate.rs
Normal file
10
src/qalculate.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
pub fn eval(expr: String) -> String {
|
||||
let out = std::process::Command::new("qalc")
|
||||
.arg(expr)
|
||||
.output().map_err(|e| e.to_string());
|
||||
|
||||
match out {
|
||||
Err(e) => e,
|
||||
Ok(out) => String::from_utf8_lossy(&out.stdout).into_owned().trim().split('=').last().unwrap().trim().to_string()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue