mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-08-24 16:11:43 +00:00
terminal: add isTextMime helper for plain text MIME type names
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
const std = @import("std");
|
||||
|
||||
/// The clipboard destination for a write.
|
||||
pub const Location = enum(c_int) {
|
||||
standard = 0,
|
||||
@@ -6,6 +8,21 @@ pub const Location = enum(c_int) {
|
||||
_,
|
||||
};
|
||||
|
||||
/// MIME types that name plain text across the platforms terminals run
|
||||
/// on. We accept the union everywhere since serving text under any of these
|
||||
/// names is harmless.
|
||||
pub fn isTextMime(mime: []const u8) bool {
|
||||
const names: []const []const u8 = &.{
|
||||
"text/plain",
|
||||
"text/plain;charset=utf-8",
|
||||
"UTF8_STRING",
|
||||
"TEXT",
|
||||
"STRING",
|
||||
};
|
||||
for (names) |n| if (std.mem.eql(u8, mime, n)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// A single representation of clipboard data.
|
||||
///
|
||||
/// The MIME type and data are borrowed and only valid for the duration of a
|
||||
@@ -34,3 +51,11 @@ pub const WriteResult = enum(c_int) {
|
||||
io_error = 5,
|
||||
_,
|
||||
};
|
||||
|
||||
test isTextMime {
|
||||
const testing = std.testing;
|
||||
try testing.expect(isTextMime("text/plain"));
|
||||
try testing.expect(isTextMime("UTF8_STRING"));
|
||||
try testing.expect(!isTextMime("image/png"));
|
||||
try testing.expect(!isTextMime("."));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user