add(error): introduce zterm.Error containing all zterm errors with their corresponding description
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 28s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 28s
This commit is contained in:
@@ -6,6 +6,7 @@ const Cell = @import("cell.zig");
|
|||||||
const Color = @import("color.zig").Color;
|
const Color = @import("color.zig").Color;
|
||||||
const Size = @import("size.zig").Size;
|
const Size = @import("size.zig").Size;
|
||||||
const Style = @import("style.zig");
|
const Style = @import("style.zig");
|
||||||
|
const Error = @import("error.zig").Error;
|
||||||
|
|
||||||
const log = std.log.scoped(.container);
|
const log = std.log.scoped(.container);
|
||||||
|
|
||||||
@@ -144,7 +145,7 @@ pub const Rectangle = packed struct {
|
|||||||
/// children accordingly without removing the coloring of the `Rectangle`
|
/// children accordingly without removing the coloring of the `Rectangle`
|
||||||
fill: Color = .default,
|
fill: Color = .default,
|
||||||
|
|
||||||
// NOTE: caller owns `cells` slice and ensures that `cells.len == size.cols * size.rows`
|
// NOTE: caller owns `Cells` slice and ensures that `cells.len == size.cols * size.rows`
|
||||||
pub fn contents(this: @This(), cells: []Cell, size: Size) void {
|
pub fn contents(this: @This(), cells: []Cell, size: Size) void {
|
||||||
std.debug.assert(cells.len == @as(usize, size.cols) * @as(usize, size.rows));
|
std.debug.assert(cells.len == @as(usize, size.cols) * @as(usize, size.rows));
|
||||||
|
|
||||||
@@ -600,8 +601,8 @@ pub fn Container(comptime Event: type) type {
|
|||||||
size.rows,
|
size.rows,
|
||||||
});
|
});
|
||||||
this.size = size;
|
this.size = size;
|
||||||
if (this.properties.fixed_size.cols > 0 and size.cols < this.properties.fixed_size.cols) return error.TooSmall;
|
if (this.properties.fixed_size.cols > 0 and size.cols < this.properties.fixed_size.cols) return Error.TooSmall;
|
||||||
if (this.properties.fixed_size.rows > 0 and size.rows < this.properties.fixed_size.rows) return error.TooSmall;
|
if (this.properties.fixed_size.rows > 0 and size.rows < this.properties.fixed_size.rows) return Error.TooSmall;
|
||||||
|
|
||||||
try this.element.handle(event);
|
try this.element.handle(event);
|
||||||
|
|
||||||
@@ -623,8 +624,8 @@ pub fn Container(comptime Event: type) type {
|
|||||||
}
|
}
|
||||||
// check if the available screen is large enough
|
// check if the available screen is large enough
|
||||||
switch (layout.direction) {
|
switch (layout.direction) {
|
||||||
.horizontal => if (fixed_size.cols > size.cols) return error.TooSmall,
|
.horizontal => if (fixed_size.cols > size.cols) return Error.TooSmall,
|
||||||
.vertical => if (fixed_size.rows > size.rows) return error.TooSmall,
|
.vertical => if (fixed_size.rows > size.rows) return Error.TooSmall,
|
||||||
}
|
}
|
||||||
const sides = this.properties.border.sides;
|
const sides = this.properties.border.sides;
|
||||||
const padding = layout.padding;
|
const padding = layout.padding;
|
||||||
|
|||||||
4
src/error.zig
Normal file
4
src/error.zig
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
pub const Error = error{
|
||||||
|
/// Thrown when a `Container` is too small to be rendered in the current screen part.
|
||||||
|
TooSmall,
|
||||||
|
};
|
||||||
@@ -8,6 +8,7 @@ pub const input = @import("input.zig");
|
|||||||
pub const testing = @import("testing.zig");
|
pub const testing = @import("testing.zig");
|
||||||
|
|
||||||
pub const App = @import("app.zig").App;
|
pub const App = @import("app.zig").App;
|
||||||
|
pub const Error = @import("error.zig").Error;
|
||||||
// App also exports further types once initialized with the user events at compile time:
|
// App also exports further types once initialized with the user events at compile time:
|
||||||
// `App.Container`
|
// `App.Container`
|
||||||
// `App.Element`
|
// `App.Element`
|
||||||
@@ -31,6 +32,7 @@ test {
|
|||||||
_ = @import("terminal.zig");
|
_ = @import("terminal.zig");
|
||||||
_ = @import("container.zig");
|
_ = @import("container.zig");
|
||||||
_ = @import("queue.zig");
|
_ = @import("queue.zig");
|
||||||
|
_ = @import("error.zig");
|
||||||
|
|
||||||
_ = color;
|
_ = color;
|
||||||
_ = size;
|
_ = size;
|
||||||
|
|||||||
Reference in New Issue
Block a user