-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
235 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,70 @@ | ||
//use crate::parser::parser_structs_and_enums::instruction_tokenization::ProgramInfo; | ||
//use monaco::api::TextModel; | ||
use wasm_bindgen::JsCast; | ||
use web_sys::HtmlElement; | ||
use crate::agent::datapath_communicator::DatapathCommunicator; | ||
use web_sys::{KeyboardEvent, InputEvent, HtmlInputElement}; | ||
use yew::prelude::*; | ||
use yew_hooks::prelude::*; | ||
use monaco::api::TextModel; | ||
use crate::emulation_core::mips::datapath::MipsDatapath; | ||
use crate::ui::visual_datapath::{DatapathSize, VisualDatapath}; | ||
use crate::ui::hex_editor::component::HexEditor; | ||
use wasm_bindgen::JsCast; | ||
|
||
#[derive(PartialEq, Properties)] | ||
pub struct Consoleprops { | ||
pub datapath: MipsDatapath, | ||
pub communicator: &'static DatapathCommunicator, | ||
pub parsermsg: String, | ||
pub memory_text_model: UseStateHandle<TextModel>, | ||
pub memory_curr_instr: UseStateHandle<u64>, | ||
pub active_tab: UseStateHandle<ConsoleTabState>, | ||
} | ||
|
||
#[derive(Default, PartialEq)] | ||
pub enum ConsoleTabState { | ||
#[default] | ||
Console, | ||
Datapath, | ||
HexEditor | ||
pub show_input: UseStateHandle<bool> | ||
} | ||
|
||
#[function_component(Console)] | ||
pub fn console(props: &Consoleprops) -> Html { | ||
let active_tab = &props.active_tab; | ||
let zoom_datapath = use_bool_toggle(false); | ||
let switch_datapath = use_bool_toggle(false); | ||
let change_tab = { | ||
let active_tab = active_tab.clone(); | ||
Callback::from(move |event: MouseEvent| { | ||
let target = event.target().unwrap().dyn_into::<HtmlElement>().unwrap(); | ||
let tab_name = target | ||
.get_attribute("label") | ||
.unwrap_or(String::from("console")); | ||
|
||
let new_tab = match tab_name.as_str() { | ||
"console" => ConsoleTabState::Console, | ||
"datapath" => ConsoleTabState::Datapath, | ||
"hex_editor" => ConsoleTabState::HexEditor, | ||
_ => ConsoleTabState::default(), | ||
}; | ||
|
||
active_tab.set(new_tab); | ||
}) | ||
}; | ||
|
||
let toggle_zoom = { | ||
let zoom_datapath = zoom_datapath.clone(); | ||
|
||
Callback::from(move |_| { | ||
zoom_datapath.toggle(); | ||
}) | ||
}; | ||
|
||
let datapath_size = match *zoom_datapath { | ||
true => DatapathSize::Big, | ||
false => DatapathSize::Small, | ||
}; | ||
|
||
let switch_datapath_type = { | ||
let switch_datapath = switch_datapath.clone(); | ||
|
||
Callback::from(move |_| { | ||
switch_datapath.toggle(); | ||
}) | ||
let show_input = props.show_input.clone(); | ||
let input_value = use_state_eq(String::new); | ||
let error_msg = use_state_eq(|| ""); | ||
|
||
let on_keyup = { | ||
let error_msg = error_msg.clone(); | ||
let input_value = input_value.clone(); | ||
use_callback(move |event: KeyboardEvent, (input_value, error_msg)| { | ||
// let communicator = props.communicator; | ||
let key_code = event.key_code(); | ||
let error_msg = error_msg.clone(); | ||
let input_value = input_value.clone(); | ||
// If Enter was pressed parse and send input to emulator core | ||
if key_code == 13 { | ||
let input_value = &*input_value; | ||
log::debug!("Input: {}", (input_value)); | ||
// Parse based on syscall type (int, float, string) | ||
let val: String = match input_value.parse() { | ||
Ok(value) => { | ||
value | ||
}, | ||
Err(_err) => { | ||
error_msg.set("Invalid input"); | ||
return | ||
} | ||
}; | ||
// Send Input command | ||
} | ||
}, (input_value, error_msg)) | ||
}; | ||
|
||
let svg_path = match *switch_datapath { | ||
true => "static/datapath_full.svg", | ||
false => "static/datapath_simple.svg", | ||
}; | ||
let on_input = Callback::from(move |event: InputEvent| { | ||
// let communicator = props.communicator; | ||
let target = event.target(); | ||
let input = target.unwrap().unchecked_into::<HtmlInputElement>(); | ||
|
||
let switch_datapath_button_label = match *switch_datapath { | ||
true => "Switch to Simple Datapath", | ||
false => "Switch to Full Datapath", | ||
}; | ||
input_value.set(input.value()); | ||
}); | ||
|
||
html! { | ||
<> | ||
// Console buttons | ||
if **active_tab == ConsoleTabState::Console { | ||
<pre class="console"> | ||
{ props.parsermsg.clone() } | ||
</pre> | ||
} else if **active_tab == ConsoleTabState::Datapath { | ||
<div class="datapath-wrapper"> | ||
<VisualDatapath datapath={props.datapath.clone()} svg_path={svg_path} size={datapath_size} /> | ||
</div> | ||
} else if **active_tab == ConsoleTabState::HexEditor { | ||
<div class="hex-wrapper"> | ||
<HexEditor memory_text_model={props.memory_text_model.clone()} instruction_num={props.memory_curr_instr.clone()}/> | ||
<div> | ||
{props.parsermsg.clone()} | ||
<div> | ||
{*error_msg} | ||
</div> | ||
if *show_input { | ||
<div class="console-input"> | ||
<svg viewBox="0 0 330 330" class="console-arrow"> | ||
<path id="XMLID_222_" d="M250.606,154.389l-150-149.996c-5.857-5.858-15.355-5.858-21.213,0.001 c-5.857,5.858-5.857,15.355,0.001,21.213l139.393,139.39L79.393,304.394c-5.857,5.858-5.857,15.355,0.001,21.213 C82.322,328.536,86.161,330,90,330s7.678-1.464,10.607-4.394l149.999-150.004c2.814-2.813,4.394-6.628,4.394-10.606 C255,161.018,253.42,157.202,250.606,154.389z"/> | ||
</svg> | ||
<input type="text" onkeyup={on_keyup} oninput={on_input}/> | ||
</div> | ||
} | ||
<div class="button-bar"> | ||
<div class="tabs"> | ||
if **active_tab == ConsoleTabState::Console { | ||
<button class={classes!("bottom-tab", "pressed")} label="console" onclick={change_tab.clone()}>{"Console"}</button> | ||
} else { | ||
<button class="bottom-tab" label="console" onclick={change_tab.clone()}>{"Console"}</button> | ||
} | ||
|
||
if **active_tab == ConsoleTabState::Datapath { | ||
<button class={classes!("bottom-tab", "pressed")} label="datapath" onclick={change_tab.clone()}>{"Datapath"}</button> | ||
} else { | ||
<button class="bottom-tab" label="datapath" onclick={change_tab.clone()}>{"Datapath"}</button> | ||
} | ||
|
||
if **active_tab == ConsoleTabState::HexEditor { | ||
<button class={classes!("bottom-tab", "pressed")} label="hex_editor" onclick={change_tab.clone()}>{"Hex Editor"}</button> | ||
} else { | ||
<button class="bottom-tab" label="hex_editor" onclick={change_tab.clone()}>{"Hex Editor"}</button> | ||
} | ||
</div> | ||
|
||
if **active_tab == ConsoleTabState::Datapath { | ||
<div class="buttons"> | ||
<button class={ classes!("bg-red-500", "button") } onclick={toggle_zoom}>{"Toggle Zoom"}</button> | ||
<button class="button" onclick={switch_datapath_type}>{switch_datapath_button_label}</button> | ||
</div> | ||
} | ||
</div> | ||
</> | ||
</div> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
pub mod component; | ||
pub mod helper; | ||
pub mod component; |
Oops, something went wrong.