remove gui
This commit is contained in:
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
|
||||
#![allow(rustdoc::missing_crate_level_docs)] // it's an example
|
||||
use eframe::egui;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
use std::io::prelude::*;
|
||||
|
||||
mod byte_writer;
|
||||
mod gui;
|
||||
mod node;
|
||||
mod read_and_write;
|
||||
|
||||
use gui::Omelt;
|
||||
use read_and_write::{is_valid_file, save_action, string_translate};
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
@@ -36,7 +32,6 @@ fn main() -> std::io::Result<()> {
|
||||
}
|
||||
let mut txt = "".to_owned();
|
||||
to_compress.read_to_string(&mut txt)?;
|
||||
eprintln!("txt = {:?}", txt);
|
||||
save_action(&txt, &mut after_compression)?;
|
||||
println!("Done.")
|
||||
}
|
||||
@@ -87,38 +82,11 @@ fn main() -> std::io::Result<()> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let options = eframe::NativeOptions {
|
||||
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)?,
|
||||
)))
|
||||
}),
|
||||
);
|
||||
display_options();
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let options = eframe::NativeOptions {
|
||||
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")?,
|
||||
)))
|
||||
}),
|
||||
);
|
||||
display_options();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +94,6 @@ fn main() -> std::io::Result<()> {
|
||||
}
|
||||
|
||||
fn display_options() {
|
||||
println!("<input.oeuf> To open file with gui.");
|
||||
println!("--compress , -c <intput> [<output>] To compress a file.");
|
||||
println!("--uncompress, -u <intput.oeuf> [<output>] To uncompress a file.");
|
||||
println!("--print ,-p <input> To print a file compressed.");
|
||||
|
||||
@@ -6,7 +6,6 @@ use std::io::{Seek, SeekFrom};
|
||||
|
||||
use crate::node;
|
||||
use byte_writer::*;
|
||||
use eframe::Result;
|
||||
use node::*;
|
||||
|
||||
const MAGIC_NUMBER: u8 = 128;
|
||||
|
||||
Reference in New Issue
Block a user