mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-23 21:53:53 +01:00
fancify prompt
This commit is contained in:
parent
d7da623a09
commit
adeb8e4472
2 changed files with 37 additions and 13 deletions
|
@ -7,7 +7,6 @@ pub const c = @cImport({
|
|||
pub fn checkGitError(errno: c_int) !void {
|
||||
if (errno < 0) {
|
||||
const err = c.git_error_last();
|
||||
// TODO: this looks terrible. save to buf or something
|
||||
std.log.err(
|
||||
"libgit2 error: {}/{}: {s}",
|
||||
.{ errno, err.*.klass, err.*.message },
|
||||
|
|
|
@ -15,6 +15,8 @@ const symbols = struct {
|
|||
const top_end = "";
|
||||
const staged = "";
|
||||
const unstaged = "";
|
||||
const home = "";
|
||||
const root = "";
|
||||
};
|
||||
|
||||
pub fn render(writer: anytype, status: i16, mode: FishMode) !void {
|
||||
|
@ -52,7 +54,7 @@ fn Renderer(comptime Writer: type) type {
|
|||
try self.renderCwd();
|
||||
self.renderGit() catch |err| {
|
||||
switch (err) {
|
||||
error.GitError => {},
|
||||
error.GitError => {}, // git error will be printed
|
||||
else => return err,
|
||||
}
|
||||
};
|
||||
|
@ -86,7 +88,6 @@ fn Renderer(comptime Writer: type) type {
|
|||
try self.setStyle(.{});
|
||||
}
|
||||
|
||||
// TODO: fancify (using symbols.path_separator) + some formatting
|
||||
fn renderCwd(self: *Self) !void {
|
||||
const pwd = std.fs.cwd();
|
||||
const realpath = try pwd.realpathAlloc(std.heap.c_allocator, ".");
|
||||
|
@ -102,28 +103,52 @@ fn Renderer(comptime Writer: type) type {
|
|||
try self.setStyle(.{
|
||||
.background = .{ .Yellow = {} },
|
||||
.foreground = .{ .Magenta = {} },
|
||||
.font_style = .{ .bold = true },
|
||||
});
|
||||
try self.writer.writeAll(" ~/");
|
||||
try self.writer.writeAll(" " ++ symbols.home);
|
||||
if (home.len != realpath.len) {
|
||||
try self.setStyle(.{
|
||||
.background = .{ .Yellow = {} },
|
||||
.foreground = .{ .Black = {} },
|
||||
});
|
||||
try self.writer.writeAll(realpath[(home.len + 1)..]);
|
||||
try self.renderPathSep();
|
||||
try self.renderPath(realpath[(home.len + 1)..]);
|
||||
}
|
||||
written_path = true;
|
||||
}
|
||||
}
|
||||
|
||||
// write root-relative path
|
||||
if (!written_path) {
|
||||
try self.setStyle(.{
|
||||
.background = .{ .Yellow = {} },
|
||||
.foreground = .{ .Red = {} },
|
||||
});
|
||||
try self.writer.writeAll(" " ++ symbols.root);
|
||||
|
||||
// don't render separators when we're in /
|
||||
if (realpath.len > 1) {
|
||||
try self.renderPathSep();
|
||||
try self.renderPath(realpath[1..]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn renderPath(self: *Self, path: []const u8) !void {
|
||||
for (path) |byte|
|
||||
if (byte == '/')
|
||||
try self.renderPathSep()
|
||||
else
|
||||
try self.writer.writeByte(byte);
|
||||
}
|
||||
|
||||
fn renderPathSep(self: *Self) !void {
|
||||
try self.setStyle(.{
|
||||
.background = self.last_style.?.background,
|
||||
.foreground = .{ .Blue = {} },
|
||||
});
|
||||
|
||||
try self.writer.writeAll(" " ++ symbols.path_separator ++ " ");
|
||||
|
||||
try self.setStyle(.{
|
||||
.background = self.last_style.?.background,
|
||||
.foreground = .{ .Black = {} },
|
||||
});
|
||||
try self.writer.writeAll(" ");
|
||||
try self.writer.writeAll(realpath);
|
||||
}
|
||||
}
|
||||
|
||||
fn renderGit(self: *Self) !void {
|
||||
|
|
Loading…
Reference in a new issue