get some more stuff working
This commit is contained in:
+24
-15
@@ -13,26 +13,28 @@ const Style = grome.view.style.Style;
|
||||
pub const Nucleus = struct {
|
||||
location: Point,
|
||||
style_loop_ctr: usize,
|
||||
widget: Widget,
|
||||
|
||||
const healthy_loop = [_]Style{
|
||||
"\x1b[92m[1] \x1b[0m", // 92 - bright green
|
||||
"\x1b[10106m[2] \x1b[0m", // 256 color 10106 (85)
|
||||
"\x1b[38;2;56;142;60m[3] \x1b[0m", // RGB(56,142,60)
|
||||
"\x1b[32m[4] \x1b[0m", // standard green (92)
|
||||
"\x1b[39m[5] \x1b[0m", // even lighter
|
||||
"\x1b[35m[6] \x1b[0m", // medium green (64)
|
||||
.{ .escape = },
|
||||
.{ .escape = "" },
|
||||
.{ .escape = "" },
|
||||
.{ .escape = "" },
|
||||
.{ .escape = "" },
|
||||
.{ .escape = "" },
|
||||
style.rgb(95, 133, 99),
|
||||
style.rgb(95, 129, 78),
|
||||
style.rgb(94, 121, 66),
|
||||
style.rgb(93, 115, 45),
|
||||
style.rgb(93, 110, 34),
|
||||
style.rgb(93, 115, 45),
|
||||
style.rgb(94, 121, 66),
|
||||
style.rgb(95, 129, 78),
|
||||
style.rgb(95, 133, 99),
|
||||
};
|
||||
|
||||
pub fn init(loc: Point) Nucleus {
|
||||
return .{
|
||||
.location = loc,
|
||||
.stlye_loop_ctr = 0,
|
||||
.style_loop_ctr = 0,
|
||||
.widget = .{
|
||||
.geometryFn = Nucleus.geometry,
|
||||
.renderFn = Nucleus.render,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -47,7 +49,14 @@ pub const Nucleus = struct {
|
||||
|
||||
pub fn render(widget: *Widget, frame: *SubMatrix(Cell)) WidgetError!void {
|
||||
const self: *@This() = @fieldParentPtr("widget", widget);
|
||||
var row = frame.rowable.row(0) catch return WidgetError.UnknownError;
|
||||
@memcpy(row[0..ending], self.text[0..ending]);
|
||||
frame.set(
|
||||
.{ .x = 0, .y = 0 },
|
||||
.{
|
||||
.char = ("Ω" ** 4).*,
|
||||
.width = 2,
|
||||
.style = healthy_loop[(self.style_loop_ctr / 5) % healthy_loop.len],
|
||||
},
|
||||
) catch return WidgetError.UnknownError;
|
||||
self.style_loop_ctr += 1;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub const Text = @import("text.zig").Text;
|
||||
pub const Nucleus = @import("nucleus.zig").Nucleus;
|
||||
|
||||
@@ -7,6 +7,7 @@ const Clock = std.Io.Clock;
|
||||
const Writer = std.Io.File.Writer;
|
||||
const Rect = grome.container.Rect;
|
||||
const Text = grome.game.Text;
|
||||
const Nucleus = grome.game.Nucleus;
|
||||
const Viewport = grome.view.Viewport;
|
||||
|
||||
pub fn main(init: std.process.Init) !void {
|
||||
@@ -30,6 +31,9 @@ pub fn main(init: std.process.Init) !void {
|
||||
var text = Text.init("Hello Olive", style.Blue);
|
||||
try viewport.add_widget(arena, &text.widget);
|
||||
|
||||
var nucleus = Nucleus.init(.{ .x = 1, .y = 1 });
|
||||
try viewport.add_widget(arena, &nucleus.widget);
|
||||
|
||||
try viewport.hard_refresh(w);
|
||||
try w.flush();
|
||||
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ pub const Cell = struct {
|
||||
|
||||
/// eql returns
|
||||
pub fn eql(self: *const Cell, b: *const Cell) bool {
|
||||
return mem.eql(u8, &self.char, &b.char) and self.width == b.width;
|
||||
return mem.eql(u8, &self.char, &b.char) and self.width == b.width and (self.style orelse style.Empty).eql(b.style orelse style.Empty);
|
||||
}
|
||||
|
||||
pub fn render(self: *const @This(), w: *Writer) !void {
|
||||
|
||||
@@ -81,7 +81,7 @@ pub const DoubleBuffer = struct {
|
||||
pub fn refresh(self: *@This(), w: *std.Io.Writer) !void {
|
||||
var back_iter = self.back.row_iterator();
|
||||
var front_iter = self.front.row_iterator();
|
||||
var skip_lines: usize = 0;
|
||||
var line: usize = 1;
|
||||
var rendered: bool = false;
|
||||
|
||||
while (true) {
|
||||
@@ -93,18 +93,16 @@ pub const DoubleBuffer = struct {
|
||||
continue;
|
||||
}
|
||||
|
||||
try term.move(w, skip_lines, x + 1);
|
||||
try term.move(w, line, x + 1);
|
||||
try term.clear_remaining_line(w);
|
||||
|
||||
for (back_row[x..]) |*cell| {
|
||||
try cell.render(w);
|
||||
}
|
||||
try term.next_line(w);
|
||||
skip_lines = 0;
|
||||
rendered = true;
|
||||
break;
|
||||
}
|
||||
|
||||
skip_lines += 1;
|
||||
line += 1;
|
||||
}
|
||||
|
||||
if (rendered) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const std = @import("std");
|
||||
const mem = std.mem;
|
||||
|
||||
const Writer = std.Io.Writer;
|
||||
|
||||
@@ -9,8 +10,13 @@ pub const Style = struct {
|
||||
pub fn render(self: @This(), w: *Writer) !void {
|
||||
_ = try w.write(self.escape);
|
||||
}
|
||||
|
||||
pub fn eql(self: @This(), other: Style) bool {
|
||||
return mem.eql(u8, self.escape, other.escape);
|
||||
}
|
||||
};
|
||||
|
||||
pub const Empty = Style{ .escape = "" };
|
||||
/// Reset is a special case that will reset all styles
|
||||
pub const Reset = Style{ .escape = "\x1b[0m" };
|
||||
pub const Red = Style{ .escape = "\x1b[31m" };
|
||||
@@ -41,3 +47,16 @@ pub const BrightBlue = Style{ .escape = "\x1b[94m" };
|
||||
pub const BrightMagenta = Style{ .escape = "\x1b[95m" };
|
||||
pub const BrightCyan = Style{ .escape = "\x1b[96m" };
|
||||
pub const BrightWhite = Style{ .escape = "\x1b[97m" };
|
||||
|
||||
/// rgb returns the rgb value that you want
|
||||
pub fn rgb(r: u8, g: u8, b: u8) Style {
|
||||
return .{
|
||||
.escape = std.fmt.comptimePrint("\x1b[38;2;{d};{d};{d}m", .{ r, g, b }),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn bg_rgb(r: u8, g: u8, b: u8) Style {
|
||||
return .{
|
||||
.escape = std.fmt.comptimePrint("\x1b[48;2;{d};{d};{d}m", .{ r, g, b }),
|
||||
};
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ pub fn beginning(w: *Writer) !void {
|
||||
_ = try w.write("\x1b[H");
|
||||
}
|
||||
|
||||
/// moves the cursor the rows and columns specified
|
||||
/// moves the cursor the specific row and column
|
||||
pub fn move(w: *Writer, rows: usize, cols: usize) !void {
|
||||
try w.print("\x1b[{d};{d}H", .{ rows, cols });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user