1
0
Fork 0

i cant be bothered to check what changed

This commit is contained in:
namedkitten 2020-07-14 16:17:45 +01:00
parent f4bade27c4
commit b0f1418887
19 changed files with 120 additions and 53 deletions

3
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,3 @@
{
"materialTheme.accent": "Pink"
}

View file

@ -30,6 +30,7 @@ pub fn build(b: *Builder) void {
.name = "hzzp",
.path = "deps/hzzp/src/main.zig",
});
exe.setBuildMode(mode);
const run_cmd = exe.run();

View file

@ -15,7 +15,7 @@ fn stripCarriageReturn(buffer: []u8) []u8 {
}
}
pub fn create(buffer: []u8, reader: var, writer: var) BaseClient(@TypeOf(reader), @TypeOf(writer)) {
pub fn create(buffer: []u8, reader: anytype, writer: anytype) BaseClient(@TypeOf(reader), @TypeOf(writer)) {
assert(@typeInfo(@TypeOf(reader)) == .Pointer);
assert(@typeInfo(@TypeOf(writer)) == .Pointer);
assert(buffer.len >= 32);

View file

@ -15,7 +15,7 @@ fn stripCarriageReturn(buffer: []u8) []u8 {
}
}
pub fn create(buffer: []u8, reader: var, writer: var) BaseServer(@TypeOf(reader), @TypeOf(writer)) {
pub fn create(buffer: []u8, reader: anytype, writer: anytype) BaseServer(@TypeOf(reader), @TypeOf(writer)) {
assert(@typeInfo(@TypeOf(reader)) == .Pointer);
assert(@typeInfo(@TypeOf(writer)) == .Pointer);
assert(buffer.len >= 32);

View file

@ -8,7 +8,7 @@ const expectEqual = std.testing.expectEqual;
pub const SelfType = @OpaqueType();
fn makeSelfPtr(ptr: var) *SelfType {
fn makeSelfPtr(ptr: anytype) *SelfType {
if (comptime !trait.isSingleItemPtr(@TypeOf(ptr))) {
@compileError("SelfType pointer initialization expects pointer parameter.");
}
@ -43,7 +43,7 @@ pub const Storage = struct {
erased_ptr: *SelfType,
ImplType: type,
pub fn init(args: var) !Comptime {
pub fn init(args: anytype) !Comptime {
if (args.len != 1) {
@compileError("Comptime storage expected a 1-tuple in initialization.");
}
@ -66,7 +66,7 @@ pub const Storage = struct {
pub const NonOwning = struct {
erased_ptr: *SelfType,
pub fn init(args: var) !NonOwning {
pub fn init(args: anytype) !NonOwning {
if (args.len != 1) {
@compileError("NonOwning storage expected a 1-tuple in initialization.");
}
@ -87,7 +87,7 @@ pub const Storage = struct {
allocator: *mem.Allocator,
mem: []u8,
pub fn init(args: var) !Owning {
pub fn init(args: anytype) !Owning {
if (args.len != 2) {
@compileError("Owning storage expected a 2-tuple in initialization.");
}
@ -119,7 +119,7 @@ pub const Storage = struct {
mem: [size]u8,
pub fn init(args: var) !Self {
pub fn init(args: anytype) !Self {
if (args.len != 1) {
@compileError("Inline storage expected a 1-tuple in initialization.");
}
@ -155,7 +155,7 @@ pub const Storage = struct {
Owning: Owning,
},
pub fn init(args: var) !Self {
pub fn init(args: anytype) !Self {
if (args.len != 2) {
@compileError("InlineOrOwning storage expected a 2-tuple in initialization.");
}
@ -216,7 +216,7 @@ fn makeCall(
comptime ImplT: type,
comptime call_type: GenCallType,
self_ptr: CurrSelfType,
args: var,
args: anytype,
) Return {
const is_const = CurrSelfType == *const SelfType;
const self = if (is_const) constSelfPtrAs(self_ptr, ImplT) else selfPtrAs(self_ptr, ImplT);
@ -427,7 +427,7 @@ pub fn Interface(comptime VTableT: type, comptime StorageT: type) type {
const Self = @This();
pub fn init(args: var) !Self {
pub fn init(args: anytype) !Self {
const ImplType = PtrChildOrSelf(@TypeOf(args.@"0"));
return Self{
@ -436,14 +436,14 @@ pub fn Interface(comptime VTableT: type, comptime StorageT: type) type {
};
}
pub fn initWithVTable(vtable_ptr: *const VTableT, args: var) !Self {
pub fn initWithVTable(vtable_ptr: *const VTableT, args: anytype) !Self {
return .{
.vtable_ptr = vtable_ptr,
.storage = try StorageT.init(args),
};
}
pub fn call(self: var, comptime name: []const u8, args: var) VTableReturnType(VTableT, name) {
pub fn call(self: anytype, comptime name: []const u8, args: anytype) VTableReturnType(VTableT, name) {
comptime var is_optional = true;
comptime var is_async = true;
comptime assert(vtableHasMethod(VTableT, name, &is_optional, &is_async));

View file

@ -1,6 +1,6 @@
const std = @import("std");
const Widget = @import("../types/widget.zig").Widget;
const Info = @import("../types/info.zig").Info;
const Info = @import("../types/info.zig");
const MouseEvent = @import("../types/mouseevent.zig").MouseEvent;
const terminal_version = @import("build_options").terminal_version;

View file

@ -41,7 +41,7 @@ pub const AllocationInfo = struct {
self: AllocationInfo,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
out_stream: var,
out_stream: anytype,
) !void {
@setEvalBranchQuota(2000);

View file

@ -28,6 +28,46 @@ const TerminalYellowColour = "\u{001b}[33m";
const TerminalGreenColour = "\u{001b}[32m";
const TerminalPurpleColour = "\u{001b}[35m";
pub fn comptimeColour(comptime clr: []const u8, comptime str: []const u8) []const u8 {
if (disable_colour) return str;
if (clr[0] == '#' or clr[0] == '\u{001b}') {
if (terminal_version) {
return crl ++ str ++ TerminalResetColour;
} else {
return "<span color=\"" ++ clr ++ "\">" ++ str ++ "</span>";
}
} else {
var colourText: []const u8 = "";
if (eql(u8, clr, "text")) {
colourText = if (!terminal_version) TextColour else TerminalTextColour;
} else if (eql(u8, clr, "dark")) {
colourText = if (!terminal_version) DarkerTextColour else TerminalDarkerTextColour;
} else if (eql(u8, clr, "darkest")) {
colourText = if (!terminal_version) DarkestTextColour else TerminalDarkestTextColour;
} else if (eql(u8, clr, "accentlight")) {
colourText = if (!terminal_version) AccentLightColour else TerminalAccentLightColour;
} else if (eql(u8, clr, "accentmedium")) {
colourText = if (!terminal_version) AccentMediumColour else TerminalAccentMediumColour;
} else if (eql(u8, clr, "accentdark")) {
colourText = if (!terminal_version) AccentDarkColour else TerminalAccentDarkColour;
} else if (eql(u8, clr, "red")) {
colourText = if (!terminal_version) RedColour else TerminalRedColour;
} else if (eql(u8, clr, "orange")) {
colourText = if (!terminal_version) OrangeColour else TerminalOrangeColour;
} else if (eql(u8, clr, "yellow")) {
colourText = if (!terminal_version) YellowColour else TerminalYellowColour;
} else if (eql(u8, clr, "green")) {
colourText = if (!terminal_version) GreenColour else TerminalGreenColour;
} else if (eql(u8, clr, "purple")) {
colourText = if (!terminal_version) PurpleColour else TerminalPurpleColour;
} else {
@compileError("colour not found");
}
return comptimeColour(colourText, str);
}
}
pub fn colour(alloc: *std.mem.Allocator, clr: []const u8, str: []const u8) ![]const u8 {
if (disable_colour) return str;

View file

@ -8,10 +8,10 @@ const timeWidget = @import("widgets/time/time.zig");
const batteryWidget = @import("widgets/battery/battery.zig");
const memoryWidget = @import("widgets/memory/memory.zig");
const DebugAllocator = @import("debug_allocator.zig");
const Info = @import("types/info.zig").Info;
const Info = @import("types/info.zig");
pub fn main() !void {
const debug: bool = false;
const debug: bool = true;
var allocator: *std.mem.Allocator = undefined;
var dbgAlloc: *DebugAllocator = undefined;
if (debug) {
@ -20,15 +20,14 @@ pub fn main() !void {
} else {
allocator = std.heap.page_allocator;
}
var bar = barImpl.InitBar(allocator);
var br = Bar.init(&bar);
const widgets = [_]*Widget{
&Widget.init(&textWidget.New("owo", "potato")), // 4KiB
&Widget.init(&textWidget.New("uwu", "tomato")), // 4KiB
&Widget.init(&memoryWidget.New(allocator, &br)), // 8.08KiB
&Widget.init(&weatherWidget.New(allocator, &br, "Stockholm")), // 16KiB
//&Widget.init(&textWidget.New("owo", "potato")), // 4KiB
//&Widget.init(&textWidget.New("uwu", "tomato")), // 4KiB
&Widget.init(&memoryWidget.New(&br)), // 4.08KiB
&Widget.init(&weatherWidget.New(allocator, &br, "Stockholm")), // 16.16KiB
&Widget.init(&batteryWidget.New(allocator, &br)), // 12.11KiB
&Widget.init(&timeWidget.New(allocator, &br)), // 32.46KiB
};

View file

@ -1,7 +1,7 @@
const interface = @import("interfaces");
const Interface = interface.Interface;
const SelfType = interface.SelfType;
const Info = @import("info.zig").Info;
const Info = @import("info.zig");
pub const Bar = struct {
const IFace = Interface(struct {
@ -10,7 +10,7 @@ pub const Bar = struct {
add: fn (*SelfType, Info) anyerror!void,
}, interface.Storage.NonOwning);
iface: IFace,
pub fn init(impl_ptr: var) Bar {
pub fn init(impl_ptr: anytype) Bar {
return .{ .iface = try IFace.init(.{impl_ptr}) };
}
pub fn keep_running(self: *Bar) bool {

View file

@ -1,5 +1,3 @@
pub const Info = struct {
name: []const u8,
markup: []const u8,
full_text: []const u8,
};

View file

@ -1,7 +1,7 @@
const interface = @import("interfaces");
const Interface = interface.Interface;
const SelfType = interface.SelfType;
const Info = @import("info.zig").Info;
const Info = @import("info.zig");
pub const Widget = struct {
const IFace = Interface(struct {
@ -10,7 +10,7 @@ pub const Widget = struct {
start: fn (*SelfType) anyerror!void,
}, interface.Storage.NonOwning);
iface: IFace,
pub fn init(impl_ptr: var) Widget {
pub fn init(impl_ptr: anytype) Widget {
return .{ .iface = try IFace.init(.{impl_ptr}) };
}
pub fn name(self: *Widget) []const u8 {

View file

@ -1,5 +1,5 @@
const std = @import("std");
const Info = @import("../../types/info.zig").Info;
const Info = @import("../../types/info.zig");
const Bar = @import("../../types/bar.zig").Bar;
const fs = std.fs;
const cwd = fs.cwd;
@ -86,10 +86,12 @@ pub const BatteryWidget = struct {
}
pub fn start(self: *BatteryWidget) anyerror!void {
var pparena = std.heap.ArenaAllocator.init(self.allocator);
defer pparena.deinit();
var ppallocator = &pparena.allocator;
var buffer: [1024]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&buffer);
var ppallocator = &fba.allocator;
const pp = try self.get_power_paths(ppallocator);
std.debug.print("{}\n", .{pp});
while (self.bar.keep_running()) {
var arena = std.heap.ArenaAllocator.init(self.allocator);
defer arena.deinit();

View file

@ -1,7 +1,8 @@
const std = @import("std");
const Info = @import("../../types/info.zig").Info;
const Info = @import("../../types/info.zig");
const Bar = @import("../../types/bar.zig").Bar;
const colour = @import("../../formatting/colour.zig").colour;
const comptimeColour = @import("../../formatting/colour.zig").colour;
const MemInfo = struct {
memTotal: u64,
@ -30,7 +31,7 @@ fn formatMemoryPercent(allocator: *std.mem.Allocator, percent: f64) ![]const u8
} else {
percentColour = "green";
}
const percentString = try std.fmt.allocPrint(allocator, "{d:.3}{}", .{ percent, colour(allocator, "accentdark", "%") });
const percentString = try std.fmt.allocPrint(allocator, "{d:.3}{}", .{ percent, comptimeColour(allocator, "accentdark", "%") });
return colour(allocator, percentColour, percentString);
}
@ -79,7 +80,6 @@ fn fetchTotalMemory() !MemInfo {
pub const MemoryWidget = struct {
bar: *Bar,
allocator: *std.mem.Allocator,
pub fn name(self: *MemoryWidget) []const u8 {
return "mem";
}
@ -92,9 +92,9 @@ pub const MemoryWidget = struct {
}
fn update_bar(self: *MemoryWidget) !void {
var arena = std.heap.ArenaAllocator.init(self.allocator);
defer arena.deinit();
var allocator = &arena.allocator;
var buffer: [512]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&buffer);
var allocator = &fba.allocator;
const memInfo = try fetchTotalMemory();
try self.bar.add(Info{
.name = "mem",
@ -114,9 +114,8 @@ pub const MemoryWidget = struct {
}
};
pub inline fn New(allocator: *std.mem.Allocator, bar: *Bar) MemoryWidget {
pub inline fn New(bar: *Bar) MemoryWidget {
return MemoryWidget{
.allocator = allocator,
.bar = bar,
};
}

View file

@ -1,5 +1,5 @@
const std = @import("std");
const Info = @import("../../types/info.zig").Info;
const Info = @import("../../types/info.zig");
pub const TextWidget = struct {
name: []const u8,

View file

@ -1,5 +1,5 @@
const std = @import("std");
const Info = @import("../../types/info.zig").Info;
const Info = @import("../../types/info.zig");
const Bar = @import("../../types/bar.zig").Bar;
const time = @import("time");
const colour = @import("../../formatting/colour.zig").colour;

View file

@ -2,7 +2,7 @@ const std = @import("std");
const net = std.net;
const io = std.io;
const hzzp = @import("hzzp");
const Info = @import("../../types/info.zig").Info;
const Info = @import("../../types/info.zig");
const Bar = @import("../../types/bar.zig").Bar;
const colour = @import("../../formatting/colour.zig").colour;
const DebugAllocator = @import("../../debug_allocator.zig");
@ -130,6 +130,7 @@ pub const WeatherWidget = struct {
.full_text = "DNS Error Fetching Weather",
.markup = "pango",
});
return;
},
error.InvalidIPAddressFormat => {
try self.bar.add(Info{
@ -137,6 +138,7 @@ pub const WeatherWidget = struct {
.full_text = "Invalid Weather IP",
.markup = "pango",
});
return;
},
error.ConnectionResetByPeer => {
try self.bar.add(Info{
@ -144,6 +146,7 @@ pub const WeatherWidget = struct {
.full_text = "Weather Reset",
.markup = "pango",
});
return;
},
else => |e| {
std.debug.print("\n\n\n\n\nError!: {}\n\n\n\n\n", .{@errorName(e)});

View file

@ -17,7 +17,7 @@
{
"zig":
{
"enabled": true
"enabled": false
}
}
}

View file

@ -3,6 +3,10 @@
{
"selected_items":
[
[
"Dark",
"DarkerTextColour"
],
[
"powe",
"power_now_path"
@ -86,7 +90,15 @@
[
[
"lsp",
"LSP: Toggle Diagnostics Panel"
"LSP: Disable Language Server in Project"
],
[
"lsp res",
"LSP: Restart Servers"
],
[
"lsp enable",
"LSP: Enable Language Server Globally"
],
[
"enable lang",
@ -167,11 +179,14 @@
},
"file_history":
[
"/home/kitteh/zar/src/widgets/time/time.zig",
"/home/kitteh/zar/src/widgets/memory/memory.zig",
"/home/kitteh/zar/src/formatting/colour.zig",
"/home/kitteh/bar/memory.go",
"/home/kitteh/zig-linux-x86_64-0.6.0+485231dea/lib/zig/std/std.zig",
"/home/kitteh/zar/src/debug_allocator.zig",
"/home/kitteh/zar/src/bar/bar.zig",
"/home/kitteh/bar/battery.go",
"/home/kitteh/zar/src/formatting/colour.zig",
"/home/kitteh/zar/build.zig",
"/home/kitteh/zar/deps/time/src/time.zig",
"/home/kitteh/bar/time.go",
@ -185,7 +200,6 @@
"/home/kitteh/zar/src/widgets/text/text.zig",
"/home/kitteh/bar/bar.go",
"/home/kitteh/zar/src/types/bar.zig",
"/home/kitteh/zar/src/widgets/memory/memory.zig",
"/home/kitteh/zar/src/types/widget.zig",
"/home/kitteh/zar/src/types/types.zig",
"/home/kitteh/.config/sublime-text-3/Packages/ayu/widgets/Widget - ayu-dark.sublime-settings",
@ -209,6 +223,11 @@
"case_sensitive": false,
"find_history":
[
".mutex",
"else return",
") return",
"comptime",
"colour(",
"_",
"secureZero",
"self.widgets",
@ -264,6 +283,9 @@
"regex": false,
"replace_history":
[
".items_mutex",
"else",
")",
"BatteryWidget",
"@mod(date.day, 10)",
"@mod(date.day, 100)",
@ -281,7 +303,7 @@
},
"incremental_find":
{
"height": 27.0
"height": 28.0
},
"input":
{
@ -316,7 +338,7 @@
},
"output.exec":
{
"height": 169.0
"height": 70.0
},
"output.find_results":
{
@ -329,7 +351,7 @@
"pinned_build_system": "",
"replace":
{
"height": 50.0
"height": 52.0
},
"save_all_on_build": false,
"select_file":
@ -357,7 +379,7 @@
"selected_items":
[
],
"width": 352.0
"width": 580.0
},
"settings":
{