misc: applied some clippy lints
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@ path = "src/lib.rs"
|
||||
[dependencies]
|
||||
common = { path = "../common" }
|
||||
assembler = { path = "../assembler" }
|
||||
dsa_editor = { path = "../dsa_editor" }
|
||||
dsa_editor = { git = "https://github.com/zxq5-dev/egui_code_editor", package = "egui_code_editor", rev = "5eb313e" }
|
||||
eframe = "0.31.1"
|
||||
egui = "0.31.1"
|
||||
rfd = "0.15.3"
|
||||
|
||||
@@ -43,7 +43,7 @@ impl Component for Editor {
|
||||
|
||||
if ui.input(|i| i.key_pressed(Key::S) && i.modifiers.ctrl) {
|
||||
self.save();
|
||||
};
|
||||
}
|
||||
|
||||
self.render_toolbar(state, ui, ctx);
|
||||
|
||||
@@ -87,17 +87,23 @@ impl Editor {
|
||||
fn filename(&self) -> &str {
|
||||
self.path
|
||||
.file_name()
|
||||
.unwrap_or(OsStr::new("Unnamed!"))
|
||||
.unwrap_or_else(|| OsStr::new("Unnamed!"))
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.map_or_else(
|
||||
|| unreachable!("File name should be valid UTF-8."),
|
||||
|ext| ext,
|
||||
)
|
||||
}
|
||||
|
||||
fn extension(&self) -> &str {
|
||||
self.path
|
||||
.extension()
|
||||
.unwrap_or(OsStr::new("Unknown!"))
|
||||
.unwrap_or_else(|| OsStr::new("Unknown!"))
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.map_or_else(
|
||||
|| unreachable!("File name should be valid UTF-8."),
|
||||
|ext| ext,
|
||||
)
|
||||
}
|
||||
|
||||
fn save(&mut self) {
|
||||
@@ -210,10 +216,10 @@ impl Editor {
|
||||
);
|
||||
|
||||
// Instruction column
|
||||
let instruction = match Instruction::decode(value) {
|
||||
Ok(instruction) => instruction.to_string(),
|
||||
Err(_) => format!("{value:10}"),
|
||||
};
|
||||
let instruction = Instruction::decode(value).map_or_else(
|
||||
|_| format!("{value:10}"),
|
||||
|instruction| instruction.to_string(),
|
||||
);
|
||||
|
||||
ui.label(
|
||||
egui::RichText::new(instruction)
|
||||
@@ -230,19 +236,25 @@ impl Editor {
|
||||
fn render_editor(&mut self, _state: &mut State, ui: &mut Ui, _ctx: &Context) {
|
||||
let available_width = ui.available_width();
|
||||
let syntax = match self.extension() {
|
||||
"dsa" => Syntax::dsa(),
|
||||
_ => Syntax::dsa(),
|
||||
"dsa" => Some(Syntax::new("dsa")),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
CodeEditor::default()
|
||||
let ed = CodeEditor::default()
|
||||
.id_source("editor")
|
||||
.with_fontsize(12.0)
|
||||
.with_rows(0)
|
||||
.with_theme(ColorTheme::default())
|
||||
.with_syntax(syntax)
|
||||
.with_numlines(true)
|
||||
.desired_width(available_width - 450.0)
|
||||
.show(ui, &mut self.text);
|
||||
.desired_width(available_width - 450.0);
|
||||
|
||||
let mut editor = ed.clone();
|
||||
|
||||
if let Some(syntax) = syntax {
|
||||
editor = ed.with_syntax(syntax);
|
||||
}
|
||||
|
||||
editor.show(ui, &mut self.text);
|
||||
}
|
||||
|
||||
fn render_toolbar(&mut self, _state: &mut State, ui: &mut Ui, _ctx: &Context) {
|
||||
|
||||
Reference in New Issue
Block a user