mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
libuv: starting Tty impl
This commit is contained in:
@ -295,7 +295,7 @@ test "Command: pre exec" {
|
||||
.path = "/usr/bin/env",
|
||||
.args = &.{ "/usr/bin/env", "--version" },
|
||||
.pre_exec = (struct {
|
||||
fn do() void {
|
||||
fn do(_: *Command) void {
|
||||
// This runs in the child, so we can exit and it won't
|
||||
// kill the test runner.
|
||||
os.exit(42);
|
||||
|
46
src/libuv/Tty.zig
Normal file
46
src/libuv/Tty.zig
Normal file
@ -0,0 +1,46 @@
|
||||
//! Tty handles represent a stream for the console.
|
||||
const Tty = @This();
|
||||
|
||||
const std = @import("std");
|
||||
const fd_t = std.os.fd_t;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const testing = std.testing;
|
||||
const c = @import("c.zig");
|
||||
const errors = @import("error.zig");
|
||||
const Loop = @import("Loop.zig");
|
||||
const Handle = @import("handle.zig").Handle;
|
||||
const Pty = @import("../Pty.zig");
|
||||
|
||||
handle: *c.uv_tty_t,
|
||||
|
||||
pub usingnamespace Handle(Tty);
|
||||
|
||||
pub fn init(alloc: Allocator, loop: Loop, fd: fd_t) !Tty {
|
||||
var tty = try alloc.create(c.uv_tty_t);
|
||||
errdefer alloc.destroy(tty);
|
||||
try errors.convertError(c.uv_tty_init(loop.loop, tty, fd, 0));
|
||||
return Tty{ .handle = tty };
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Tty, alloc: Allocator) void {
|
||||
alloc.destroy(self.handle);
|
||||
self.* = undefined;
|
||||
}
|
||||
|
||||
test "Tty" {
|
||||
var pty = try Pty.open(.{
|
||||
.ws_row = 20,
|
||||
.ws_col = 80,
|
||||
.ws_xpixel = 0,
|
||||
.ws_ypixel = 0,
|
||||
});
|
||||
defer pty.deinit();
|
||||
|
||||
var loop = try Loop.init(testing.allocator);
|
||||
defer loop.deinit(testing.allocator);
|
||||
var tty = try init(testing.allocator, loop, pty.slave);
|
||||
defer tty.deinit(testing.allocator);
|
||||
|
||||
tty.close(null);
|
||||
_ = try loop.run(.default);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
pub const Loop = @import("Loop.zig");
|
||||
pub const Async = @import("Async.zig");
|
||||
pub const Timer = @import("Timer.zig");
|
||||
pub const Tty = @import("Tty.zig");
|
||||
pub const Sem = @import("Sem.zig");
|
||||
pub const Thread = @import("Thread.zig");
|
||||
pub const Error = @import("error.zig").Error;
|
||||
@ -13,6 +14,7 @@ test {
|
||||
_ = Loop;
|
||||
_ = Async;
|
||||
_ = Timer;
|
||||
_ = Tty;
|
||||
_ = Sem;
|
||||
_ = Thread;
|
||||
_ = Error;
|
||||
|
Reference in New Issue
Block a user