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