Skip to content

Configuration using dynamically linked shared libraries #1358

@LordMZTE

Description

@LordMZTE

An approach I've seen many projects (such as rofi) take for plugins, which I'm a huge fan of, is loading dynamic libraries in a certain directory (could be the config dir for example).
Ghostty could utilize this as a way for advanced users to configure their terminal.

Why this makes sense

  1. Ghostty already has many of its types being C-compatible (for libghostty and the macOS apprt). This would mean that this is pretty low-effort to implement.
  2. Users may be more comfortable writing Zig or C than Ghostty's own configuration format. I myself had trouble staring at configuration lines that were giving me an error, unable to figure out why (yes, that's a separate problem, but the general point still holds :D).
  3. Keybinds could be given custom callbacks (function pointers) to do essentially anything.
  4. This would elegantly fix API for managing windows / tabs / splits #601 — such a config, or perhaps plugin is a better word, could implement some wire protocol, but that might not even be necessary depending on the use case.
  5. Microoptimization nuts like me will get a kick out of it :P

How to implement this

  1. Export relevant symbols and create headers (this is probably done already). A Zig client library could also be considered, but this isn't really a must.
  2. Discover plugins: search for dynamic library files (Linux: .so, Windows: .dll, macOS: no idea). This could just be the config directory, but also a subdirectory or somewhere entirely different.
  3. For each library - note that Zig has abstractions for both dlopen and dlsym (see: std.DynLib):
    • dlopen it (need to dlclose on shutdown)
    • Load and call some well-defined entry point symbol from it using dlsym. This could be ghostty_plugin_open, for example.
    • Plugins can now call into ghostty's API to do whatever.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions