Commit Graph

48 Commits (main)

Author SHA1 Message Date
Mitchell Hashimoto 83a4f32a14
terminal: formatter improvements for color handling 2025-10-30 10:39:46 -07:00
Mitchell Hashimoto 799e4bca50
example/zig-formatter: fix build for new palette API 2025-10-30 10:07:44 -07:00
Mitchell Hashimoto 4a88976ef9
example/zig-formatter: show how to use formatters from libghostty (#9407) 2025-10-29 21:28:52 -07:00
Mitchell Hashimoto 7d7c0bf5cd
lib-vt: Wasm SGR helpers and example (#9362)
This adds some convenience functions for parsing SGR sequences
WebAssembly and adds an example demonstrating SGR parsing in the
browser.
2025-10-26 13:19:55 -07:00
Mitchell Hashimoto a82ad89ef3
lib-vt: C API for SGR parser (#9352)
This exposes the SGR parser to the C and Wasm APIs. An example is shown
in c-vt-sgr.

Compressed example:

```c
#include <assert.h>
#include <stdio.h>
#include <ghostty/vt.h>

int main() {
  // Create parser
  GhosttySgrParser parser;
  assert(ghostty_sgr_new(NULL, &parser) == GHOSTTY_SUCCESS);

  // Parse: ESC[1;31m (bold + red foreground)
  uint16_t params[] = {1, 31};
  assert(ghostty_sgr_set_params(parser, params, NULL, 2) == GHOSTTY_SUCCESS);

  printf("Parsing: ESC[1;31m\n\n");

  // Iterate through attributes
  GhosttySgrAttribute attr;
  while (ghostty_sgr_next(parser, &attr)) {
    switch (attr.tag) {
      case GHOSTTY_SGR_ATTR_BOLD:
        printf("✓ Bold enabled\n");
        break;
      case GHOSTTY_SGR_ATTR_FG_8:
        printf("✓ Foreground color: %d (red)\n", attr.value.fg_8);
        break;
      default:
        break;
    }
  }

  ghostty_sgr_free(parser);
  return 0;
}
```

**AI disclosure:** Amp wrote most of the C headers, but I verified it
all. https://ampcode.com/threads/T-d9f145cb-e6ef-48a8-ad63-e5fc85c0d43e
2025-10-25 21:26:06 -07:00
Mitchell Hashimoto 580262c96f
terminal: add ReadonlyStream that updates terminal state (#9346)
This adds a new stream handler implementation that updates terminal
state in reaction to VT sequences, but doesn't perform any of the
actions that would require responses (e.g. queries).

This is exposed in two ways: first, as a standalone `ReadonlyStream` and
`ReadonlyHandler` type that contains all the implementation. Second, as
a convenience func on `Terminal` as `vtStream` and `vtHandler` which
return their respective types preconfigured to update the calling
terminal state.

This dramatically simplifies libghostty-vt usage from Zig (and will
eventually be exposed to C, too) since a Terminal on its own is ready to
go as a full VT parser and state machine without needing to build any
custom types!

There's a second big bonus here which is that our `stream_readonly.zig`
tests are true end-to-end tests for raw bytes to terminal state. This
will let us test a wider variety of situations more broadly. To start,
there are only a handful of tests implemented here.

**AI disclosure:** Amp wrote basically this whole thing, but I reviewed
it. https://ampcode.com/threads/T-3490efd2-1137-4112-96f6-4bf8a0141ff5
2025-10-25 14:52:33 -07:00
Mitchell Hashimoto 66486901f5
examples/wasm-key-encode: update README 2025-10-23 12:49:38 -07:00
Mitchell Hashimoto c133fac7e7
lib-vt: wasm convenience functions and a simple example (#9309)
This adds a set of Wasm convenience functions to ease memory management.
These are all prefixed with `ghostty_wasm` and are documented as part of
the standard Doxygen docs.

I also added a very simple single-page HTML example that demonstrates
how to use the Wasm module for key encoding.

This also adds a bunch of safety checks to the C API to verify that
valid values are actually passed to the function. This is an easy to hit
bug.

**AI disclosure:** The example is AI-written with Amp. I read through
all the code and understand it but I can't claim there isn't a better
way, I'm far from a JS expert. It is simple and works currently though.
Happy to see improvements if anyone wants to contribute.
2025-10-22 14:25:52 -07:00
Mitchell Hashimoto bf9f025aec
lib-vt: begin paste utilities exports starting with safe paste 2025-10-06 21:09:28 -07:00
Mitchell Hashimoto 61fe78c1d3
lib-vt: expose key encoding as a C API 2025-10-05 14:40:20 -07:00
Mitchell Hashimoto 22caf60263
update a bunch of required Zig versions to 0.15 2025-10-03 07:10:44 -07:00
Mitchell Hashimoto 3bc07c24aa
lib-vt: OSC data extraction boilerplate
This also changes OSC strings to be null-terminated to ease lib-vt
integration. This shouldn't have any practical effect on terminal
performance, but it does lower the maximum length of OSC strings by 1
since we always reserve space for the null terminator.
2025-09-29 06:40:01 -07:00
Mitchell Hashimoto a76297058f
example/c-vt: parse a full OSC command 2025-09-28 07:24:09 -07:00
Mitchell Hashimoto 37e238c2f6
remove vt prefixes 2025-09-24 12:36:50 -07:00
Mitchell Hashimoto 96e9053862
move header into subdirectory 2025-09-24 12:30:37 -07:00
Mitchell Hashimoto 48827b21d8
some PR feedback 2025-09-24 12:25:43 -07:00
Mitchell Hashimoto e7a0198103
lib-vt: docs 2025-09-24 10:46:24 -07:00
Mitchell Hashimoto 2c78ad8889
lib-vt: setup a default allocator if null 2025-09-24 10:30:13 -07:00
Mitchell Hashimoto e1429dabae
example/c-vt 2025-09-24 09:54:08 -07:00
Mitchell Hashimoto f97518cc10
example/zig-vt: add comment explaining how to get zero-dep build 2025-09-23 11:55:44 -07:00
Mitchell Hashimoto 64f26c14d3
example/zig-vt 2025-09-21 19:41:58 -07:00
Mitchell Hashimoto 1758f962f6
remove stale example wasm app 2025-09-21 19:40:00 -07:00
Mitchell Hashimoto 162f3390ca
prettier 2024-09-11 11:15:46 -07:00
Qwerasd 10b8ca3c69 spelling: normalize grey -> gray 2024-08-11 18:31:01 -04:00
Mitchell Hashimoto 779611c04b
nix: install prettier, also ignore zig-cache/out 2023-09-28 15:16:12 -07:00
Patrick Fong c2ec3f75ad lint JSON and Typescript as well 2023-09-28 11:05:54 -07:00
Mitchell Hashimoto ce490e21ea
can specify a wasm target in build 2022-12-31 08:53:11 -08:00
Mitchell Hashimoto 1093cf5254
config: enable passwd isn't compiled for wasm 2022-12-30 16:32:49 -08:00
Mitchell Hashimoto 241bfee7d4
wasm: use shared, imported memory
This switches our wasm build to use "shared" memory. Shared memory can
be shared across multiple web workers, which is something we'll want to
support for our multi-threaded behaviors later.

Shared memory has a number of different restrictions so this updates
zig-js to support it as well as updates some of our functions that need
to be aware of it.
2022-12-24 16:24:43 -08:00
Mitchell Hashimoto c391d0f3de
font: web canvas sprite font can composite 2022-12-13 22:17:27 -08:00
Mitchell Hashimoto bf054e5b44
font: web canvas sprite font can write to atlas 2022-12-13 22:01:13 -08:00
Mitchell Hashimoto 0ab8eff069
update example to show multi-codepoint grapheme 2022-12-12 22:05:27 -08:00
Mitchell Hashimoto f53d9fb704
font: web canvas shaper yields runs 2022-12-07 18:29:49 -08:00
Mitchell Hashimoto 6aa212707e
font: web canvas can render emoji 2022-12-06 10:55:42 -08:00
Mitchell Hashimoto 41cbc1a323
wasm: show color atlas in example web app 2022-12-05 21:33:54 -08:00
Mitchell Hashimoto 5993528f33
font: GroupCache is wasm compatible 2022-12-05 21:01:56 -08:00
Mitchell Hashimoto 62990bb33e
font: Group is now wasm-compatible 2022-12-05 20:52:03 -08:00
Mitchell Hashimoto 5291501251
font: DeferredFace is wasm-compatible 2022-12-05 20:28:50 -08:00
Mitchell Hashimoto d2afddb7e2
font: fix some JS memory leaks 2022-12-05 15:45:31 -08:00
Mitchell Hashimoto ed4e8c36b0
font: add 1 to the canvas glyph to avoid clipping 2022-12-05 15:37:55 -08:00
Mitchell Hashimoto 25f2f1a652
font: fix glyph offset calculations for render 2022-12-05 15:25:09 -08:00
Mitchell Hashimoto 5e9dd02eab
font: add method for drawing atlas to canvas 2022-12-05 15:01:34 -08:00
Mitchell Hashimoto 19e326dab6
font: working on rendering glyphs in canvas 2022-12-05 10:54:40 -08:00
Mitchell Hashimoto df302fc2b6
calculate font metrics via canvas 2022-12-04 22:01:58 -08:00
Mitchell Hashimoto c48d8cd151
hook up logging to wasm, example uses new zig-js package 2022-12-04 13:16:54 -08:00
Mitchell Hashimoto c32219554a
blank out web canvas impl 2022-12-01 13:02:17 -08:00
Mitchell Hashimoto b858aea124
Start scaffolding web_canvas backend 2022-12-01 13:02:17 -08:00
Mitchell Hashimoto 2457454b07
test wasm of the term package 2022-08-17 13:57:21 -07:00