remove gui
This commit is contained in:
4097
Cargo.lock
generated
4097
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -2,8 +2,3 @@
|
|||||||
name = "Omelt"
|
name = "Omelt"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
eframe = "0.31.1"
|
|
||||||
egui = "0.21.0"
|
|
||||||
egui_extras = "0.31.1"
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ cargo run
|
|||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
```
|
```
|
||||||
<input.oeuf> To open file with gui.
|
|
||||||
--compress , -c <intput> [<output>] To compress a file.
|
--compress , -c <intput> [<output>] To compress a file.
|
||||||
--uncompress, -u <intput> [<output>] To uncompress a file.
|
--uncompress, -u <intput> [<output>] To uncompress a file.
|
||||||
--print , -p <input> To print a file compressed.
|
--print , -p <input> To print a file compressed.
|
||||||
|
|||||||
87
src/gui.rs
87
src/gui.rs
@@ -1,87 +0,0 @@
|
|||||||
use eframe::egui::{self};
|
|
||||||
use std::fs::File;
|
|
||||||
|
|
||||||
use crate::read_and_write;
|
|
||||||
use read_and_write::{is_valid_file, save_action, string_translate};
|
|
||||||
|
|
||||||
pub struct Omelt {
|
|
||||||
file_name: String,
|
|
||||||
text: String,
|
|
||||||
file: File,
|
|
||||||
save_short: KeyboardShortcut,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Omelt {
|
|
||||||
pub fn new(file_name: &str, file: File) -> Self {
|
|
||||||
let mut out = Self {
|
|
||||||
file_name: file_name.to_owned(),
|
|
||||||
text: "".to_owned(),
|
|
||||||
file: file,
|
|
||||||
save_short: KeyboardShortcut::new(
|
|
||||||
egui::Key::S,
|
|
||||||
Modifiers {
|
|
||||||
alt: false,
|
|
||||||
ctrl: true,
|
|
||||||
shift: false,
|
|
||||||
mac_cmd: false,
|
|
||||||
command: true,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
};
|
|
||||||
out.update_txt();
|
|
||||||
out
|
|
||||||
}
|
|
||||||
pub fn update_txt(&mut self) {
|
|
||||||
if is_valid_file(&mut self.file) {
|
|
||||||
self.text = string_translate(&mut self.file);
|
|
||||||
} else {
|
|
||||||
println!("File is not valid");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl eframe::App for Omelt {
|
|
||||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
||||||
ctx.input(|i| {
|
|
||||||
if self.save_short.matches(i) {
|
|
||||||
let _ = save_action(&self.text, &mut self.file);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
ui.heading(&self.file_name);
|
|
||||||
if ui.add(egui::Button::new("Save")).clicked() {
|
|
||||||
let _ = self.file.set_len(0);
|
|
||||||
let _ = save_action(&self.text, &mut self.file);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
|
||||||
//let visible_text = self.text.lines().take(100).collect::<Vec<_>>().join("\n");
|
|
||||||
ui.add_sized(
|
|
||||||
ui.available_size(),
|
|
||||||
egui::TextEdit::multiline(&mut self.text).lock_focus(true),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------ShortCuts-----------------------
|
|
||||||
|
|
||||||
use egui::Modifiers;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
struct KeyboardShortcut {
|
|
||||||
key: egui::Key,
|
|
||||||
modifiers: Modifiers,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl KeyboardShortcut {
|
|
||||||
fn new(key: egui::Key, modifiers: Modifiers) -> Self {
|
|
||||||
Self { key, modifiers }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn matches(&self, input: &egui::InputState) -> bool {
|
|
||||||
input.key_pressed(self.key) && input.modifiers == self.modifiers
|
|
||||||
}
|
|
||||||
}
|
|
||||||
37
src/main.rs
37
src/main.rs
@@ -1,18 +1,14 @@
|
|||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||||
#![allow(rustdoc::missing_crate_level_docs)] // it's an example
|
#![allow(rustdoc::missing_crate_level_docs)] // it's an example
|
||||||
use eframe::egui;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::fs::OpenOptions;
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
|
||||||
mod byte_writer;
|
mod byte_writer;
|
||||||
mod gui;
|
|
||||||
mod node;
|
mod node;
|
||||||
mod read_and_write;
|
mod read_and_write;
|
||||||
|
|
||||||
use gui::Omelt;
|
|
||||||
use read_and_write::{is_valid_file, save_action, string_translate};
|
use read_and_write::{is_valid_file, save_action, string_translate};
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
@@ -36,7 +32,6 @@ fn main() -> std::io::Result<()> {
|
|||||||
}
|
}
|
||||||
let mut txt = "".to_owned();
|
let mut txt = "".to_owned();
|
||||||
to_compress.read_to_string(&mut txt)?;
|
to_compress.read_to_string(&mut txt)?;
|
||||||
eprintln!("txt = {:?}", txt);
|
|
||||||
save_action(&txt, &mut after_compression)?;
|
save_action(&txt, &mut after_compression)?;
|
||||||
println!("Done.")
|
println!("Done.")
|
||||||
}
|
}
|
||||||
@@ -87,38 +82,11 @@ fn main() -> std::io::Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let options = eframe::NativeOptions {
|
display_options();
|
||||||
viewport: egui::ViewportBuilder::default().with_inner_size([640.0, 480.0]),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
let _ = eframe::run_native(
|
|
||||||
"Omelt",
|
|
||||||
options,
|
|
||||||
Box::new(|_| {
|
|
||||||
Ok(Box::new(Omelt::new(
|
|
||||||
&r,
|
|
||||||
OpenOptions::new().read(true).write(true).open(&r)?,
|
|
||||||
)))
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let options = eframe::NativeOptions {
|
display_options();
|
||||||
viewport: egui::ViewportBuilder::default().with_inner_size([640.0, 480.0]),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
let _ = eframe::run_native(
|
|
||||||
"Omelt",
|
|
||||||
options,
|
|
||||||
Box::new(|_| {
|
|
||||||
Ok(Box::new(Omelt::new(
|
|
||||||
"new_file.oeuf",
|
|
||||||
File::create_new("new_file.oeuf")?,
|
|
||||||
)))
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +94,6 @@ fn main() -> std::io::Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn display_options() {
|
fn display_options() {
|
||||||
println!("<input.oeuf> To open file with gui.");
|
|
||||||
println!("--compress , -c <intput> [<output>] To compress a file.");
|
println!("--compress , -c <intput> [<output>] To compress a file.");
|
||||||
println!("--uncompress, -u <intput.oeuf> [<output>] To uncompress a file.");
|
println!("--uncompress, -u <intput.oeuf> [<output>] To uncompress a file.");
|
||||||
println!("--print ,-p <input> To print a file compressed.");
|
println!("--print ,-p <input> To print a file compressed.");
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ use std::io::{Seek, SeekFrom};
|
|||||||
|
|
||||||
use crate::node;
|
use crate::node;
|
||||||
use byte_writer::*;
|
use byte_writer::*;
|
||||||
use eframe::Result;
|
|
||||||
use node::*;
|
use node::*;
|
||||||
|
|
||||||
const MAGIC_NUMBER: u8 = 128;
|
const MAGIC_NUMBER: u8 = 128;
|
||||||
|
|||||||
Reference in New Issue
Block a user