8000 feat: add the thokr.jrnxf.co website, where every line is a thokr test you can type by jrnxf · Pull Request #40 · jrnxf/thokr · GitHub
[go: up one dir, main page]

Skip to content
  • Merged
    Show file tree
    Hide file tree
    Changes from all commits
    Commits
    File filter

    Filter by extension

    Filter by extension


    Conversations
    Failed to load comments.
    Loading
    Jump to
    Jump to file
    Failed to load files.
    Loading
    Diff view
    Diff view
    20 changes: 20 additions & 0 deletions .github/workflows/build.yml
    Original file line number Diff line number Diff line change
    Expand Up @@ -48,3 +48,23 @@ jobs:
    - uses: dtolnay/rust-toolchain@stable
    - uses: Swatinem/rust-cache@v2
    - run: cargo test --all

    web:
    name: web
    runs-on: ubuntu-latest
    defaults:
    run:
    working-directory: web
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-node@v4
    with:
    node-version: 24
    cache: npm
    cache-dependency-path: web/package-lock.json
    - run: npm ci
    # builds thokr's src/ to WebAssembly with the toolchain build.sh pins
    - run: ./build.sh
    - run: npx playwright install --with-deps chromium
    # the engine and the chart against thokr's insta snapshots, then the page in Chromium
    - run: npm test
    2 changes: 1 addition & 1 deletion Cargo.toml
    Original file line number Diff line number Diff line change
    Expand Up @@ -9,7 +9,7 @@ license = "MIT"
    authors = ["Colby Thomas <colby@jrnxf.co>"]
    edition = "2024"
    rust-version = "1.88"
    exclude = [".github", "*.log", "plans", "assets"]
    exclude = [".github", "*.log", "plans", "assets", "web"]
    keywords = ["tui", "terminal", "typing"]

    [dependencies]
    Expand Down
    4 changes: 4 additions & 0 deletions web/.gitignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    /dist
    /node_modules
    /.wrangler
    /test-results
    23 changes: 23 additions & 0 deletions web/README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    # thokr.jrnxf.co

    The website: one page where every line is a thokr prompt you can type. The tests are run by
    thokr itself: `engine/` compiles thokr's own `src/` (the test loop, the screen and the word lists)
    to WebAssembly, and the page sends it keys, as `main.rs` does in a terminal.

    - `public/`: the page, its scripts in `kit/` and DM Mono.
    - `engine/`: the WebAssembly build of thokr, with a small C ABI in place of `main.rs`.
    - `build.sh`: builds everything into `dist/`. It installs Rust when it is missing.
    - `test/`: checks the engine and `kit/chart.js` against thokr's insta snapshots, and types
    through the page in Chromium.

    ```sh
    cd web
    npm ci
    ./build.sh
    npx playwright install chromium
    npm test
    npx wrangler dev # serves dist on localhost
    ```

    It deploys to thokr.jrnxf.co with Cloudflare Workers Builds: the build command is `./build.sh`, the
    deploy command `npx wrangler deploy`, and the root directory `web`. `wrangler.jsonc` holds the rest.
    105 changes: 105 additions & 0 deletions web/THIRD_PARTY.md
    8 10BC8
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,105 @@
    # Third-party notices

    ## Fonts

    `public/fonts/dm-mono-400.woff2` and `public/fonts/dm-mono-500.woff2` are the latin subsets of DM
    Mono Regular and Medium, as Google Fonts serves them, unaltered.

    DM Mono, by Colophon Foundry: <https://github.com/googlefonts/dm-mono>. It is under the SIL Open
    Font License, Version 1.1:

    ```
    Copyright 2020 The DM Mono Project Authors (https://www.github.com/googlefonts/dm-mono)

    This Font Software is licensed under the SIL Open Font License, Version 1.1.
    This license is copied below, and is also available with a FAQ at:
    http://scripts.sil.org/OFL


    -----------------------------------------------------------
    SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
    -----------------------------------------------------------

    PREAMBLE
    The goals of the Open Font License (OFL) are to stimulate worldwide
    development of collaborative font projects, to support the font creation
    efforts of academic and linguistic communities, and to provide a free and
    open framework in which fonts may be shared and improved in partnership
    with others.

    The OFL allows the licensed fonts to be used, studied, modified and
    redistributed freely as long as they are not sold by themselves. The
    fonts, including any derivative works, can be bundled, embedded,
    redistributed and/or sold with any software provided that any reserved
    names are not used by derivative works. The fonts and derivatives,
    however, cannot be released under any other type of license. The
    requirement for fonts to remain under this license does not apply
    to any document created using the fonts or their derivatives.

    DEFINITIONS
    "Font Software" refers to the set of files released by the Copyright
    Holder(s) under this license and clearly marked as such. This may
    include source files, build scripts and documentation.

    "Reserved Font Name" refers to any names specified as such after the
    copyright statement(s).

    "Original Version" refers to the collection of Font Software components as
    distributed by the Copyright Holder(s).

    "Modified Version" refers to any derivative made by adding to, deleting,
    or substituting -- in part or in whole -- any of the components of the
    Original Version, by changing formats or by porting the Font Software to a
    new environment.

    "Author" refers to any designer, engineer, programmer, technical
    writer or other person who contributed to the Font Software.

    PERMISSION & CONDITIONS
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of the Font Software, to use, study, copy, merge, embed, modify,
    redistribute, and sell modified and unmodified copies of the Font
    Software, subject to the following conditions:

    1) Neither the Font Software nor any of its individual components,
    in Original or Modified Versions, may be sold by itself.

    2) Original or Modified Versions of the Font Software may be bundled,
    redistributed and/or sold with any software, provided that each copy
    contains the above copyright notice and this license. These can be
    included either as stand-alone text files, human-readable headers or
    in the appropriate machine-readable metadata fields within text or
    binary files as long as those fields can be easily viewed by the user.

    3) No Modified Version of the Font Software may use the Reserved Font
    Name(s) unless explicit written permission is granted by the corresponding
    Copyright Holder. This restriction only applies to the primary font name as
    presented to the users.

    4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
    Software shall not be used to promote, endorse or advertise any
    Modified Version, except to acknowledge the contribution(s) of the
    Copyright Holder(s) and the Author(s) or with their explicit written
    permission.

    5) The Font Software, modified or unmodified, in part or in whole,
    must be distributed entirely under this license, and must not be
    distributed under any other license. The requirement for fonts to
    remain under this license does not apply to any document created
    using the Font Software.

    TERMINATION
    This license becomes null and void if any of the above conditions are
    not met.

    DISCLAIMER
    THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
    OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
    COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
    INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
    DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
    OTHER DEALINGS IN THE FONT SOFTWARE.
    ```
    66 changes: 66 additions & 0 deletions web/build.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    #!/bin/sh
    # Builds the website into web/dist: the page from web/public, and its engine,
    # thokr's own Rust (src/) compiled to WebAssembly from this checkout, named by
    # its content so browsers can keep it for good. The word lists come with it:
    # lang.rs includes src/lang/*.txt.
    #
    # It runs as is in Cloudflare's Workers Builds, whose image has no Rust: it then
    # installs rustup, at the version and checksum below, and the toolchain.
    set -eu

    RUST_VERSION=1.99.1
    RUSTUP_VERSION=1.29.2
    # from https://static.rust-lang.org/rustup/archive/$RUSTUP_VERSION/x86_64-unknown-linux-gnu/rustup-init.sha256
    RUSTUP_INIT_SHA256=5be191e8c70a5007074254cb74d78dbfdd25cd5a61c27de7b8e5410122ec24f4

    web=$(cd "$(dirname "$0")" && pwd)
    root=$(dirname "$web")

    sha256() {
    if command -v sha256sum >/dev/null; then sha256sum "$1"; else shasum -a 256 "$1"; fi | cut -d ' ' -f 1
    }

    if ! command -v rustup >/dev/null; then
    cargo_home=${CARGO_HOME:-$HOME/.cargo}
    if [ ! -x "$cargo_home/bin/rustup" ]; then
    case "$(uname -s)-$(uname -m)" in
    Linux-x86_64) ;;
    *) echo "build.sh needs rustup; see https://rustup.rs" >&2; exit 1 ;;
    esac
    # rustup-init reads its own file name, so it must keep it
    tmp=$(mktemp -d)
    trap 'rm -rf "$tmp"' EXIT
    init=$tmp/rustup-init
    echo "Installing rustup $RUSTUP_VERSION"
    curl -sSfL --retry 3 -o "$init" \
    "https://static.rust-lang.org/rustup/archive/$RUSTUP_VERSION/x86_64-unknown-linux-gnu/rustup-init"
    if [ "$(sha256 "$init")" != "$RUSTUP_INIT_SHA256" ]; then
    echo "rustup-init does not match its checksum" >&2
    exit 1
    fi
    chmod +x "$init"
    "$init" -y --no-modify-path --profile minimal --default-toolchain none
    fi
    PATH=$cargo_home/bin:$PATH
    fi
    rustup toolchain install "$RUST_VERSION" --profile minimal --target wasm32-wasip1

    target=$root/target/web
    rustup run "$RUST_VERSION" cargo build --release --locked --target wasm32-wasip1 \
    --manifest-path "$web/engine/Cargo.toml" --target-dir "$target"

    dist=$web/dist
    rm -rf "$dist"
    mkdir -p "$dist"
    cp -R "$web/public/." "$dist/"
    engine=$target/wasm32-wasip1/release/thokr_web_engine.wasm
    wasm=thokr.$(sha256 "$engine" | cut -c 1-16).wasm
    cp "$engine" "$dist/kit/$wasm"
    version=$(sed -n 's/^version = "\(.*\)"$/\1/p' "$root/Cargo.toml" | head -n 1)
    sed "s/__THOKR_WASM__/$wasm/" "$web/public/kit/engine.js" > "$dist/kit/engine.js"
    sed "s/__THOKR_VERSION__/$version/" "$web/public/index.html" > "$dist/index.html"
    if grep -rq "__THOKR_" "$dist"; then
    echo "a placeholder was left in dist" >&2
    exit 1
    fi
    ls -lR "$dist"
    Loading
    Loading
    0