mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
renderer: yeet usingns
This commit is contained in:
@ -12,9 +12,9 @@ const builtin = @import("builtin");
|
|||||||
const build_config = @import("build_config.zig");
|
const build_config = @import("build_config.zig");
|
||||||
const WasmTarget = @import("os/wasm/target.zig").Target;
|
const WasmTarget = @import("os/wasm/target.zig").Target;
|
||||||
|
|
||||||
pub usingnamespace @import("renderer/cursor.zig");
|
const cursor = @import("renderer/cursor.zig");
|
||||||
pub usingnamespace @import("renderer/message.zig");
|
const message = @import("renderer/message.zig");
|
||||||
pub usingnamespace @import("renderer/size.zig");
|
const size = @import("renderer/size.zig");
|
||||||
pub const shadertoy = @import("renderer/shadertoy.zig");
|
pub const shadertoy = @import("renderer/shadertoy.zig");
|
||||||
pub const Metal = @import("renderer/Metal.zig");
|
pub const Metal = @import("renderer/Metal.zig");
|
||||||
pub const OpenGL = @import("renderer/OpenGL.zig");
|
pub const OpenGL = @import("renderer/OpenGL.zig");
|
||||||
@ -22,6 +22,13 @@ pub const WebGL = @import("renderer/WebGL.zig");
|
|||||||
pub const Options = @import("renderer/Options.zig");
|
pub const Options = @import("renderer/Options.zig");
|
||||||
pub const Thread = @import("renderer/Thread.zig");
|
pub const Thread = @import("renderer/Thread.zig");
|
||||||
pub const State = @import("renderer/State.zig");
|
pub const State = @import("renderer/State.zig");
|
||||||
|
pub const CursorStyle = cursor.Style;
|
||||||
|
pub const Message = message.Message;
|
||||||
|
pub const CellSize = size.CellSize;
|
||||||
|
pub const ScreenSize = size.ScreenSize;
|
||||||
|
pub const GridSize = size.GridSize;
|
||||||
|
pub const Padding = size.Padding;
|
||||||
|
pub const cursorStyle = cursor.style;
|
||||||
|
|
||||||
/// Possible implementations, used for build options.
|
/// Possible implementations, used for build options.
|
||||||
pub const Impl = enum {
|
pub const Impl = enum {
|
||||||
|
@ -5,15 +5,15 @@ const State = @import("State.zig");
|
|||||||
/// Available cursor styles for drawing that renderers must support.
|
/// Available cursor styles for drawing that renderers must support.
|
||||||
/// This is a superset of terminal cursor styles since the renderer supports
|
/// This is a superset of terminal cursor styles since the renderer supports
|
||||||
/// some additional cursor states such as the hollow block.
|
/// some additional cursor states such as the hollow block.
|
||||||
pub const CursorStyle = enum {
|
pub const Style = enum {
|
||||||
block,
|
block,
|
||||||
block_hollow,
|
block_hollow,
|
||||||
bar,
|
bar,
|
||||||
underline,
|
underline,
|
||||||
|
|
||||||
/// Create a cursor style from the terminal style request.
|
/// Create a cursor style from the terminal style request.
|
||||||
pub fn fromTerminal(style: terminal.CursorStyle) ?CursorStyle {
|
pub fn fromTerminal(term: terminal.CursorStyle) ?Style {
|
||||||
return switch (style) {
|
return switch (term) {
|
||||||
.bar => .bar,
|
.bar => .bar,
|
||||||
.block => .block,
|
.block => .block,
|
||||||
.underline => .underline,
|
.underline => .underline,
|
||||||
@ -23,11 +23,11 @@ pub const CursorStyle = enum {
|
|||||||
|
|
||||||
/// Returns the cursor style to use for the current render state or null
|
/// Returns the cursor style to use for the current render state or null
|
||||||
/// if a cursor should not be rendered at all.
|
/// if a cursor should not be rendered at all.
|
||||||
pub fn cursorStyle(
|
pub fn style(
|
||||||
state: *State,
|
state: *State,
|
||||||
focused: bool,
|
focused: bool,
|
||||||
blink_visible: bool,
|
blink_visible: bool,
|
||||||
) ?CursorStyle {
|
) ?Style {
|
||||||
// Note the order of conditionals below is important. It represents
|
// Note the order of conditionals below is important. It represents
|
||||||
// a priority system of how we determine what state overrides cursor
|
// a priority system of how we determine what state overrides cursor
|
||||||
// visibility and style.
|
// visibility and style.
|
||||||
@ -57,7 +57,7 @@ pub fn cursorStyle(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we use whatever style the terminal wants.
|
// Otherwise, we use whatever style the terminal wants.
|
||||||
return CursorStyle.fromTerminal(state.terminal.screen.cursor.cursor_style);
|
return Style.fromTerminal(state.terminal.screen.cursor.cursor_style);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "cursor: default uses configured style" {
|
test "cursor: default uses configured style" {
|
||||||
@ -75,10 +75,10 @@ test "cursor: default uses configured style" {
|
|||||||
.preedit = null,
|
.preedit = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
try testing.expect(cursorStyle(&state, true, true) == .bar);
|
try testing.expect(style(&state, true, true) == .bar);
|
||||||
try testing.expect(cursorStyle(&state, false, true) == .block_hollow);
|
try testing.expect(style(&state, false, true) == .block_hollow);
|
||||||
try testing.expect(cursorStyle(&state, false, false) == .block_hollow);
|
try testing.expect(style(&state, false, false) == .block_hollow);
|
||||||
try testing.expect(cursorStyle(&state, true, false) == null);
|
try testing.expect(style(&state, true, false) == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "cursor: blinking disabled" {
|
test "cursor: blinking disabled" {
|
||||||
@ -96,10 +96,10 @@ test "cursor: blinking disabled" {
|
|||||||
.preedit = null,
|
.preedit = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
try testing.expect(cursorStyle(&state, true, true) == .bar);
|
try testing.expect(style(&state, true, true) == .bar);
|
||||||
try testing.expect(cursorStyle(&state, true, false) == .bar);
|
try testing.expect(style(&state, true, false) == .bar);
|
||||||
try testing.expect(cursorStyle(&state, false, true) == .block_hollow);
|
try testing.expect(style(&state, false, true) == .block_hollow);
|
||||||
try testing.expect(cursorStyle(&state, false, false) == .block_hollow);
|
try testing.expect(style(&state, false, false) == .block_hollow);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "cursor: explicitly not visible" {
|
test "cursor: explicitly not visible" {
|
||||||
@ -118,10 +118,10 @@ test "cursor: explicitly not visible" {
|
|||||||
.preedit = null,
|
.preedit = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
try testing.expect(cursorStyle(&state, true, true) == null);
|
try testing.expect(style(&state, true, true) == null);
|
||||||
try testing.expect(cursorStyle(&state, true, false) == null);
|
try testing.expect(style(&state, true, false) == null);
|
||||||
try testing.expect(cursorStyle(&state, false, true) == null);
|
try testing.expect(style(&state, false, true) == null);
|
||||||
try testing.expect(cursorStyle(&state, false, false) == null);
|
try testing.expect(style(&state, false, false) == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "cursor: always block with preedit" {
|
test "cursor: always block with preedit" {
|
||||||
@ -137,18 +137,18 @@ test "cursor: always block with preedit" {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// In any bool state
|
// In any bool state
|
||||||
try testing.expect(cursorStyle(&state, false, false) == .block);
|
try testing.expect(style(&state, false, false) == .block);
|
||||||
try testing.expect(cursorStyle(&state, true, false) == .block);
|
try testing.expect(style(&state, true, false) == .block);
|
||||||
try testing.expect(cursorStyle(&state, true, true) == .block);
|
try testing.expect(style(&state, true, true) == .block);
|
||||||
try testing.expect(cursorStyle(&state, false, true) == .block);
|
try testing.expect(style(&state, false, true) == .block);
|
||||||
|
|
||||||
// If we're scrolled though, then we don't show the cursor.
|
// If we're scrolled though, then we don't show the cursor.
|
||||||
for (0..100) |_| try term.index();
|
for (0..100) |_| try term.index();
|
||||||
try term.scrollViewport(.{ .top = {} });
|
try term.scrollViewport(.{ .top = {} });
|
||||||
|
|
||||||
// In any bool state
|
// In any bool state
|
||||||
try testing.expect(cursorStyle(&state, false, false) == null);
|
try testing.expect(style(&state, false, false) == null);
|
||||||
try testing.expect(cursorStyle(&state, true, false) == null);
|
try testing.expect(style(&state, true, false) == null);
|
||||||
try testing.expect(cursorStyle(&state, true, true) == null);
|
try testing.expect(style(&state, true, true) == null);
|
||||||
try testing.expect(cursorStyle(&state, false, true) == null);
|
try testing.expect(style(&state, false, true) == null);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user