Skip to content

Commit

Permalink
cli: add +boo command
Browse files Browse the repository at this point in the history
Add a `+boo` command to show the animation from the website. The data
for the frames is compressed during the build process. This build step
was added to the SharedDeps object because it is used in both
libghostty and in binaries.

The compression is done as follows:
- All files are concatenated together using \x01 as a combining byte
- The files are compressed to a cached build file
- A zig file is written to stdout which `@embedFile`s the compressed
  file and exposes it to the importer
- A new anonymous module "framedata" is added in the SharedDeps object

Any file can import framedata and access the compressed bytes via
`framedata.compressed`. In the `boo` command, we decompress the file and
split it into frames for use in the animation.

The overall addition to the binary size is:

before = 34_486_400 b
after  = 35_394_288 b
---------------------
total  =  + 907_888 b

The compressed file ends up at 85_409 bytes. I am not sure why the
binary ends up so much larger, perhaps usage of `std.compress.flate`?
  • Loading branch information
rockorager committed Jan 9, 2025
1 parent 12ce9f2 commit f16cd47
Show file tree
Hide file tree
Showing 242 changed files with 10,175 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
.lazy = true,
},
.vaxis = .{
.url = "git+https://github.com/rockorager/libvaxis/?ref=main#6d729a2dc3b934818dffe06d2ba3ce02841ed74b",
.hash = "12200df4ebeaed45de26cb2c9f3b6f3746d8013b604e035dae658f86f586c8c91d2f",
.url = "git+https://github.com/rockorager/libvaxis#2237a7059eae99e9f132dd5acd1555e49d6c7d93",
.hash = "1220f5aec880d4f430cc1597ede88f1530da69e39a4986080e976b0c7b919c2ebfeb",
},
.z2d = .{
.url = "git+https://github.com/vancluever/z2d?ref=v0.4.0#4638bb02a9dc41cc2fb811f092811f6a951c752a",
Expand Down
37 changes: 37 additions & 0 deletions src/build/GhosttyFrameData.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! GhosttyFrameData generates a compressed file and zig module which contains (and exposes) the
//! Ghostty animation frames for use in `ghostty +boo`
const GhosttyFrameData = @This();

const std = @import("std");
const Config = @import("Config.zig");
const SharedDeps = @import("SharedDeps.zig");

/// The exe.
exe: *std.Build.Step.Compile,

/// The output path for the compressed framedata zig file
output: std.Build.LazyPath,

pub fn init(b: *std.Build) !GhosttyFrameData {
const exe = b.addExecutable(.{
.name = "framegen",
.root_source_file = b.path("src/build/framegen/main.zig"),
.target = b.host,
});

const run = b.addRunArtifact(exe);

_ = run.addOutputFileArg("framedata.compressed");
return .{
.exe = exe,
.output = run.captureStdOut(),
};
}

/// Add the "framedata" import.
pub fn addImport(self: *const GhosttyFrameData, step: *std.Build.Step.Compile) void {
self.output.addStepDependencies(&step.step);
step.root_module.addAnonymousImport("framedata", .{
.root_source_file = self.output,
});
}
4 changes: 4 additions & 0 deletions src/build/SharedDeps.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ const Config = @import("Config.zig");
const HelpStrings = @import("HelpStrings.zig");
const MetallibStep = @import("MetallibStep.zig");
const UnicodeTables = @import("UnicodeTables.zig");
const GhosttyFrameData = @import("GhosttyFrameData.zig");

config: *const Config,

options: *std.Build.Step.Options,
help_strings: HelpStrings,
metallib: ?*MetallibStep,
unicode_tables: UnicodeTables,
framedata: GhosttyFrameData,

/// Used to keep track of a list of file sources.
pub const LazyPathList = std.ArrayList(std.Build.LazyPath);
Expand All @@ -22,6 +24,7 @@ pub fn init(b: *std.Build, cfg: *const Config) !SharedDeps {
.config = cfg,
.help_strings = try HelpStrings.init(b, cfg),
.unicode_tables = try UnicodeTables.init(b),
.framedata = try GhosttyFrameData.init(b),

// Setup by retarget
.options = undefined,
Expand Down Expand Up @@ -495,6 +498,7 @@ pub fn add(

self.help_strings.addImport(step);
self.unicode_tables.addImport(step);
self.framedata.addImport(step);

return static_libs;
}
Expand Down
41 changes: 41 additions & 0 deletions src/build/framegen/frames/frame_001.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@


<span class="b">+++==*%%%%%%%%%%%%*==+++</span>
<span class="b">++****++</span> <span class="b">++****++</span>
<span class="b">++**++</span> <span class="b">++**++</span>
<span class="b">xx**+=</span> o+*%$@@@@@@$%*+o <span class="b">=+**xx</span>
<span class="b">xx**oo</span> ·=$@@@@@@@$$$$$$$$@@@@@@@$=· <span class="b">oo**xx</span>
<span class="b">xx**</span> x$@@@$$$$$$$$$$$$$$$$$$$$$$$$@@@$x <span class="b">**xx</span>
<span class="b">ox**</span> ·$@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@@$· <span class="b">**xo</span>
<span class="b">==+~</span> ~@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@@@~ <span class="b">~+==</span>
<span class="b">x+++</span> $@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@$ <span class="b">+++x</span>
<span class="b">==</span> ·@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@@· <span class="b">==</span>
<span class="b">ox++</span> ~@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@~ <span class="b">++xo</span>
<span class="b">+++~</span> @$$$$$@@@@@@@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@ <span class="b">~+++</span>
<span class="b">==</span> $$$$$@@%%%%%%$$$$$$$@@@@@$$$@@@@@@@@@@@@@@@@@@@@$$$$$$ <span class="b">==</span>
<span class="b">==</span> @$$$$* $$$$% =$$$$$@ <span class="b">==</span>
<span class="b">==</span> ·$$$$@ x@$@ @$$$$$· <span class="b">==</span>
<span class="b">==</span> ·@$$$$% ·$$$$% *$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$@@$%%$$$$$$@@@@@@@@$$$$@@@@@@@@@@@@@@@@@@@@$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$@@@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ~$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$~ <span class="b">==</span>
<span class="b">==</span> @@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@@ <span class="b">==</span>
<span class="b">==x·</span> $@@$$$$$$$$$@@@@@@@@@@$$$$$$$$@@@@@@@@@@$$$$$$$$$@@$ <span class="b">·+==</span>
<span class="b">++++</span> =@@@@@@@@@* x$@@@@@@@@$x *@@@@@@@@@= <span class="b">++++</span>
<span class="b">xx==++</span> <span class="b">++==oo</span>
<span class="b">++===+</span> <span class="b">++%%+o</span> <span class="b">o+%%++</span> <span class="b">+===++</span>
<span class="b">++=====%+=++++*=*========***++++***========*=*++++=+%=====++</span>
<span class="b">xx++==******====++</span> <span class="b">++==********==++</span> <span class="b">++====******==++xx</span>
<span class="b">++++</span> <span class="b">++++</span> <span class="b">++++</span>

41 changes: 41 additions & 0 deletions src/build/framegen/frames/frame_002.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

<span class="b">++++++++++++</span>
<span class="b">++==*%%%**=++++++=**%%%*==++</span>
<span class="b">++**=*</span> <span class="b">*=**++</span>
<span class="b">x+**+=</span> <span class="b">=+**+x</span>
<span class="b">++==</span> o=%@@@@@@@@@@@@@@@@%=o <span class="b">==++</span>
<span class="b">===+</span> +$@@@@@$$$$$$$$$$$$$$$$@@@@@$+ <span class="b">+===</span>
<span class="b">++=+</span> =@@@@$$$$$$$$$$$$$$$$$$$$$$$$$$@@@@= <span class="b">+=++</span>
<span class="b">++==</span> $@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@@$ <span class="b">==++</span>
<span class="b">**</span> $@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@@$ <span class="b">**</span>
<span class="b">+++o</span> +@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@@+ <span class="b">o+++</span>
<span class="b">==</span> %@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@% <span class="b">==</span>
<span class="b">xx++</span> %@$$$$@@@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@% <span class="b">++xx</span>
<span class="b">==+·</span> x@$$$@@%=*%$$@@@@@@@@@@@$$$$$@@@@@@@@@@@@@@@@@@$$$$$@x <span class="b">·+==</span>
<span class="b">==</span> @$$$$% ~$@$$$@= x@$$$$$@ <span class="b">==</span>
<span class="b">==</span> $$$$@* %$$@· @$$$$$ <span class="b">==</span>
<span class="b">==</span> ·@$$$@* $$$$+ $$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$~ ~ox+=%@@$$$@@*==============*$@$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$@@@@@@@@@@@@@@@@@$$$$$$$@@@@@@@@@@@@@@@@$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@· <span class="b">==</span>
<span class="b">==</span> ~$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$~ <span class="b">==</span>
<span class="b">==</span> ·@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@ <span class="b">==</span>
<span class="b">==</span> $@$$$$$$$$$$$$$$@@@@$$$$$$$$$$$$$$@@@@$$$$$$$$$$$$$$@$ <span class="b">==</span>
<span class="b">==+o</span> +@@@$$$$$$$@@@$***%@@@@$$$$$$@@@@%***$@@@$$$$$$$@@@+ <span class="b">o+==</span>
<span class="b">++==</span> ·=$@@@@@$*~ +%@@@@@@%+ ~*$@@@@@$=· <span class="b">==++</span>
<span class="b">===+</span> <span class="b">+===</span>
<span class="b">++====x+</span> <span class="b">*=**==</span> <span class="b">==**=*</span> <span class="b">+x====++</span>
<span class="b">++=====**%******=========**%****%**=========******%**=====++</span>
<span class="b">++++========++xx</span> <span class="b">++++========++++</span> <span class="b">xx++========++++</span>


Loading

0 comments on commit f16cd47

Please sign in to comment.