Skip to content

Commit 0a31739

Browse files
committed
[Feat] add loading
1 parent 6a83ed7 commit 0a31739

File tree

22 files changed

+324
-83
lines changed

22 files changed

+324
-83
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ syntect = { version = "5", default-features = false, features = ["default-fancy"
5353
katex = { version = "0.4.6", default-features = false, features = ["wasm-js"] }
5454
gloo-worker = { version = "0.4", features = ["futures"] }
5555
gloo-timers = { version = "0.3", features = ["futures"] }
56+
uuid = { version = "1", features = ["v4", "js"] }

app/src/commands/boa.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,16 @@ async fn run_boa(cli: BoaCommand, ctx: CommandContext) {
6060
let mut boa_ctx = Context::default();
6161
match boa_ctx.eval(Source::from_bytes(source.as_bytes())) {
6262
Ok(value) => match value.to_string(&mut boa_ctx) {
63-
Ok(out) => ctx.terminal.push_text(out.to_std_string_escaped()),
64-
Err(err) => ctx
65-
.terminal
66-
.push_error(format!("boa: failed to stringify result: {err}")),
63+
Ok(out) => {
64+
ctx.terminal.push_text(out.to_std_string_escaped());
65+
}
66+
Err(err) => {
67+
ctx.terminal
68+
.push_error(format!("boa: failed to stringify result: {err}"));
69+
}
6770
},
68-
Err(err) => ctx.terminal.push_error(format!("boa: {err}")),
69-
}
71+
Err(err) => {
72+
ctx.terminal.push_error(format!("boa: {err}"));
73+
}
74+
};
7075
}

app/src/commands/cat.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::commands::fetch::fetch_text_with_cache;
22
use crate::commands::{parse_cli, CommandContext};
3+
use crate::utils::run_async;
34
use crate::vfs_data::{find_node, format_path, resolve_path, VfsKind};
45
use micro_cli::Parser;
56
use shell_parser::integration::{CommandInfo, ExecutableCommand};
6-
use wasm_bindgen_futures::spawn_local;
77
use yew::html;
88

99
#[derive(Parser, Debug, Default)]
@@ -19,7 +19,7 @@ impl ExecutableCommand<CommandContext> for CatCommand {
1919
return Ok(());
2020
};
2121
let ctx = ctx.clone();
22-
spawn_local(async move {
22+
run_async(ctx.clone(), async move {
2323
run_cat(cli, ctx).await;
2424
});
2525
Ok(())
@@ -51,9 +51,13 @@ async fn run_cat(cli: CatCommand, ctx: CommandContext) {
5151
let uri = format!("/data/{}", path.join("/"));
5252

5353
match fetch_text_with_cache(&uri, &cache).await {
54-
Ok(text) => ctx.terminal.push_component(html! {
55-
<span class="whitespace-break-spaces">{text}</span>
56-
}),
57-
Err(err) => ctx.terminal.push_error(format!("cat: {err}")),
54+
Ok(text) => {
55+
ctx.terminal.push_component(html! {
56+
<span class="whitespace-break-spaces">{text}</span>
57+
});
58+
}
59+
Err(err) => {
60+
ctx.terminal.push_error(format!("cat: {err}"));
61+
}
5862
}
5963
}

app/src/commands/clear.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ use shell_parser::integration::{CommandInfo, ExecutableCommand};
55
#[derive(Parser, Debug, Default)]
66
#[command(name = "clear", about = "Clear the terminal")]
77
pub struct ClearCommand {
8-
#[arg(short = 'l', long = "last", help = "Clear the last output")]
9-
last: bool,
8+
#[arg(
9+
short = 'n',
10+
long = "number",
11+
help = "Clear the {number} output counting from the end"
12+
)]
13+
num: Option<usize>,
1014
}
1115

1216
impl ExecutableCommand<CommandContext> for ClearCommand {
@@ -15,7 +19,11 @@ impl ExecutableCommand<CommandContext> for ClearCommand {
1519
return Ok(());
1620
};
1721

18-
ctx.terminal.clear(cli.last);
22+
if let Some(num) = cli.num {
23+
ctx.terminal.clear(Some(num));
24+
} else {
25+
ctx.terminal.clear(None);
26+
}
1927

2028
Ok(())
2129
}

app/src/commands/du.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ impl ExecutableCommand<CommandContext> for DuCommand {
2424
ctx.terminal
2525
.push_text(format!("{} => {} bytes", format_path(&path), bytes));
2626
}
27-
None => ctx
28-
.terminal
29-
.push_error(format!("du: {}: not found", format_path(&path))),
27+
None => {
28+
ctx.terminal
29+
.push_error(format!("du: {}: not found", format_path(&path)));
30+
}
3031
}
3132
Ok(())
3233
}

app/src/commands/eval.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ async fn run_eval(cli: EvalCommand, ctx: CommandContext) {
5858
}
5959
ctx.terminal.execute_command(script);
6060
}
61-
Err(err) => ctx.terminal.push_error(format!("eval: {err}")),
61+
Err(err) => {
62+
ctx.terminal.push_error(format!("eval: {err}"));
63+
}
6264
}
6365
}

app/src/commands/history.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ impl ExecutableCommand<CommandContext> for HistoryCommand {
9999
};
100100

101101
match result {
102-
Ok(message) => ctx.terminal.push_text(format!("history: {message}")),
103-
Err(err) => ctx.terminal.push_error(err),
102+
Ok(message) => {
103+
ctx.terminal.push_text(format!("history: {message}"));
104+
}
105+
Err(err) => {
106+
ctx.terminal.push_error(err);
107+
}
104108
}
105109

106110
Ok(())

app/src/commands/ls.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,20 @@ impl ExecutableCommand<CommandContext> for LsCommand {
5757
};
5858
ctx.terminal.push_component(rendered);
5959
}
60-
_ => ctx.terminal.push_error("ls: empty directory"),
60+
_ => {
61+
ctx.terminal.push_error("ls: empty directory");
62+
}
6163
},
62-
Some(_) => ctx
63-
.terminal
64-
.push_error(format!("ls: {}: not a directory", format_path(&path))),
65-
None => ctx.terminal.push_error(format!(
66-
"ls: {}: no such file or directory",
67-
format_path(&path)
68-
)),
64+
Some(_) => {
65+
ctx.terminal
66+
.push_error(format!("ls: {}: not a directory", format_path(&path)));
67+
}
68+
None => {
69+
ctx.terminal.push_error(format!(
70+
"ls: {}: no such file or directory",
71+
format_path(&path)
72+
));
73+
}
6974
}
7075
Ok(())
7176
}

app/src/commands/navigate.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ impl ExecutableCommand<CommandContext> for NavigateCommand {
2424
terminal.execute_command(&format!("history --push {path}"));
2525
match terminal.to_terminal() {
2626
Some(full_terminal) => run_route(&path, full_terminal),
27-
None => terminal.push_error("navigate: unable to execute route"),
27+
None => {
28+
terminal.push_error("navigate: unable to execute route");
29+
}
2830
}
2931
});
3032

0 commit comments

Comments
 (0)