Small refactoring; Disabled window resizing
This commit is contained in:
parent
f86d0e662b
commit
23beb7d12b
@ -1,25 +1,27 @@
|
||||
import { Terminal } from "xterm";
|
||||
|
||||
const term = new Terminal({
|
||||
fontFamily:
|
||||
'"Fira Code", courier-new, courier, monospace, "Powerline Extra Symbols"',
|
||||
});
|
||||
const term = new Terminal();
|
||||
|
||||
let line = "";
|
||||
let command = "";
|
||||
|
||||
term.onKey(({ key, domEvent }) => {
|
||||
const printable = !(domEvent.altKey || domEvent.ctrlKey || domEvent.metaKey);
|
||||
const isPrintable = !(
|
||||
domEvent.altKey ||
|
||||
domEvent.ctrlKey ||
|
||||
domEvent.metaKey
|
||||
);
|
||||
|
||||
if (domEvent.key === "Enter") {
|
||||
//@ts-ignore
|
||||
window.__WRITE_PTY(line);
|
||||
window.__WRITE_PTY(command);
|
||||
term.writeln("");
|
||||
line = "";
|
||||
command = "";
|
||||
return;
|
||||
}
|
||||
|
||||
if (printable) {
|
||||
if (isPrintable) {
|
||||
term.write(key);
|
||||
line += key;
|
||||
command += key;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2,8 +2,5 @@ import { defineConfig } from "vite";
|
||||
import { viteSingleFile } from "vite-plugin-singlefile";
|
||||
|
||||
export default defineConfig({
|
||||
esbuild: {
|
||||
keepNames: true,
|
||||
},
|
||||
plugins: [viteSingleFile()],
|
||||
});
|
||||
|
15
main.go
15
main.go
@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
@ -11,7 +12,7 @@ import (
|
||||
"github.com/webview/webview"
|
||||
)
|
||||
|
||||
type PtyOutEvent struct {
|
||||
type PtyRespEvent struct {
|
||||
Result string `json:"result"`
|
||||
}
|
||||
|
||||
@ -23,7 +24,7 @@ func main() {
|
||||
defer w.Destroy()
|
||||
|
||||
w.SetTitle("Ratatouille")
|
||||
w.SetSize(480, 320, webview.HintNone)
|
||||
w.SetSize(720, 432, webview.HintFixed)
|
||||
|
||||
b, _ := ioutil.ReadFile("frontend/dist/index.html")
|
||||
w.SetHtml(string(b))
|
||||
@ -33,16 +34,18 @@ func main() {
|
||||
})
|
||||
|
||||
go func() {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
for {
|
||||
buf := make([]byte, 1024)
|
||||
n, _ := p.Read(buf)
|
||||
if n == 0 {
|
||||
continue
|
||||
n, err := p.Read(buf)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
|
||||
result := string(buf)
|
||||
event := PtyOutEvent{Result: result[:n]}
|
||||
event := PtyRespEvent{Result: result[:n]}
|
||||
payload, err := json.Marshal(event)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Whoopsie", err)
|
||||
continue
|
||||
|
Loading…
x
Reference in New Issue
Block a user