Support Windows
Build a windows-x64 binary and add install.ps1. The editor, browser links, paths, clipboard images and t3tui upgrade all learn Windows' way of doing things; t3tui tmux says it needs WSL.
This commit is contained in:
1 parent
2845b6fe2b
commit
df2c8e0907
23 files changed
+355
-72
No files matched your search
@@ -117,3 +117,15 @@ describe("pasted paths", () => {
|
||||
expect(pastedImagePath("", null)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
test("a dropped Windows file keeps its backslashes", () => {
|
||||
expect(pastedImagePath('"C:\\Users\\me\\shot.png"', null)).toBe("C:\\Users\\me\\shot.png");
|
||||
expect(pastedImagePath("file:///C:/Users/me/my%20shot.png", null)).toBe("C:/Users/me/my shot.png");
|
||||
expect(pastedImagePath("C:\\Users\\me\\notes.txt", null)).toBeNull();
|
||||
});
|
||||
|
||||
test("on Windows, the clipboard's image comes through PowerShell as base64", () => {
|
||||
const [tool] = clipboardImageCommands("win32");
|
||||
expect(tool?.read("image/png")[0]).toBe("powershell.exe");
|
||||
expect(tool?.decode?.(new TextEncoder().encode("iVBORw==\r\n"))).toEqual(Buffer.from([0x89, 0x50, 0x4e, 0x47]));
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import { expect, test } from "bun:test";
|
||||
|
||||
import { isNvim, windowsCommand, windowsWords } from "../src/ui/editor.ts";
|
||||
|
||||
test("splits a Windows command line on spaces outside quotes", () => {
|
||||
expect(windowsWords('"C:\\Program Files\\Git\\usr\\bin\\vim.exe" -p')).toEqual(["C:\\Program Files\\Git\\usr\\bin\\vim.exe", "-p"]);
|
||||
expect(windowsWords("code --wait")).toEqual(["code", "--wait"]);
|
||||
});
|
||||
|
||||
test("runs a .cmd through cmd, and anything else as it is", () => {
|
||||
const which = (program: string) => ({ code: "C:\\VS Code\\bin\\code.cmd", nvim: "C:\\nvim\\nvim.exe" })[program] ?? null;
|
||||
expect(windowsCommand("code --wait", which)).toEqual(["cmd.exe", "/c", "C:\\VS Code\\bin\\code.cmd", "--wait"]);
|
||||
expect(windowsCommand("nvim", which)).toEqual(["C:\\nvim\\nvim.exe"]);
|
||||
expect(windowsCommand("missing", which)).toEqual(["missing"]);
|
||||
});
|
||||
|
||||
test("knows Neovim by name or path", () => {
|
||||
expect(isNvim("nvim")).toBe(true);
|
||||
expect(isNvim("/usr/bin/nvim")).toBe(true);
|
||||
expect(isNvim("C:\\Program Files\\Neovim\\bin\\nvim.exe")).toBe(true);
|
||||
expect(isNvim("vim")).toBe(false);
|
||||
});
|
||||
+26
-1
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
import { isWebUrl, pathAt } from "../src/model/links.ts";
|
||||
import { browserCommand, isWebUrl, pathAt } from "../src/model/links.ts";
|
||||
|
||||
const at = (text: string, word: string) => pathAt(text, text.indexOf(word));
|
||||
|
||||
@@ -34,3 +34,28 @@ describe("paths in text", () => {
|
||||
expect(isWebUrl("src/ui/App.tsx")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("on Windows", () => {
|
||||
test("finds paths with backslashes and drives", () => {
|
||||
const text = "see src\\ui\\App.tsx:12 and C:\\Users\\me\\notes.md, or ..\\a.ts";
|
||||
expect(pathAt(text, text.indexOf("App"), "win32")).toBe("src\\ui\\App.tsx");
|
||||
expect(pathAt(text, text.indexOf("Users"), "win32")).toBe("C:\\Users\\me\\notes.md");
|
||||
expect(pathAt(text, text.indexOf("a.ts"), "win32")).toBe("..\\a.ts");
|
||||
});
|
||||
|
||||
test("leaves URLs and line numbers alone", () => {
|
||||
expect(pathAt("https://example.com/a", 12, "win32")).toBeNull();
|
||||
expect(pathAt("at a:b/c.ts", 8, "win32")).toBeNull();
|
||||
});
|
||||
|
||||
test("backslashes are not path characters elsewhere", () => {
|
||||
expect(pathAt("src\\ui\\App.tsx", 8, "linux")).toBe("App.tsx");
|
||||
});
|
||||
});
|
||||
|
||||
test("opens the browser the platform's way, past cmd's reach on Windows", () => {
|
||||
const url = "https://example.com/?a=1&b=2";
|
||||
expect(browserCommand(url, "linux")).toEqual(["xdg-open", url]);
|
||||
expect(browserCommand(url, "darwin")).toEqual(["open", url]);
|
||||
expect(browserCommand(url, "win32")).toEqual(["rundll32.exe", "url.dll,FileProtocolHandler", url]);
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import { expect, test } from "bun:test";
|
||||
|
||||
import { isWindowsAbsolute, tildify } from "../src/model/paths.ts";
|
||||
|
||||
test("shortens the home folder, on either kind of slash", () => {
|
||||
expect(tildify("/home/me/projects", "/home/me")).toBe("~/projects");
|
||||
expect(tildify("/home/me", "/home/me")).toBe("~");
|
||||
expect(tildify("/home/mean/projects", "/home/me")).toBe("/home/mean/projects");
|
||||
expect(tildify("C:\\Users\\me\\projects", "C:\\Users\\me")).toBe("~\\projects");
|
||||
expect(tildify("C:\\Users\\mean", "C:\\Users\\me")).toBe("C:\\Users\\mean");
|
||||
});
|
||||
|
||||
test("knows a Windows absolute path", () => {
|
||||
expect(isWindowsAbsolute("C:\\a.png")).toBe(true);
|
||||
expect(isWindowsAbsolute("c:/a.png")).toBe(true);
|
||||
expect(isWindowsAbsolute("\\\\server\\share\\a.png")).toBe(true);
|
||||
expect(isWindowsAbsolute("/a.png")).toBe(false);
|
||||
expect(isWindowsAbsolute("a.png")).toBe(false);
|
||||
});
|
||||
+36
-1
@@ -1,9 +1,44 @@
|
||||
import { expect, test } from "bun:test";
|
||||
|
||||
import { assetName, checksumFor, isCompiled } from "../src/upgrade.ts";
|
||||
import { existsSync, mkdtempSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { assetName, checksumFor, isCompiled, isEmbeddedPath, removeOldBinaries, replaceBinary } from "../src/upgrade.ts";
|
||||
|
||||
test("names the release asset for a platform", () => {
|
||||
expect(assetName("darwin", "arm64")).toBe("t3tui-darwin-arm64");
|
||||
expect(assetName("win32", "x64")).toBe("t3tui-windows-x64.exe");
|
||||
});
|
||||
|
||||
test("knows Bun's embedded filesystem on every platform", () => {
|
||||
expect(isEmbeddedPath("/$bunfs/root/t3tui-linux-x64")).toBe(true);
|
||||
expect(isEmbeddedPath("B:\\~BUN\\root\\t3tui-windows-x64.exe")).toBe(true);
|
||||
expect(isEmbeddedPath("B:/~BUN/root/t3tui-windows-x64.exe")).toBe(true);
|
||||
expect(isEmbeddedPath("/home/me/t3tui/src/upgrade.ts")).toBe(false);
|
||||
expect(isEmbeddedPath("C:\\t3tui\\src\\upgrade.ts")).toBe(false);
|
||||
});
|
||||
|
||||
test("on Windows, moves the old binary aside and removes it on the next start", async () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "t3tui-upgrade-"));
|
||||
const target = join(dir, "t3tui.exe");
|
||||
writeFileSync(target, "old");
|
||||
writeFileSync(join(dir, "notes.txt"), "mine");
|
||||
await replaceBinary(target, new TextEncoder().encode("new"), "win32");
|
||||
expect(readFileSync(target, "utf8")).toBe("new");
|
||||
expect(readdirSync(dir).filter((name) => name.includes(".old-"))).toHaveLength(1);
|
||||
removeOldBinaries(target);
|
||||
expect(readdirSync(dir).sort()).toEqual(["notes.txt", "t3tui.exe"]);
|
||||
});
|
||||
|
||||
test("elsewhere, renames straight over the binary", async () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "t3tui-upgrade-"));
|
||||
const target = join(dir, "t3tui");
|
||||
writeFileSync(target, "old");
|
||||
await replaceBinary(target, new TextEncoder().encode("new"), "linux");
|
||||
expect(readFileSync(target, "utf8")).toBe("new");
|
||||
expect(readdirSync(dir)).toEqual(["t3tui"]);
|
||||
expect(existsSync(`${target}.upgrade-${process.pid}`)).toBe(false);
|
||||
});
|
||||
|
||||
test("reads a hash from a sha256sum listing", () => {
|
||||
|
||||
Reference in new issue
Block a user