feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set: - servers: saved servers, passwordless and password login, proxy, self-signed certificates, per-server device tokens (Keystore), connect form, instance list sheet with switch/disconnect - sessions: virtualized list, search, new session, rename/archive/delete, running indicator, event stream keeps it live - chat: pushed window with system back bar, streaming Markdown via ui/markdown, reasoning and tool rows with image previews, footer menu (read aloud via a Kotlin TTS plugin, copy, fork), user message menu (copy, revert, fork), context usage ring and detail sheet, attachments (photos/files via the document picker), permissions - release builds allow plain http:// LAN servers (Go's net/http dials directly, no cleartext manifest needed) - a local fork of MyGo (third_party/mygo) lowers the Android host's minSdk to 24 (Android 7.0); Go 1.27.4 via mise Version 0.3.0.
This commit is contained in:
1 parent
2fb4a8ea79
commit
6c0ee61750
2538 files changed
+675779
-4792
No files matched your search
@@ -0,0 +1,206 @@
|
||||
// Libbuild builds libghostty-vt for every platform MyGo supports from
|
||||
// Ghostty's sources at a commit, with Zig (the version Ghostty asks for),
|
||||
// and writes mygo-plugin.json, which names the files and their SHA-256 for
|
||||
// the CLI and the terminal package, and ghostty_themes.go, the themes that
|
||||
// Ghostty ships:
|
||||
//
|
||||
// go generate ./plugins/terminal
|
||||
//
|
||||
// With -themes, it only writes the themes, which needs no Zig.
|
||||
//
|
||||
// The files go into plugins/terminal/build, to publish as the assets of the
|
||||
// release libghostty-vt-<commit>, which mygo-plugin.json points at:
|
||||
//
|
||||
// gh release create libghostty-vt-<commit> plugins/terminal/build/* --latest=false ...
|
||||
//
|
||||
// macOS's libraries are linked by Apple's linker when Xcode is installed,
|
||||
// which the build of Ghostty prefers, so build them on a Mac.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"debug/elf"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// commit is the commit of Ghostty this package binds.
|
||||
const commit = "befcdfd2c3a1cb24d9ec886e93c95b2b5daa7028"
|
||||
|
||||
var targets = []struct {
|
||||
goos, goarch, zig string
|
||||
// name is the file in apps; built is where Zig puts it.
|
||||
name, built string
|
||||
}{
|
||||
{"darwin", "arm64", "aarch64-macos", "libghostty-vt.dylib", "lib/libghostty-vt.dylib"},
|
||||
{"darwin", "amd64", "x86_64-macos", "libghostty-vt.dylib", "lib/libghostty-vt.dylib"},
|
||||
// The glibc of Debian 10 and Ubuntu 20.04, and later.
|
||||
{"linux", "amd64", "x86_64-linux-gnu.2.28", "libghostty-vt.so", "lib/libghostty-vt.so"},
|
||||
{"linux", "arm64", "aarch64-linux-gnu.2.28", "libghostty-vt.so", "lib/libghostty-vt.so"},
|
||||
{"windows", "amd64", "x86_64-windows-gnu", "ghostty-vt.dll", "bin/ghostty-vt.dll"},
|
||||
{"windows", "arm64", "aarch64-windows-gnu", "ghostty-vt.dll", "bin/ghostty-vt.dll"},
|
||||
}
|
||||
|
||||
func main() {
|
||||
src := flag.String("src", "", "a checkout of Ghostty, at the commit (cloned into the user's cache when empty)")
|
||||
out := flag.String("out", "build", "the directory of the libraries")
|
||||
release := flag.String("release", "https://github.com/egoist/mygo/releases/download/libghostty-vt-"+commit[:12], "the URL of the release hosting the libraries")
|
||||
themes := flag.Bool("themes", false, "only write the themes")
|
||||
flag.Parse()
|
||||
if *themes {
|
||||
writeThemes(*src)
|
||||
return
|
||||
}
|
||||
if *src == "" {
|
||||
*src = checkout()
|
||||
}
|
||||
if err := os.MkdirAll(*out, 0o755); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
files := map[string]map[string]string{}
|
||||
for _, t := range targets {
|
||||
prefix, err := os.MkdirTemp("", "libghostty-vt-")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(prefix)
|
||||
log.Printf("building %s/%s", t.goos, t.goarch)
|
||||
run(*src, "zig", "build", "-Demit-lib-vt", "-Dtarget="+t.zig, "-Doptimize=ReleaseFast", "-Dstrip=true", "--prefix", prefix)
|
||||
ext := filepath.Ext(t.name)
|
||||
asset := fmt.Sprintf("libghostty-vt-%s-%s%s", t.goos, t.goarch, ext)
|
||||
built := filepath.Join(prefix, t.built)
|
||||
if t.goos == "linux" {
|
||||
// The build keeps the debug information of ELF libraries,
|
||||
// four fifths of them.
|
||||
built = stripELF(built)
|
||||
}
|
||||
sum := copyFile(built, filepath.Join(*out, asset))
|
||||
files[t.goos+"-"+t.goarch] = map[string]string{"name": t.name, "url": *release + "/" + asset, "sha256": sum}
|
||||
}
|
||||
manifest := map[string]any{"libraries": []any{map[string]any{
|
||||
"name": "libghostty-vt",
|
||||
"source": "https://github.com/ghostty-org/ghostty/tree/" + commit,
|
||||
"files": files,
|
||||
}}}
|
||||
data, err := json.MarshalIndent(manifest, "", " ")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile("mygo-plugin.json", append(data, '\n'), 0o644); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("wrote mygo-plugin.json; publish %s as the assets of %s", *out, *release)
|
||||
writeThemes(*src)
|
||||
}
|
||||
|
||||
// checkout returns a checkout of Ghostty at the commit in the user's
|
||||
// cache, cloning or fetching it.
|
||||
func checkout() string {
|
||||
cache, err := os.UserCacheDir()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
dir := filepath.Join(cache, "mygo", "ghostty-src")
|
||||
if _, err := os.Stat(filepath.Join(dir, ".git")); err != nil {
|
||||
run("", "git", "clone", "--filter=blob:none", "https://github.com/ghostty-org/ghostty", dir)
|
||||
} else {
|
||||
run(dir, "git", "fetch", "origin")
|
||||
}
|
||||
run(dir, "git", "checkout", "--detach", commit)
|
||||
return dir
|
||||
}
|
||||
|
||||
func run(dir, name string, args ...string) {
|
||||
cmd := exec.Command(name, args...)
|
||||
cmd.Dir = dir
|
||||
cmd.Stdout, cmd.Stderr = os.Stderr, os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Fatalf("%s %s: %v", name, strings.Join(args, " "), err)
|
||||
}
|
||||
}
|
||||
|
||||
// copyFile copies src, following links, to dst and returns its SHA-256.
|
||||
func copyFile(src, dst string) string {
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer in.Close()
|
||||
f, err := os.Create(dst)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
h := sha256.New()
|
||||
if _, err := io.Copy(io.MultiWriter(f, h), in); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
// stripELF writes a copy of the ELF library at path without the contents
|
||||
// of its debug sections, as `strip --strip-debug` would, and returns its
|
||||
// path. What loading uses (the segments, and the sections in them) stays
|
||||
// in place; the other sections after the segments move down, and the
|
||||
// debug sections keep their headers, empty, so that no index changes.
|
||||
func stripELF(path string) string {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
f, err := elf.NewFile(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if f.Class != elf.ELFCLASS64 || f.Data != elf.ELFDATA2LSB {
|
||||
log.Fatalf("%s: not a 64-bit little-endian ELF file", path)
|
||||
}
|
||||
end := uint64(0)
|
||||
for _, p := range f.Progs {
|
||||
end = max(end, p.Off+p.Filesz)
|
||||
}
|
||||
out := append([]byte(nil), data[:end]...)
|
||||
le := binary.LittleEndian
|
||||
shoff := le.Uint64(data[0x28:])
|
||||
shentsize, shnum := uint64(le.Uint16(data[0x3a:])), uint64(le.Uint16(data[0x3c:]))
|
||||
headers := append([]byte(nil), data[shoff:shoff+shentsize*shnum]...)
|
||||
for i, s := range f.Sections {
|
||||
h := headers[uint64(i)*shentsize:]
|
||||
if s.Type == elf.SHT_NULL || s.Type == elf.SHT_NOBITS || s.Flags&elf.SHF_ALLOC != 0 || s.Offset < end {
|
||||
continue
|
||||
}
|
||||
size := s.FileSize
|
||||
if strings.HasPrefix(s.Name, ".debug") || strings.HasPrefix(s.Name, ".zdebug") {
|
||||
size = 0
|
||||
}
|
||||
align := max(s.Addralign, 1)
|
||||
for uint64(len(out))%align != 0 {
|
||||
out = append(out, 0)
|
||||
}
|
||||
le.PutUint64(h[0x18:], uint64(len(out))) // sh_offset
|
||||
le.PutUint64(h[0x20:], size) // sh_size
|
||||
out = append(out, data[s.Offset:s.Offset+size]...)
|
||||
}
|
||||
for len(out)%8 != 0 {
|
||||
out = append(out, 0)
|
||||
}
|
||||
le.PutUint64(out[0x28:], uint64(len(out))) // e_shoff
|
||||
out = append(out, headers...)
|
||||
stripped := path + ".stripped"
|
||||
if err := os.WriteFile(stripped, out, 0o755); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return stripped
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"bufio"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// themesFile is the Go file with the themes Ghostty ships.
|
||||
const themesFile = "ghostty_themes.go"
|
||||
|
||||
// themeKeys are the keys of a theme of Ghostty's after its palette, in the
|
||||
// order of ghosttyTheme's colors.
|
||||
var themeKeys = []string{"background", "foreground", "cursor-color", "cursor-text", "selection-background", "selection-foreground"}
|
||||
|
||||
// themesLicense is the license of the themes, iTerm2-Color-Schemes'.
|
||||
const themesLicense = `MIT License
|
||||
|
||||
Copyright (c) 2011 to Present Mark Badolato
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
This license covers the iTerm-Color-Schemes repository collection of themes.
|
||||
The copyright/license for each individual theme belongs to the author of that theme.`
|
||||
|
||||
// writeThemes writes the themes that the Ghostty at the commit ships, from
|
||||
// the archive its build.zig.zon names, into themesFile: from the checkout
|
||||
// src, else from GitHub.
|
||||
func writeThemes(src string) {
|
||||
var zon []byte
|
||||
if src != "" {
|
||||
var err error
|
||||
if zon, err = os.ReadFile(filepath.Join(src, "build.zig.zon")); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
zon = fetch("https://raw.githubusercontent.com/ghostty-org/ghostty/" + commit + "/build.zig.zon")
|
||||
}
|
||||
m := regexp.MustCompile(`\.iterm2_themes\s*=\s*\.\{\s*\.url\s*=\s*"([^"]+)"`).FindSubmatch(zon)
|
||||
if m == nil {
|
||||
log.Fatal("build.zig.zon names no iterm2_themes")
|
||||
}
|
||||
url := string(m[1])
|
||||
log.Printf("reading the themes of %s", url)
|
||||
gz, err := gzip.NewReader(bytes.NewReader(fetch(url)))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
type theme struct {
|
||||
name string
|
||||
colors [22]uint32
|
||||
}
|
||||
var themes []theme
|
||||
tr := tar.NewReader(gz)
|
||||
for {
|
||||
h, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
dir, name := path.Split(h.Name)
|
||||
if h.Typeflag != tar.TypeReg || path.Clean(dir) != "ghostty" {
|
||||
continue
|
||||
}
|
||||
data, err := io.ReadAll(tr)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
colors, err := parseTheme(data)
|
||||
if err != nil {
|
||||
log.Fatalf("theme %q: %v", name, err)
|
||||
}
|
||||
themes = append(themes, theme{name, colors})
|
||||
}
|
||||
if len(themes) == 0 {
|
||||
log.Fatal("the archive has no themes")
|
||||
}
|
||||
slices.SortFunc(themes, func(a, b theme) int { return strings.Compare(a.name, b.name) })
|
||||
var b bytes.Buffer
|
||||
b.WriteString("// Code generated by go generate (internal/libbuild); DO NOT EDIT.\n\npackage terminal\n\n")
|
||||
fmt.Fprintf(&b, "// ghosttyThemes are the themes the Ghostty this package binds ships, from\n// iTerm2-Color-Schemes (https://github.com/mbadolato/iTerm2-Color-Schemes),\n// as %s has them:\n//\n", path.Base(url))
|
||||
for line := range strings.Lines(themesLicense) {
|
||||
b.WriteString(strings.TrimRight("//\t"+line, " \t\n") + "\n")
|
||||
}
|
||||
b.WriteString("var ghosttyThemes = [...]ghosttyTheme{\n")
|
||||
for _, t := range themes {
|
||||
fmt.Fprintf(&b, "\t{%s, [22]uint32{", strconv.Quote(t.name))
|
||||
for i, c := range t.colors {
|
||||
if i > 0 {
|
||||
b.WriteString(", ")
|
||||
}
|
||||
fmt.Fprintf(&b, "0x%06x", c)
|
||||
}
|
||||
b.WriteString("}},\n")
|
||||
}
|
||||
b.WriteString("}\n")
|
||||
src2, err := format.Source(b.Bytes())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(themesFile, src2, 0o644); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("wrote %d themes into %s", len(themes), themesFile)
|
||||
}
|
||||
|
||||
// parseTheme reads the colors of a theme Ghostty ships, which sets each
|
||||
// of them in #rrggbb: anything else is an error, for the terminal package
|
||||
// to read it.
|
||||
func parseTheme(data []byte) ([22]uint32, error) {
|
||||
var colors [22]uint32
|
||||
set := map[int]bool{}
|
||||
sc := bufio.NewScanner(bytes.NewReader(data))
|
||||
for sc.Scan() {
|
||||
line := strings.TrimSpace(sc.Text())
|
||||
if line == "" || line[0] == '#' {
|
||||
continue
|
||||
}
|
||||
key, value, ok := strings.Cut(line, "=")
|
||||
if !ok {
|
||||
return colors, fmt.Errorf("%q sets nothing", line)
|
||||
}
|
||||
key, value = strings.TrimSpace(key), strings.TrimSpace(value)
|
||||
i := slices.Index(themeKeys, key) + 16
|
||||
if key == "palette" {
|
||||
index, c, _ := strings.Cut(value, "=")
|
||||
n, err := strconv.Atoi(strings.TrimSpace(index))
|
||||
if err != nil || n < 0 || n > 255 {
|
||||
return colors, fmt.Errorf("%q is no palette entry", value)
|
||||
}
|
||||
if n >= 16 {
|
||||
continue
|
||||
}
|
||||
i, value = n, strings.TrimSpace(c)
|
||||
} else if i < 16 {
|
||||
return colors, fmt.Errorf("unknown key %q", key)
|
||||
}
|
||||
hex, ok := strings.CutPrefix(value, "#")
|
||||
v, err := strconv.ParseUint(hex, 16, 32)
|
||||
if !ok || len(hex) != 6 || err != nil {
|
||||
return colors, fmt.Errorf("%s is %q, not #rrggbb", key, value)
|
||||
}
|
||||
colors[i], set[i] = uint32(v), true
|
||||
}
|
||||
if len(set) != len(colors) {
|
||||
return colors, fmt.Errorf("sets %d colors of %d", len(set), len(colors))
|
||||
}
|
||||
return colors, sc.Err()
|
||||
}
|
||||
|
||||
func fetch(url string) []byte {
|
||||
res, err := http.Get(url)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK {
|
||||
log.Fatalf("%s: %s", url, res.Status)
|
||||
}
|
||||
data, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return data
|
||||
}
|
||||
Reference in new issue
Block a user