gemini-browser

A text-based gemini browser
git clone git://git.laack.co/gemini-browser.git
Log | Files | Refs | README

README-wasm.md (1719B)


      1 # WASM for _Tcell_
      2 
      3 You can build _Tcell_ project into a webpage by compiling it slightly differently. This will result in a _Tcell_ project you can embed into another html page, or use as a standalone page.
      4 
      5 ## Building your project
      6 
      7 WASM needs special build flags in order to work. You can build it by executing
      8 ```sh
      9 GOOS=js GOARCH=wasm go build -o yourfile.wasm
     10 ```
     11 
     12 ## Additional files
     13 
     14 You also need 5 other files in the same directory as the wasm. Four (`tcell.html`, `tcell.js`, `termstyle.css`, and `beep.wav`) are provided in the `webfiles` directory. The last one, `wasm_exec.js`, can be copied from GOROOT into the current directory by executing
     15 ```sh
     16 cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" ./
     17 ```
     18 
     19 In `tcell.js`, you also need to change the constant
     20 ```js
     21 const wasmFilePath = "yourfile.wasm"
     22 ```
     23 to the file you outputted to when building.
     24 
     25 ## Displaying your project
     26 
     27 ### Standalone
     28 
     29 You can see the project (with an white background around the terminal) by serving the directory. You can do this using any framework, including another golang project:
     30 
     31 ```golang
     32 // server.go
     33 
     34 package main
     35 
     36 import (
     37 	"log"
     38 	"net/http"
     39 )
     40 
     41 func main() {
     42 	log.Fatal(http.ListenAndServe(":8080",
     43 		http.FileServer(http.Dir("/path/to/dir/to/serve")),
     44 	))
     45 }
     46 
     47 ```
     48 
     49 To see the webpage with this example, you can type in `localhost:8080/tcell.html` into your browser while `server.go` is running.
     50 
     51 ### Embedding
     52 It is recommended to use an iframe if you want to embed the app into a webpage:
     53 ```html
     54 <iframe src="tcell.html" title="Tcell app"></iframe>
     55 ```
     56 
     57 ## Other considerations
     58 
     59 ### Accessing files
     60 
     61 `io.Open(filename)` and other related functions for reading file systems do not work; use `http.Get(filename)` instead.