Skip to content

Commit 2995a28

Browse files
committed
feat: clear terminal button, cleanup styling
1 parent f12000d commit 2995a28

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

src-tauri/src/terminal.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use tauri::State;
55
use crate::AppState;
66
use crate::steam::SteamDownload;
77

8+
/* Parts of this file are derived from https://github.com/cablehead/tauri-xtermjs-nushell/blob/0bdd4a27ee2874de12e99bccd6c91d6ec5d28fbc/src-tauri/src/main.rs */
9+
810
#[tauri::command]
911
pub async fn async_write_to_pty(data: &str, state: State<'_, AppState>) -> Result<(), ()> {
1012
write!(state.writer.lock().await, "{}", data).map_err(|_| ())
@@ -18,7 +20,7 @@ pub async fn async_read_from_pty(state: State<'_, AppState>) -> Result<Option<St
1820
let data = reader.fill_buf().map_err(|_| ())?;
1921

2022
// Send the data to the webview if necessary
21-
if data.len() > 0 {
23+
if !data.is_empty() {
2224
std::str::from_utf8(data)
2325
.map(|v| Some(v.to_string()))
2426
.map_err(|_| ())?
@@ -64,14 +66,14 @@ pub fn create_depotdownloader_command(steam_download: &SteamDownload, cwd: &Path
6466
command.cwd(cwd);
6567

6668
if !steam_download.is_anonymous() {
67-
command.args(["-username", &*steam_download.username().clone().unwrap()]);
68-
command.args(["-password", &*steam_download.password().clone().unwrap()]);
69+
command.args(["-username", &steam_download.username().clone().unwrap()]);
70+
command.args(["-password", &steam_download.password().clone().unwrap()]);
6971
}
7072

71-
command.args(["-app", &*steam_download.app_id()]);
72-
command.args(["-depot", &*steam_download.depot_id()]);
73-
command.args(["-manifest", &*steam_download.manifest_id()]);
74-
command.args(["-dir", &*steam_download.output_path()]);
73+
command.args(["-app", steam_download.app_id()]);
74+
command.args(["-depot", steam_download.depot_id()]);
75+
command.args(["-manifest", steam_download.manifest_id()]);
76+
command.args(["-dir", &steam_download.output_path()]);
7577

7678
command
7779
}

src/index.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<body class="select-none">
1818
<div class="f1-light text-center mb-1">Steam Depot Downloader</div>
1919
<div class="flex justify-between gap-2 w-svw flex-row">
20-
<div class="w-1/2 h-full">
20+
<div class="w-1/2 h-full" id="left-side">
2121
<div class="mx-auto">
2222
<form id="theform">
2323
<div class="form-group mx-3 mt-1">
@@ -159,10 +159,15 @@
159159
</div>
160160
</div>
161161
</div>
162-
<div class="w-1/2 h-full px-2">
162+
<div class="w-1/2 h-full px-2" id="right-side">
163163
<div class="mt-2 h-full w-full mx-auto">
164164
<div class="border border-gray-300 rounded-md bg-gray-900 text-white shadow shadow-blue-200">
165-
<span class="text-md font-semibold block text-center">Download output</span>
165+
<div class="text-md font-semibold w-full inline-flex my-px items-center">
166+
<span class="text-center w-full">Download output</span>
167+
<button id="clear-terminal" class="disabled:pointer-events-none disabled:line-through disabled:text-gray-300 ml-auto py-px px-2 border-2 rounded-xs border-red-500/75 font-normal enabled:hover:bg-red-200/30 enabled:active:bg-red-200/50">
168+
Clear
169+
</button>
170+
</div>
166171
<div class="max-h-[70vh]" id="xtermjs"></div>
167172
</div>
168173
<div class="mt-3 justify-between flex flex-row gap-3">

src/ts/main.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ import {Terminal} from "@xterm/xterm";
77
import { FitAddon } from "@xterm/addon-fit";
88
import { listen } from "@tauri-apps/api/event";
99

10-
function setLoader(state: boolean) {
11-
$("#busy").prop("hidden", !state);
10+
/* Parts of this file are derived from https://github.com/cablehead/tauri-xtermjs-nushell/blob/0bdd4a27ee2874de12e99bccd6c91d6ec5d28fbc/src/main.ts */
11+
12+
function blockTerminalClearButton(state: boolean) {
13+
$("#clear-terminal").prop( "disabled", state );
1214
}
1315

1416

1517
function setLoadingState(state: boolean) {
1618
$("#busy").prop("hidden", !state);
1719

1820
// loop through all buttons and input fields and disable them
19-
for (const element of document.querySelectorAll("button, input")) {
21+
for (const element of document.querySelectorAll("button, input, div[role='button']")) {
2022
if (element.closest("#settings-content")) continue;
23+
if (element.closest("#right-side")) continue;
2124
(element as any).disabled = state;
2225
}
2326

@@ -49,15 +52,15 @@ const invalidFields = () => {
4952
return invalidFields;
5053
};
5154

52-
const registerTerminal = async (terminalElement: HTMLElement) => {
55+
const registerTerminal: (terminalElement: HTMLElement) => Promise<Terminal> = async (terminalElement: HTMLElement) => {
5356
const fitAddon = new FitAddon();
5457
const term = new Terminal({
5558
fontSize: 10,
5659
cursorBlink: true,
5760
rows: 100,
5861
cols: 100,
5962
theme: {
60-
background: "rgb(47, 47, 47)",
63+
background: "rgb(33, 33, 33)",
6164
},
6265
});
6366
term.loadAddon(fitAddon);
@@ -97,18 +100,23 @@ const registerTerminal = async (terminalElement: HTMLElement) => {
97100
}
98101

99102
window.requestAnimationFrame(readFromPty);
103+
104+
return term;
100105
};
101106

102107

103108
$(async () => {
104-
await registerTerminal($("#xtermjs")[0]);
109+
let terminal = await registerTerminal($("#xtermjs")[0]);
105110
let downloadDirectory: string | null;
106111

107112
// Startup logic
108113
setLoadingState(true);
109114
await invoke("preload_vectum");
110115
setLoadingState(false);
111116

117+
$("#clear-terminal").on("click", async () => {
118+
terminal.reset()
119+
})
112120

113121
$("#pickpath").on("click", async () => {
114122
// Open a dialog
@@ -196,6 +204,9 @@ $(async () => {
196204

197205
setLoadingState(true);
198206
await invoke("start_download", {steamDownload: steamDownload});
207+
208+
// Block clear terminal button (to avoid clearing ongoing download logs)
209+
blockTerminalClearButton(true);
199210
console.log("Send frontend data over to backend. Ready for next download.");
200211
});
201212

@@ -230,4 +241,5 @@ $(async () => {
230241

231242
listen<string>("command-exited", () => {
232243
setLoadingState(false);
244+
blockTerminalClearButton(false);
233245
});

0 commit comments

Comments
 (0)