clean up uncessary hacks

This commit is contained in:
Gabriel Dinner-David
2024-11-24 15:50:05 -05:00
parent 487f3dabc7
commit 0ff5e5635d
15 changed files with 60 additions and 76 deletions

View File

@ -73,13 +73,11 @@ fetch(url.href)
run(config_str.ptr, config_str.len); run(config_str.ptr, config_str.len);
await new Promise((resolve) => setTimeout(resolve, 500)) await new Promise((resolve) => setTimeout(resolve, 500))
const io = new Uint8ClampedArray(stdin, 4); const io = new Uint8ClampedArray(stdin, 4);
const text = new TextEncoder().encode("hello world\n\r"); const text = new TextEncoder().encode("hello world\r\n");
io.set(text); io.set(text);
const n = new Int32Array(stdin); const n = new Int32Array(stdin);
console.error("storing");
Atomics.store(n, 0, text.length) Atomics.store(n, 0, text.length)
Atomics.notify(n, 0); Atomics.notify(n, 0);
console.error("done storing");
function drawing() { function drawing() {
requestAnimationFrame(() => { requestAnimationFrame(() => {
draw(); draw();
@ -88,14 +86,13 @@ fetch(url.href)
} }
drawing() drawing()
setTimeout(() => { setInterval(() => {
const text = new TextEncoder().encode("🐏\n\r👍🏽\n\rM_ghostty\033[2;2H\033[48;2;240;40;40m\033[38;2;23;255;80mhello"); // const text = new TextEncoder().encode("🐏\n\r👍🏽\n\rM_ghostty\033[2;2H\033[48;2;240;40;40m\033[38;2;23;255;80mhello");
const text = new TextEncoder().encode("🐏\r\n👍🏽\r\nM_ghostty\033[48;2;240;40;40m\033[38;2;23;255;80mhello\r\n");
const n = new Int32Array(stdin); const n = new Int32Array(stdin);
console.error("storing");
const place = Atomics.add(n, 0, text.length) const place = Atomics.add(n, 0, text.length)
const io = new Uint8ClampedArray(stdin, 4 + place); const io = new Uint8ClampedArray(stdin, 4 + place);
io.set(text); io.set(text);
Atomics.notify(n, 0); Atomics.notify(n, 0);
console.error("done storing");
}, 5000) }, 5000)
}) })

View File

@ -795,6 +795,7 @@ export const importObject = {
const read = Math.min(iov_len, bytes.length); const read = Math.min(iov_len, bytes.length);
const io = new Uint8ClampedArray(zjs.memory.buffer, iov_base, iov_len); const io = new Uint8ClampedArray(zjs.memory.buffer, iov_base, iov_len);
io.set(bytes.slice(0, read)); io.set(bytes.slice(0, read));
console.error(bytes[read-1]);
bytes = bytes.slice(read); bytes = bytes.slice(read);
if (bytes.length === 0) bytes = null; if (bytes.length === 0) bytes = null;
nwritten += read; nwritten += read;

View File

@ -619,9 +619,9 @@ enum {
#ifndef SIMDUTF_IMPLEMENTATION_H #ifndef SIMDUTF_IMPLEMENTATION_H
#define SIMDUTF_IMPLEMENTATION_H #define SIMDUTF_IMPLEMENTATION_H
#include <string> #include <string>
// #if !defined(SIMDUTF_NO_THREADS) #if !defined(SIMDUTF_NO_THREADS)
// #include <atomic> #include <atomic>
// #endif #endif
#include <vector> #include <vector>
#include <tuple> #include <tuple>
/* begin file include/simdutf/internal/isadetection.h */ /* begin file include/simdutf/internal/isadetection.h */
@ -3692,7 +3692,7 @@ class atomic_ptr {
public: public:
atomic_ptr(T *_ptr) : ptr{_ptr} {} atomic_ptr(T *_ptr) : ptr{_ptr} {}
// #if defined(SIMDUTF_NO_THREADS) #if defined(SIMDUTF_NO_THREADS)
operator const T*() const { return ptr; } operator const T*() const { return ptr; }
const T& operator*() const { return *ptr; } const T& operator*() const { return *ptr; }
const T* operator->() const { return ptr; } const T* operator->() const { return ptr; }
@ -3702,24 +3702,24 @@ public:
T* operator->() { return ptr; } T* operator->() { return ptr; }
atomic_ptr& operator=(T *_ptr) { ptr = _ptr; return *this; } atomic_ptr& operator=(T *_ptr) { ptr = _ptr; return *this; }
// #else #else
// operator const T*() const { return ptr.load(); } operator const T*() const { return ptr.load(); }
// const T& operator*() const { return *ptr; } const T& operator*() const { return *ptr; }
// const T* operator->() const { return ptr.load(); } const T* operator->() const { return ptr.load(); }
// operator T*() { return ptr.load(); } operator T*() { return ptr.load(); }
// T& operator*() { return *ptr; } T& operator*() { return *ptr; }
// T* operator->() { return ptr.load(); } T* operator->() { return ptr.load(); }
// atomic_ptr& operator=(T *_ptr) { ptr = _ptr; return *this; } atomic_ptr& operator=(T *_ptr) { ptr = _ptr; return *this; }
// #endif #endif
private: private:
// #if defined(SIMDUTF_NO_THREADS) #if defined(SIMDUTF_NO_THREADS)
T* ptr; T* ptr;
// #else #else
// std::atomic<T*> ptr; std::atomic<T*> ptr;
// #endif #endif
}; };
class detect_best_supported_implementation_on_first_use; class detect_best_supported_implementation_on_first_use;

View File

@ -64,7 +64,7 @@ font_grid_set: font.SharedGridSet,
// Used to rate limit desktop notifications. Some platforms (notably macOS) will // Used to rate limit desktop notifications. Some platforms (notably macOS) will
// run out of resources if desktop notifications are sent too fast and the OS // run out of resources if desktop notifications are sent too fast and the OS
// will kill Ghostty. // will kill Ghostty.
last_notification_time: ?internal_os.Instant = null, last_notification_time: ?std.time.Instant = null,
last_notification_digest: u64 = 0, last_notification_digest: u64 = 0,
/// The conditional state of the configuration. See the equivalent field /// The conditional state of the configuration. See the equivalent field

View File

@ -21,6 +21,7 @@ const assert = std.debug.assert;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const ArenaAllocator = std.heap.ArenaAllocator; const ArenaAllocator = std.heap.ArenaAllocator;
const global_state = &@import("global.zig").state; const global_state = &@import("global.zig").state;
const oni = @import("oniguruma");
const crash = @import("crash/main.zig"); const crash = @import("crash/main.zig");
const unicode = @import("unicode/main.zig"); const unicode = @import("unicode/main.zig");
const renderer = @import("renderer.zig"); const renderer = @import("renderer.zig");
@ -173,7 +174,7 @@ const Mouse = struct {
/// The left click time was the last time the left click was done. This /// The left click time was the last time the left click was done. This
/// is always set on the first left click. /// is always set on the first left click.
left_click_count: u8 = 0, left_click_count: u8 = 0,
left_click_time: internal_os.Instant = undefined, left_click_time: std.time.Instant = undefined,
/// The last x/y sent for mouse reports. /// The last x/y sent for mouse reports.
event_point: ?terminal.point.Coordinate = null, event_point: ?terminal.point.Coordinate = null,
@ -255,7 +256,7 @@ const DerivedConfig = struct {
links: []Link, links: []Link,
const Link = struct { const Link = struct {
regex: input.Link.Regex, regex: oni.Regex,
action: input.Link.Action, action: input.Link.Action,
highlight: input.Link.Highlight, highlight: input.Link.Highlight,
}; };
@ -2723,7 +2724,7 @@ pub fn mouseButtonCallback(
// If we are within the interval that the click would register // If we are within the interval that the click would register
// an increment then we do not extend the selection. // an increment then we do not extend the selection.
if (internal_os.Instant.now()) |now| { if (std.time.Instant.now()) |now| {
const since = now.since(self.mouse.left_click_time); const since = now.since(self.mouse.left_click_time);
if (since <= self.config.mouse_interval) { if (since <= self.config.mouse_interval) {
// Click interval very short, we may be increasing // Click interval very short, we may be increasing
@ -2869,7 +2870,7 @@ pub fn mouseButtonCallback(
self.mouse.left_click_ypos = pos.y; self.mouse.left_click_ypos = pos.y;
// Setup our click counter and timer // Setup our click counter and timer
if (internal_os.Instant.now()) |now| { if (std.time.Instant.now()) |now| {
// If we have mouse clicks, then we check if the time elapsed // If we have mouse clicks, then we check if the time elapsed
// is less than and our interval and if so, increase the count. // is less than and our interval and if so, increase the count.
if (self.mouse.left_click_count > 0) { if (self.mouse.left_click_count > 0) {
@ -4477,7 +4478,7 @@ fn showDesktopNotification(self: *Surface, title: [:0]const u8, body: [:0]const
// how fast identical notifications can be sent sequentially. // how fast identical notifications can be sent sequentially.
const hash_algorithm = std.hash.Wyhash; const hash_algorithm = std.hash.Wyhash;
const now = try internal_os.Instant.now(); const now = try std.time.Instant.now();
// Set a limit of one desktop notification per second so that the OS // Set a limit of one desktop notification per second so that the OS
// doesn't kill us when we run out of resources. // doesn't kill us when we run out of resources.

View File

@ -127,18 +127,20 @@ pub const Artifact = enum {
wasm_module, wasm_module,
pub fn detect() Artifact { pub fn detect() Artifact {
// assert(builtin.output_mode == .Obj); if (builtin.target.isWasm()) {
// assert(builtin.link_mode == .Static); // assert(builtin.output_mode == .Obj);
return .wasm_module; // assert(builtin.link_mode == .Static);
return .wasm_module;
}
// return switch (builtin.output_mode) { return switch (builtin.output_mode) {
// .Exe => .exe, .Exe => .exe,
// .Lib => .lib, .Lib => .lib,
// else => { else => {
// @compileLog(builtin.output_mode); @compileLog(builtin.output_mode);
// @compileError("unsupported artifact output mode"); @compileError("unsupported artifact output mode");
// }, },
// }; };
} }
}; };

View File

@ -8,8 +8,6 @@ const oni = @import("oniguruma");
const Mods = @import("key.zig").Mods; const Mods = @import("key.zig").Mods;
const builtin = @import("builtin"); const builtin = @import("builtin");
pub const Regex = oni.Regex;
/// The regular expression that will be used to match the link. Ownership /// The regular expression that will be used to match the link. Ownership
/// of this memory is up to the caller. The link will never free this memory. /// of this memory is up to the caller. The link will never free this memory.
regex: []const u8, regex: []const u8,

View File

@ -44,16 +44,3 @@ pub const clickInterval = mouse.clickInterval;
pub const open = openpkg.open; pub const open = openpkg.open;
pub const pipe = pipepkg.pipe; pub const pipe = pipepkg.pipe;
pub const resourcesDir = resourcesdir.resourcesDir; pub const resourcesDir = resourcesdir.resourcesDir;
pub const Instant = if (true) std.time.Instant else struct {
pub fn now() !@This() {
return .{};
}
pub fn order(self: *const Instant, other: Instant) std.math.Order {
_ = self;
_ = other;
return .eq;
}
};
pub fn sleep(nanosecond: u64) void {
_ = nanosecond;
}

View File

@ -1,20 +1,19 @@
const std = @import("std"); const std = @import("std");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const oni = @import("oniguruma");
const configpkg = @import("../config.zig"); const configpkg = @import("../config.zig");
const inputpkg = @import("../input.zig"); const inputpkg = @import("../input.zig");
const terminal = @import("../terminal/main.zig"); const terminal = @import("../terminal/main.zig");
const point = terminal.point; const point = terminal.point;
const Screen = terminal.Screen; const Screen = terminal.Screen;
const Terminal = terminal.Terminal; const Terminal = terminal.Terminal;
const builtin = @import("builtin");
const js = @import("zig-js");
const log = std.log.scoped(.renderer_link); const log = std.log.scoped(.renderer_link);
/// The link configuration needed for renderers. /// The link configuration needed for renderers.
pub const Link = struct { pub const Link = struct {
/// The regular expression to match the link against. /// The regular expression to match the link against.
regex: inputpkg.Link.Regex, regex: oni.Regex,
/// The situations in which the link should be highlighted. /// The situations in which the link should be highlighted.
highlight: inputpkg.Link.Highlight, highlight: inputpkg.Link.Highlight,

View File

@ -2,7 +2,6 @@ const std = @import("std");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const gl = @import("opengl"); const gl = @import("opengl");
const Size = @import("../size.zig").Size; const Size = @import("../size.zig").Size;
const internal_os = @import("../../os/main.zig");
const log = std.log.scoped(.opengl_custom); const log = std.log.scoped(.opengl_custom);
@ -48,11 +47,11 @@ pub const State = struct {
/// The first time a frame was drawn. This is used to update /// The first time a frame was drawn. This is used to update
/// the time uniform. /// the time uniform.
first_frame_time: internal_os.Instant, first_frame_time: std.time.Instant,
/// The last time a frame was drawn. This is used to update /// The last time a frame was drawn. This is used to update
/// the time uniform. /// the time uniform.
last_frame_time: internal_os.Instant, last_frame_time: std.time.Instant,
pub fn init( pub fn init(
alloc: Allocator, alloc: Allocator,
@ -140,8 +139,8 @@ pub const State = struct {
.vao = vao, .vao = vao,
.ebo = ebo, .ebo = ebo,
.fb_texture = fb_tex, .fb_texture = fb_tex,
.first_frame_time = try internal_os.Instant.now(), .first_frame_time = try std.time.Instant.now(),
.last_frame_time = try internal_os.Instant.now(), .last_frame_time = try std.time.Instant.now(),
}; };
} }
@ -184,7 +183,7 @@ pub const State = struct {
/// this. /// this.
pub fn newFrame(self: *State) !void { pub fn newFrame(self: *State) !void {
// Update our frame time // Update our frame time
const now = internal_os.Instant.now() catch self.first_frame_time; const now = std.time.Instant.now() catch self.first_frame_time;
const since_ns: f32 = @floatFromInt(now.since(self.first_frame_time)); const since_ns: f32 = @floatFromInt(now.since(self.first_frame_time));
const delta_ns: f32 = @floatFromInt(now.since(self.last_frame_time)); const delta_ns: f32 = @floatFromInt(now.since(self.last_frame_time));
self.uniforms.time = since_ns / std.time.ns_per_s; self.uniforms.time = since_ns / std.time.ns_per_s;

View File

@ -35,7 +35,7 @@ pub const Placement = struct {
/// The map used for storing images. /// The map used for storing images.
pub const ImageMap = std.AutoHashMapUnmanaged(u32, struct { pub const ImageMap = std.AutoHashMapUnmanaged(u32, struct {
image: Image, image: Image,
transmit_time: internal_os.Instant, transmit_time: std.time.Instant,
}); });
/// The state for a single image that is to be rendered. The image can be /// The state for a single image that is to be rendered. The image can be

View File

@ -346,7 +346,7 @@ pub const LoadingImage = struct {
} }
// Set our time // Set our time
self.image.transmit_time = internal_os.Instant.now() catch |err| { self.image.transmit_time = std.time.Instant.now() catch |err| {
log.warn("failed to get time: {}", .{err}); log.warn("failed to get time: {}", .{err});
return error.InternalError; return error.InternalError;
}; };
@ -453,7 +453,7 @@ pub const Image = struct {
format: command.Transmission.Format = .rgb, format: command.Transmission.Format = .rgb,
compression: command.Transmission.Compression = .none, compression: command.Transmission.Compression = .none,
data: []const u8 = "", data: []const u8 = "",
transmit_time: internal_os.Instant = undefined, transmit_time: std.time.Instant = undefined,
pub const Error = error{ pub const Error = error{
InternalError, InternalError,

View File

@ -496,7 +496,7 @@ pub const ImageStorage = struct {
// bit is fine compared to the megabytes we're looking to save. // bit is fine compared to the megabytes we're looking to save.
const Candidate = struct { const Candidate = struct {
id: u32, id: u32,
time: internal_os.Instant, time: std.time.Instant,
used: bool, used: bool,
}; };

View File

@ -102,7 +102,7 @@ pub fn threadEnter(
}; };
// Track our process start time for abnormal exits // Track our process start time for abnormal exits
const process_start = try internal_os.Instant.now(); const process_start = try std.time.Instant.now();
// Create our pipe that we'll use to kill our read thread. // Create our pipe that we'll use to kill our read thread.
// pipe[0] is the read end, pipe[1] is the write end. // pipe[0] is the read end, pipe[1] is the write end.
@ -345,7 +345,7 @@ fn processExit(
// Determine how long the process was running for. // Determine how long the process was running for.
const runtime_ms: ?u64 = runtime: { const runtime_ms: ?u64 = runtime: {
const process_end = internal_os.Instant.now() catch break :runtime null; const process_end = std.time.Instant.now() catch break :runtime null;
const runtime_ns = process_end.since(execdata.start); const runtime_ns = process_end.since(execdata.start);
const runtime_ms = runtime_ns / std.time.ns_per_ms; const runtime_ms = runtime_ns / std.time.ns_per_ms;
break :runtime runtime_ms; break :runtime runtime_ms;
@ -603,7 +603,7 @@ pub const ThreadData = struct {
const WRITE_REQ_PREALLOC = std.math.pow(usize, 2, 5); const WRITE_REQ_PREALLOC = std.math.pow(usize, 2, 5);
/// Process start time and boolean of whether its already exited. /// Process start time and boolean of whether its already exited.
start: internal_os.Instant, start: std.time.Instant,
exited: bool = false, exited: bool = false,
/// The number of milliseconds below which we consider a process /// The number of milliseconds below which we consider a process
@ -1288,7 +1288,7 @@ const Subprocess = struct {
const res = posix.waitpid(pid, std.c.W.NOHANG); const res = posix.waitpid(pid, std.c.W.NOHANG);
log.debug("waitpid result={}", .{res.pid}); log.debug("waitpid result={}", .{res.pid});
if (res.pid != 0) break; if (res.pid != 0) break;
internal_os.sleep(10 * std.time.ns_per_ms); std.time.sleep(10 * std.time.ns_per_ms);
} }
}, },
} }
@ -1311,7 +1311,7 @@ const Subprocess = struct {
const pgid = c.getpgid(pid); const pgid = c.getpgid(pid);
if (pgid == my_pgid) { if (pgid == my_pgid) {
log.warn("pgid is our own, retrying", .{}); log.warn("pgid is our own, retrying", .{});
internal_os.sleep(10 * std.time.ns_per_ms); std.time.sleep(10 * std.time.ns_per_ms);
continue; continue;
} }

View File

@ -68,7 +68,7 @@ terminal_stream: terminal.Stream(StreamHandler),
/// Last time the cursor was reset. This is used to prevent message /// Last time the cursor was reset. This is used to prevent message
/// flooding with cursor resets. /// flooding with cursor resets.
last_cursor_reset: ?internal_os.Instant = null, last_cursor_reset: ?std.time.Instant = null,
/// The configuration for this IO that is derived from the main /// The configuration for this IO that is derived from the main
/// configuration. This must be exported so that we don't need to /// configuration. This must be exported so that we don't need to
@ -552,7 +552,7 @@ fn processOutputLocked(self: *Termio, buf: []const u8) void {
// non-blink state so it is rendered if visible. If we're under // non-blink state so it is rendered if visible. If we're under
// HEAVY read load, we don't want to send a ton of these so we // HEAVY read load, we don't want to send a ton of these so we
// use a timer under the covers // use a timer under the covers
if (internal_os.Instant.now()) |now| cursor_reset: { if (std.time.Instant.now()) |now| cursor_reset: {
if (self.last_cursor_reset) |last| { if (self.last_cursor_reset) |last| {
log.err("now: {} last: {}", .{ now, last }); log.err("now: {} last: {}", .{ now, last });
if (now.since(last) <= (500 * std.time.ns_per_ms)) { if (now.since(last) <= (500 * std.time.ns_per_ms)) {