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 WasmTarget = @import("os/wasm/target.zig").Target;
|
||||
|
||||
pub usingnamespace @import("renderer/cursor.zig");
|
||||
pub usingnamespace @import("renderer/message.zig");
|
||||
pub usingnamespace @import("renderer/size.zig");
|
||||
const cursor = @import("renderer/cursor.zig");
|
||||
const message = @import("renderer/message.zig");
|
||||
const size = @import("renderer/size.zig");
|
||||
pub const shadertoy = @import("renderer/shadertoy.zig");
|
||||
pub const Metal = @import("renderer/Metal.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 Thread = @import("renderer/Thread.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.
|
||||
pub const Impl = enum {
|
||||
|
@ -5,15 +5,15 @@ const State = @import("State.zig");
|
||||
/// Available cursor styles for drawing that renderers must support.
|
||||
/// This is a superset of terminal cursor styles since the renderer supports
|
||||
/// some additional cursor states such as the hollow block.
|
||||
pub const CursorStyle = enum {
|
||||
pub const Style = enum {
|
||||
block,
|
||||
block_hollow,
|
||||
bar,
|
||||
underline,
|
||||
|
||||
/// Create a cursor style from the terminal style request.
|
||||
pub fn fromTerminal(style: terminal.CursorStyle) ?CursorStyle {
|
||||
return switch (style) {
|
||||
pub fn fromTerminal(term: terminal.CursorStyle) ?Style {
|
||||
return switch (term) {
|
||||
.bar => .bar,
|
||||
.block => .block,
|
||||
.underline => .underline,
|
||||
@ -23,11 +23,11 @@ pub const CursorStyle = enum {
|
||||
|
||||
/// Returns the cursor style to use for the current render state or null
|
||||
/// if a cursor should not be rendered at all.
|
||||
pub fn cursorStyle(
|
||||
pub fn style(
|
||||
state: *State,
|
||||
focused: bool,
|
||||
blink_visible: bool,
|
||||
) ?CursorStyle {
|
||||
) ?Style {
|
||||
// Note the order of conditionals below is important. It represents
|
||||
// a priority system of how we determine what state overrides cursor
|
||||
// visibility and style.
|
||||
@ -57,7 +57,7 @@ pub fn cursorStyle(
|
||||
}
|
||||
|
||||
// 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" {
|
||||
@ -75,10 +75,10 @@ test "cursor: default uses configured style" {
|
||||
.preedit = null,
|
||||
};
|
||||
|
||||
try testing.expect(cursorStyle(&state, true, true) == .bar);
|
||||
try testing.expect(cursorStyle(&state, false, true) == .block_hollow);
|
||||
try testing.expect(cursorStyle(&state, false, false) == .block_hollow);
|
||||
try testing.expect(cursorStyle(&state, true, false) == null);
|
||||
try testing.expect(style(&state, true, true) == .bar);
|
||||
try testing.expect(style(&state, false, true) == .block_hollow);
|
||||
try testing.expect(style(&state, false, false) == .block_hollow);
|
||||
try testing.expect(style(&state, true, false) == null);
|
||||
}
|
||||
|
||||
test "cursor: blinking disabled" {
|
||||
@ -96,10 +96,10 @@ test "cursor: blinking disabled" {
|
||||
.preedit = null,
|
||||
};
|
||||
|
||||
try testing.expect(cursorStyle(&state, true, true) == .bar);
|
||||
try testing.expect(cursorStyle(&state, true, false) == .bar);
|
||||
try testing.expect(cursorStyle(&state, false, true) == .block_hollow);
|
||||
try testing.expect(cursorStyle(&state, false, false) == .block_hollow);
|
||||
try testing.expect(style(&state, true, true) == .bar);
|
||||
try testing.expect(style(&state, true, false) == .bar);
|
||||
try testing.expect(style(&state, false, true) == .block_hollow);
|
||||
try testing.expect(style(&state, false, false) == .block_hollow);
|
||||
}
|
||||
|
||||
test "cursor: explicitly not visible" {
|
||||
@ -118,10 +118,10 @@ test "cursor: explicitly not visible" {
|
||||
.preedit = null,
|
||||
};
|
||||
|
||||
try testing.expect(cursorStyle(&state, true, true) == null);
|
||||
try testing.expect(cursorStyle(&state, true, false) == null);
|
||||
try testing.expect(cursorStyle(&state, false, true) == null);
|
||||
try testing.expect(cursorStyle(&state, false, false) == null);
|
||||
try testing.expect(style(&state, true, true) == null);
|
||||
try testing.expect(style(&state, true, false) == null);
|
||||
try testing.expect(style(&state, false, true) == null);
|
||||
try testing.expect(style(&state, false, false) == null);
|
||||
}
|
||||
|
||||
test "cursor: always block with preedit" {
|
||||
@ -137,18 +137,18 @@ test "cursor: always block with preedit" {
|
||||
};
|
||||
|
||||
// In any bool state
|
||||
try testing.expect(cursorStyle(&state, false, false) == .block);
|
||||
try testing.expect(cursorStyle(&state, true, false) == .block);
|
||||
try testing.expect(cursorStyle(&state, true, true) == .block);
|
||||
try testing.expect(cursorStyle(&state, false, true) == .block);
|
||||
try testing.expect(style(&state, false, false) == .block);
|
||||
try testing.expect(style(&state, true, false) == .block);
|
||||
try testing.expect(style(&state, true, true) == .block);
|
||||
try testing.expect(style(&state, false, true) == .block);
|
||||
|
||||
// If we're scrolled though, then we don't show the cursor.
|
||||
for (0..100) |_| try term.index();
|
||||
try term.scrollViewport(.{ .top = {} });
|
||||
|
||||
// In any bool state
|
||||
try testing.expect(cursorStyle(&state, false, false) == null);
|
||||
try testing.expect(cursorStyle(&state, true, false) == null);
|
||||
try testing.expect(cursorStyle(&state, true, true) == null);
|
||||
try testing.expect(cursorStyle(&state, false, true) == null);
|
||||
try testing.expect(style(&state, false, false) == null);
|
||||
try testing.expect(style(&state, true, false) == null);
|
||||
try testing.expect(style(&state, true, true) == null);
|
||||
try testing.expect(style(&state, false, true) == null);
|
||||
}
|
||||
|
Reference in New Issue
Block a user