@setoelkahfi / svara / commits / a3ee253

Added external terminal

mellobacon committed Oct 6, 2022 at 20:20 UTC a3ee25363a72993a30958228949717d5346371ce
2 files changed +81 -18
src-tauri/src/main.rs
+39 -17
@@ -1,28 +1,50 @@
1 #![cfg_attr(
2 - all(not(debug_assertions), target_os = "windows"),
3 - windows_subsystem = "windows"
2 + all(not(debug_assertions), target_os = "windows"),
3 + windows_subsystem = "windows"
4 )]
5
6 -use std::process::Command;
6 use std::env;
7 +use std::process::Command;
8 #[tauri::command]
9 -fn open_in_explorer(path: &str){
10 - // FOR OTHER OS REFER - https://doc.rust-lang.org/std/env/consts/constant.OS.html
11 - // REF - https://github.com/tauri-apps/tauri/issues/4062
12 - // TARGET - WINDOWS
13 - if env:: consts:: OS == "windows" {
14 - Command::new("explorer")
15 - .args(["/select,",path])
9 +fn open_in_explorer(path: &str) {
10 + // FOR OTHER OS REFER - https://doc.rust-lang.org/std/env/consts/constant.OS.html
11 + // REF - https://github.com/tauri-apps/tauri/issues/4062
12 + // TARGET - WINDOWS
13 + if env::consts::OS == "windows" {
14 + Command::new("explorer")
15 + .args(["/select,", path])
16 + .spawn()
17 + .unwrap();
18 + } else if env::consts::OS == "linux" {
19 + Command::new("explorer")
20 + .args(["/select,", path])
21 .spawn()
22 .unwrap();
18 - }
23 + }
24 +}
25 +
26 +#[tauri::command]
27 +fn open_terminal(path: &str) {
28 + if env::consts::OS == "windows" {
29 + // programs for windows: [cmd, powershell, wt]
30 + // programs for ubuntu: [gnome-terminal]
31 + // .args(["/C", "start", "wt"])
32 + Command::new("cmd")
33 + .args(["/C", "wt", "-d", path])
34 + .spawn()
35 + .unwrap();
36 + }
37 + else {
38 + Command::new("sh")
39 + .args(["cd", path])
40 + .spawn()
41 + .unwrap();
42 + }
43 }
44
45 fn main() {
22 - tauri::Builder::default()
23 - .invoke_handler(tauri::generate_handler![
24 - open_in_explorer
25 - ])
26 - .run(tauri::generate_context!())
27 - .expect("error while running tauri application");
46 + tauri::Builder::default()
47 + .invoke_handler(tauri::generate_handler![open_in_explorer, open_terminal])
48 + .run(tauri::generate_context!())
49 + .expect("error while running tauri application");
50 }
src/components/Footer/Footer.svelte
+42 -1
@@ -1,6 +1,10 @@
1 <script lang="ts">
2 + import { Terminal } from "carbon-icons-svelte";
3 import { hidden, tabinfo } from "../Content/Editor/scripts/Tabs";
4 import { line_column } from "../Content/Editor/scripts/Editor";
5 + import { invoke } from "@tauri-apps/api/tauri";
6 + import { homeDir } from '@tauri-apps/api/path';
7 + import { filetree } from "../FileTree/scripts/TreeStore";
8 </script>
9
10 <div id="footer">
@@ -9,9 +13,19 @@
13 <span>Nucleus</span>
14 </div>
15 </div>
16 + <div id="tools">
17 + <span class="terminal-button tool" on:click={async() => {
18 + let userpath = await homeDir();
19 + if ($filetree.length > 0) {
20 + userpath = $filetree[0].path;
21 + }
22 + // opens terminal externally for the time being
23 + invoke("open_terminal", {path: userpath});
24 + }}><Terminal /> <span class="toolname">Terminal</span></span>
25 + </div>
26 {#if !$hidden}
27 <div id="codeinfo">
14 - <span>Line {$line_column.line}, Col {$line_column.col}</span>
28 + <span>{$line_column.line} : {$line_column.col}</span>
29 <span>{$tabinfo}</span>
30 </div>
31 {/if}
@@ -38,6 +52,33 @@
52 align-items: center;
53 flex-grow: 1;
54 }
55 + #tools {
56 + display: flex;
57 + align-items: center;
58 + justify-content: flex-start;
59 + padding: 0 7px;
60 + height: 100%;
61 + }
62 + #tools span {
63 + display: flex;
64 + align-items: center;
65 + justify-content: center;
66 + }
67 + #tools .tool:hover {
68 + background-color: #b1b1b133;
69 + cursor: pointer;
70 + }
71 + .tool {
72 + height: 100%;
73 + padding: 0 5px;
74 + }
75 + .toolname {
76 + margin-left: 5px;
77 + }
78 + :global(#tools span svg) {
79 + width: 18px;
80 + height: 18px;
81 + }
82 #codeinfo span {
83 padding: 0 7px;
84 }