Basic input and output
commit
9632e8705e
@ -0,0 +1,2 @@
|
||||
/target
|
||||
/dist
|
@ -0,0 +1,210 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "console_error_panic_hook"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.108"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memory_units"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb37d2df5df740e582f28f8560cf425f52bb267d872fe58358eadb554909f07a"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.82"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tildashe"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"console_error_panic_hook",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
"wee_alloc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.74"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.74"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.74"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.74"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.74"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f"
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wee_alloc"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"libc",
|
||||
"memory_units",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "tildashe"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
opt-level = 'z'
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
console_error_panic_hook = "0.1"
|
||||
web-sys = { version = "0.3", features = ["Window", "Document", "HtmlElement", "Node", "Text", "KeyboardEvent"] }
|
||||
wasm-bindgen = "=0.2.74"
|
||||
wee_alloc = "0.4.5"
|
@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>~ashe</title>
|
||||
<script src="https://unpkg.com/ansi_up@5.1.0/ansi_up.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="target"></div>
|
||||
<style>
|
||||
html, body {
|
||||
--background-color: rgb(37, 29, 51);
|
||||
--foreground-color: white;
|
||||
|
||||
background: var(--background-color);
|
||||
color: var(--foreground-color);
|
||||
}
|
||||
|
||||
#target {
|
||||
white-space: pre;
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
}
|
||||
|
||||
#target::after {
|
||||
content: '█';
|
||||
display: inline-block;
|
||||
/* animation: blink 2.4s infinite; */
|
||||
opacity: .8;
|
||||
}
|
||||
|
||||
@keyframes blink {
|
||||
0%, 49% {
|
||||
color: var(--foreground-color);
|
||||
border: solid 1px transparent;
|
||||
}
|
||||
|
||||
50%, 99% {
|
||||
color: transparent;
|
||||
border: solid .5px var(--foreground-color);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,14 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_namespace = console)]
|
||||
pub fn log(s: &str);
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! console_log {
|
||||
// Note that this is using the `log` function imported above during
|
||||
// `bare_bones`
|
||||
($($t:tt)*) => (js::log(&format_args!($($t)*).to_string()))
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
extern crate console_error_panic_hook;
|
||||
|
||||
mod js;
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::panic;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use web_sys::KeyboardEvent;
|
||||
use web_sys::Element;
|
||||
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||
|
||||
enum Key {
|
||||
Letter(char),
|
||||
Space,
|
||||
Backspace,
|
||||
Return,
|
||||
Ctrl(Box<Key>)
|
||||
}
|
||||
|
||||
struct State {
|
||||
// cwd : &Directory
|
||||
input : String,
|
||||
output : VecDeque<String>
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn new() -> Self {
|
||||
State {
|
||||
input : String::new(),
|
||||
output : VecDeque::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||
|
||||
let mut state = State::new();
|
||||
|
||||
let window = web_sys::window().expect("should have a window in this context");
|
||||
let document = window.document().expect("window should have a document");
|
||||
let mut target = document
|
||||
.get_element_by_id("target")
|
||||
.expect("should have #target on the page");
|
||||
|
||||
print_state(&mut target, &state);
|
||||
|
||||
let closure = Closure::wrap(Box::new(move |event: web_sys::KeyboardEvent| {
|
||||
let key = parse_key_event(&event, false);
|
||||
|
||||
if key.is_none() {
|
||||
return
|
||||
}
|
||||
|
||||
let key = key.unwrap();
|
||||
|
||||
update_state(&mut state, key);
|
||||
print_state(&mut target, &state);
|
||||
}) as Box<dyn FnMut(_)>);
|
||||
|
||||
|
||||
document.add_event_listener_with_callback("keydown", closure.as_ref().unchecked_ref()).unwrap();
|
||||
|
||||
closure.forget();
|
||||
}
|
||||
|
||||
fn parse_key_event(event : &KeyboardEvent, ignore_ctrl : bool) -> Option<Key> {
|
||||
if event.ctrl_key() && !ignore_ctrl {
|
||||
let base = parse_key_event(event, true)?;
|
||||
|
||||
return Some(Key::Ctrl(Box::new(base)))
|
||||
}
|
||||
|
||||
let key = event.key();
|
||||
|
||||
// TODO: ^C
|
||||
match key.as_str() {
|
||||
"Space" => Some(Key::Space),
|
||||
"Backspace" => Some(Key::Backspace),
|
||||
"Enter" => Some(Key::Return),
|
||||
_ => {
|
||||
if key.len() != 1 {
|
||||
None
|
||||
} else {
|
||||
Some(Key::Letter(key.chars().next().unwrap()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_state(state : &mut State, key : Key) {
|
||||
match key {
|
||||
Key::Return => {
|
||||
let input = std::mem::replace(&mut state.input, String::new());
|
||||
state.output.push_back(format!("> {}", input));
|
||||
if state.output.len() > 10 {
|
||||
state.output.pop_front();
|
||||
}
|
||||
|
||||
// TODO - parse the command
|
||||
},
|
||||
Key::Backspace => {
|
||||
if state.input.len() > 0 {
|
||||
state.input.remove(state.input.len() - 1);
|
||||
}
|
||||
},
|
||||
Key::Space => state.input += " ",
|
||||
Key::Letter(letter) => {
|
||||
let mut tmp = [0; 4];
|
||||
state.input += letter.encode_utf8(&mut tmp)
|
||||
}
|
||||
Key::Ctrl(letter) =>
|
||||
match letter.as_ref() {
|
||||
Key::Letter(letter) => {
|
||||
if *letter == 'c' {
|
||||
let mut input = std::mem::replace(&mut state.input, String::new());
|
||||
input += "^C";
|
||||
state.output.push_back(format!("> {}", input));
|
||||
if state.output.len() > 10 {
|
||||
state.output.pop_front();
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn print_state(target : &mut Element, state : &State) {
|
||||
let mut output = state.output.iter().map(|s| (*s).clone()).collect::<Vec<String>>().join("\n");
|
||||
|
||||
if state.output.len() > 0 {
|
||||
output += "\n";
|
||||
}
|
||||
|
||||
// TODO: Line overflow
|
||||
output += format!("> {}", state.input.as_str()).as_str();
|
||||
|
||||
target.set_text_content(Some(output.as_str()));
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
ashe@tilde.club's password:
|
||||
|
||||
ashe@tilde.club:~$ ls
|
||||
about.md contact.md *projects*
|
||||
|
||||
ashe@tilde.club:~$ cat about.md
|
||||
───────┬──────────────────────────────────────────────────
|
||||
│ File: about.md
|
||||
───────┼──────────────────────────────────────────────────
|
||||
1 │ some stuff
|
||||
2 │
|
||||
3 │ some more stuff
|
||||
───────┴──────────────────────────────────────────────────
|
||||
|
||||
ashe@tilde.club:~$ cat contact.md
|
||||
───────┬──────────────────────────────────────────────────
|
||||
│ File: contact.md
|
||||
───────┼──────────────────────────────────────────────────
|
||||
1 │ some stuff
|
||||
2 │
|
||||
3 │ some more stuff
|
||||
───────┴──────────────────────────────────────────────────
|
||||
|
||||
ashe@tilde.club:~$ cat projects
|
||||
/bin/cat: projects: Is a directory
|
||||
|
||||
ashe@tilde.club:~$ ls projects
|
||||
ashe.gay tilde.club/~ashe tempest.dev
|
||||
|
||||
ashe@tilde.club:~$ cat projects/ashe.gay
|
||||
───────┬──────────────────────────────────────────────────
|
||||
│ File: projects/ashe.gay
|
||||
───────┼──────────────────────────────────────────────────
|
||||
1 │ # ashe.gay
|
||||
2 │
|
||||
3 │ a site for my creative writing and other vaguely
|
||||
4 │ less technical shit. of course me being me the
|
||||
5 │ implementation itself is actually technical as
|
||||
6 │ fuck what with the styles, animations, and
|
||||
7 | everything else
|
||||
───────┴──────────────────────────────────────────────────
|
||||
|
||||
ashe@tilde.club:~$
|
Loading…
Reference in New Issue