diff options
| author | 2021-12-21 07:06:13 +0200 | |
|---|---|---|
| committer | 2021-12-21 07:07:58 +0200 | |
| commit | fecea5d7a74f97d41c50734349c80062ce2e9cb6 (patch) | |
| tree | 8c84ca5c9f27dd95038658c97f996e04a4862e00 /src/Buffer.zig | |
| parent | bugfix (diff) | |
| download | es-fecea5d7a74f97d41c50734349c80062ce2e9cb6.tar.gz es-fecea5d7a74f97d41c50734349c80062ce2e9cb6.tar.xz es-fecea5d7a74f97d41c50734349c80062ce2e9cb6.zip | |
zig fmt
Diffstat (limited to 'src/Buffer.zig')
| -rw-r--r-- | src/Buffer.zig | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/Buffer.zig b/src/Buffer.zig index 0416fda..d7f051d 100644 --- a/src/Buffer.zig +++ b/src/Buffer.zig | |||
| @@ -38,7 +38,7 @@ pub fn init(allocator: Allocator, name: []const u8) !Buffer { | |||
| 38 | // TODO: buffer-specific config support | 38 | // TODO: buffer-specific config support |
| 39 | var config = try Config.readConfig(allocator); | 39 | var config = try Config.readConfig(allocator); |
| 40 | 40 | ||
| 41 | return Buffer { | 41 | return Buffer{ |
| 42 | .allocator = allocator, | 42 | .allocator = allocator, |
| 43 | 43 | ||
| 44 | .name = name_owned, | 44 | .name = name_owned, |
| @@ -193,7 +193,7 @@ pub fn drawRows(self: Buffer, writer: anytype, screenrows: usize, screencols: us | |||
| 193 | } | 193 | } |
| 194 | } | 194 | } |
| 195 | } else if (self.rows.items.len == 0 and y == screenrows / 3) { | 195 | } else if (self.rows.items.len == 0 and y == screenrows / 3) { |
| 196 | const welcome_data = try std.fmt.allocPrint(self.allocator, "ES -- version {}", .{ es_config.es_version }); | 196 | const welcome_data = try std.fmt.allocPrint(self.allocator, "ES -- version {}", .{es_config.es_version}); |
| 197 | defer self.allocator.free(welcome_data); | 197 | defer self.allocator.free(welcome_data); |
| 198 | var welcome = welcome_data; | 198 | var welcome = welcome_data; |
| 199 | if (welcome.len > screencols - 1) { | 199 | if (welcome.len > screencols - 1) { |
| @@ -201,7 +201,7 @@ pub fn drawRows(self: Buffer, writer: anytype, screenrows: usize, screencols: us | |||
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | const padding = (screencols - welcome.len - 1) / 2; | 203 | const padding = (screencols - welcome.len - 1) / 2; |
| 204 | try writer.print("{s}~{s}", .{Highlight.line_no.asString(), Highlight.normal.asString()}); | 204 | try writer.print("{s}~{s}", .{ Highlight.line_no.asString(), Highlight.normal.asString() }); |
| 205 | try printWithLeftPadding(self.allocator, writer, "{s}", welcome.len + padding, ' ', .{welcome}); | 205 | try printWithLeftPadding(self.allocator, writer, "{s}", welcome.len + padding, ' ', .{welcome}); |
| 206 | } else { | 206 | } else { |
| 207 | try writer.print("{s}~", .{Highlight.line_no.asString()}); | 207 | try writer.print("{s}~", .{Highlight.line_no.asString()}); |
| @@ -225,7 +225,7 @@ pub fn drawStatusBar(self: Buffer, writer: anytype, screencols: usize) !void { | |||
| 225 | else | 225 | else |
| 226 | @as([]const u8, ""); | 226 | @as([]const u8, ""); |
| 227 | 227 | ||
| 228 | var lbuf = try std.fmt.allocPrint(self.allocator, "{s}{s}", .{name, modified}); | 228 | var lbuf = try std.fmt.allocPrint(self.allocator, "{s}{s}", .{ name, modified }); |
| 229 | defer self.allocator.free(lbuf); | 229 | defer self.allocator.free(lbuf); |
| 230 | 230 | ||
| 231 | var rbuf = try std.fmt.allocPrint(self.allocator, " {s} | {}/{}", .{ | 231 | var rbuf = try std.fmt.allocPrint(self.allocator, " {s} | {}/{}", .{ |
| @@ -263,7 +263,7 @@ pub fn goToLine(self: *Buffer, editor: *Editor) !void { | |||
| 263 | defer editor.allocator.free(line_str); | 263 | defer editor.allocator.free(line_str); |
| 264 | 264 | ||
| 265 | const line = std.fmt.parseUnsigned(usize, line_str, 0) catch |err| { | 265 | const line = std.fmt.parseUnsigned(usize, line_str, 0) catch |err| { |
| 266 | try editor.setStatusMessage("Couldn't parse '{s}' as an integer: {}", .{line_str, err}); | 266 | try editor.setStatusMessage("Couldn't parse '{s}' as an integer: {}", .{ line_str, err }); |
| 267 | return; | 267 | return; |
| 268 | }; | 268 | }; |
| 269 | 269 | ||
| @@ -419,34 +419,34 @@ pub fn save(self: *Buffer, editor: *Editor) !void { | |||
| 419 | // TODO: Add a config value for this | 419 | // TODO: Add a config value for this |
| 420 | try self.cleanWhiteSpace(); | 420 | try self.cleanWhiteSpace(); |
| 421 | 421 | ||
| 422 | const tmpname = try std.fmt.allocPrint(self.allocator, "{s}~{}", .{self.name, std.time.milliTimestamp()}); | 422 | const tmpname = try std.fmt.allocPrint(self.allocator, "{s}~{}", .{ self.name, std.time.milliTimestamp() }); |
| 423 | defer self.allocator.free(tmpname); | 423 | defer self.allocator.free(tmpname); |
| 424 | 424 | ||
| 425 | const tmpfile = std.fs.cwd().createFile(tmpname, .{.truncate = true}) catch |err| { | 425 | const tmpfile = std.fs.cwd().createFile(tmpname, .{ .truncate = true }) catch |err| { |
| 426 | try editor.setStatusMessage("Cannot open tempfile '{s}' for writing: {}", .{tmpname, err}); | 426 | try editor.setStatusMessage("Cannot open tempfile '{s}' for writing: {}", .{ tmpname, err }); |
| 427 | return; | 427 | return; |
| 428 | }; | 428 | }; |
| 429 | defer tmpfile.close(); | 429 | defer tmpfile.close(); |
| 430 | 430 | ||
| 431 | const stat = statFile(self.name) catch |err| { | 431 | const stat = statFile(self.name) catch |err| { |
| 432 | try editor.setStatusMessage("Couldn't stat file '{s}': {}", .{self.name, err}); | 432 | try editor.setStatusMessage("Couldn't stat file '{s}': {}", .{ self.name, err }); |
| 433 | return; | 433 | return; |
| 434 | }; | 434 | }; |
| 435 | 435 | ||
| 436 | tmpfile.chmod(stat.mode) catch |err| { | 436 | tmpfile.chmod(stat.mode) catch |err| { |
| 437 | try editor.setStatusMessage("Couldn't chmod tempfile '{s}': {}", .{tmpname, err}); | 437 | try editor.setStatusMessage("Couldn't chmod tempfile '{s}': {}", .{ tmpname, err }); |
| 438 | return; | 438 | return; |
| 439 | }; | 439 | }; |
| 440 | 440 | ||
| 441 | // TODO: chown | 441 | // TODO: chown |
| 442 | 442 | ||
| 443 | self.writeToFile(tmpfile) catch |err| { | 443 | self.writeToFile(tmpfile) catch |err| { |
| 444 | try editor.setStatusMessage("Couldn't write to tempfile '{s}': {}", .{tmpname, err}); | 444 | try editor.setStatusMessage("Couldn't write to tempfile '{s}': {}", .{ tmpname, err }); |
| 445 | return; | 445 | return; |
| 446 | }; | 446 | }; |
| 447 | 447 | ||
| 448 | std.fs.cwd().rename(tmpname, self.name) catch |err| { | 448 | std.fs.cwd().rename(tmpname, self.name) catch |err| { |
| 449 | try editor.setStatusMessage("Couldn't move '{s}' to '{s}': {}", .{tmpname, self.name, err}); | 449 | try editor.setStatusMessage("Couldn't move '{s}' to '{s}': {}", .{ tmpname, self.name, err }); |
| 450 | return; | 450 | return; |
| 451 | }; | 451 | }; |
| 452 | 452 | ||
| @@ -480,9 +480,7 @@ pub fn selectSyntaxHighlighting(self: *Buffer) !void { | |||
| 480 | for (Syntax.database) |syntax| { | 480 | for (Syntax.database) |syntax| { |
| 481 | for (syntax.filematch) |filematch| { | 481 | for (syntax.filematch) |filematch| { |
| 482 | const is_ext = filematch[0] == '.'; | 482 | const is_ext = filematch[0] == '.'; |
| 483 | if ((is_ext and ext != null and std.mem.eql(u8, ext.?, filematch)) | 483 | if ((is_ext and ext != null and std.mem.eql(u8, ext.?, filematch)) or (!is_ext and std.mem.eql(u8, self.name, filematch))) { |
| 484 | or (!is_ext and std.mem.eql(u8, self.name, filematch)) | ||
| 485 | ) { | ||
| 486 | self.syntax = syntax; | 484 | self.syntax = syntax; |
| 487 | 485 | ||
| 488 | for (self.rows.items) |*row| { | 486 | for (self.rows.items) |*row| { |