Skip to content

Commit

Permalink
Start console i/o UI
Browse files Browse the repository at this point in the history
  • Loading branch information
cayb0rg committed Feb 5, 2024
1 parent d206069 commit 299818d
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 133 deletions.
4 changes: 4 additions & 0 deletions src/agent/datapath_communicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,8 @@ impl DatapathCommunicator {
) -> Box<dyn VisualDatapath> {
todo!()
}

pub fn get_accepting_input(&self) -> bool {
todo!()
}
}
16 changes: 9 additions & 7 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ use js_sys::Object;
use monaco::{
api::TextModel,
sys::{
editor::{
IMarkerData
},
editor::IMarkerData,
MarkerSeverity,
}
};
use swim::{parser::parser_assembler_main::parser, ui::{console::component::ConsoleTabState, swim_editor::component::EditorTabState}};
use swim::{parser::parser_assembler_main::parser, ui::{footer::component::FooterTabState, swim_editor::component::EditorTabState}};
use swim::parser::parser_structs_and_enums::ProgramInfo;
use std::rc::Rc;
use swim::agent::EmulationCoreAgent;
use swim::agent::datapath_communicator::DatapathCommunicator;
use swim::emulation_core::datapath::Datapath;
use swim::emulation_core::mips::datapath::MipsDatapath;
use swim::emulation_core::mips::datapath::Stage;
use swim::ui::console::component::Console;
use swim::ui::footer::component::Footer;
use swim::ui::regview::component::Regview;
use swim::ui::swim_editor::component::SwimEditor;
use wasm_bindgen::{JsCast, JsValue};
Expand Down Expand Up @@ -73,8 +71,12 @@ fn app(props: &AppProps) -> Html {

let memory_text_model = use_state_eq(|| TextModel::create(&memory_text_output, Some("ini"), None).unwrap());

// Show input
let show_input = use_state_eq(|| bool::default());
show_input.set(true);

// Store the currently selected tabs in windows
let console_active_tab = use_state_eq(ConsoleTabState::default);
let console_active_tab = use_state_eq(FooterTabState::default);
let editor_active_tab = use_state_eq(EditorTabState::default);

// Since we want the Datapath to be independent from all the
Expand Down Expand Up @@ -483,7 +485,7 @@ fn app(props: &AppProps) -> Html {
</div>

// Console
<Console parsermsg={(*parser_text_output).clone()} datapath={(*datapath.borrow()).clone()} memory_text_model={memory_text_model} memory_curr_instr={memory_curr_instr.clone()} active_tab={console_active_tab.clone()}/>
<Footer parsermsg={(*parser_text_output).clone()} datapath={(*datapath.borrow()).clone()} memory_text_model={memory_text_model} memory_curr_instr={memory_curr_instr.clone()} active_tab={console_active_tab.clone()} communicator={props.communicator} show_input={show_input.clone()}/>
</div>

// Right column
Expand Down
5 changes: 3 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@


pub mod assembled_view;
pub mod console;
pub mod footer;
pub mod hex_editor;
pub mod regview;
pub mod swim_editor;
pub mod visual_datapath;
pub mod visual_datapath;
pub mod console;
10 changes: 5 additions & 5 deletions src/ui/assembled_view/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use yew::prelude::*;
use wasm_bindgen::JsCast;
use log::debug;
use crate::parser::parser_structs_and_enums::ProgramInfo;
use crate::ui::console::component::ConsoleTabState;
use crate::ui::footer::component::FooterTabState;
use crate::ui::swim_editor::component::EditorTabState;


Expand All @@ -20,7 +20,7 @@ pub struct TextSegmentProps {
pub editor_curr_line: UseStateHandle<f64>,
pub pc: u64,
pub editor_active_tab: UseStateHandle<EditorTabState>,
pub console_active_tab: UseStateHandle<ConsoleTabState>
pub console_active_tab: UseStateHandle<FooterTabState>
}
#[derive(PartialEq, Properties)]
pub struct DataSegmentProps {
Expand All @@ -30,7 +30,7 @@ pub struct DataSegmentProps {
pub memory_curr_instr: UseStateHandle<u64>,
pub editor_curr_line: UseStateHandle<f64>,
pub editor_active_tab: UseStateHandle<EditorTabState>,
pub console_active_tab: UseStateHandle<ConsoleTabState>,
pub console_active_tab: UseStateHandle<FooterTabState>,
pub pc_limit: usize
}

Expand Down Expand Up @@ -72,7 +72,7 @@ pub fn TextSegment(props: &TextSegmentProps) -> Html {
use_callback(move |args: (MouseEvent, usize), memory_curr_instr| {
let (_e, address) = args;
memory_curr_instr.set(address as u64);
console_active_tab.set(ConsoleTabState::HexEditor);
console_active_tab.set(FooterTabState::HexEditor);
}, memory_curr_instr)
};

Expand Down Expand Up @@ -185,7 +185,7 @@ pub fn DataSegment(props: &DataSegmentProps) -> Html {
use_callback(move |args: (MouseEvent, usize), memory_curr_instr| {
let (_e, address) = args;
memory_curr_instr.set(address as u64);
console_active_tab.set(ConsoleTabState::HexEditor);
console_active_tab.set(FooterTabState::HexEditor);
}, memory_curr_instr)
};

Expand Down
164 changes: 52 additions & 112 deletions src/ui/console/component.rs
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>
}
}
3 changes: 1 addition & 2 deletions src/ui/console/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pub mod component;
pub mod helper;
pub mod component;
Loading

0 comments on commit 299818d

Please sign in to comment.