bell doesn't crash

This commit is contained in:
Mitchell Hashimoto
2022-04-27 09:12:23 -07:00
parent 7d10c8f0a4
commit 2767f19ced
3 changed files with 17 additions and 0 deletions

View File

@ -7,3 +7,7 @@ Performance:
Correctness:
* `exit` in the shell should close the window
Visual:
* bell

View File

@ -4,11 +4,14 @@
const Terminal = @This();
const std = @import("std");
const builtin = @import("builtin");
const testing = std.testing;
const Allocator = std.mem.Allocator;
const ansi = @import("ansi.zig");
const Parser = @import("Parser.zig");
const log = std.log.scoped(.terminal);
/// Screen is the current screen state.
screen: Screen,
@ -105,6 +108,7 @@ pub fn append(self: *Terminal, alloc: Allocator, str: []const u8) !void {
///
/// This may allocate if necessary to store the character in the grid.
pub fn appendChar(self: *Terminal, alloc: Allocator, c: u8) !void {
log.debug("char: {}", .{c});
const actions = self.parser.next(c);
for (actions) |action_opt| {
switch (action_opt orelse continue) {
@ -127,12 +131,19 @@ fn print(self: *Terminal, alloc: Allocator, c: u8) !void {
fn execute(self: *Terminal, c: u8) !void {
switch (@intToEnum(ansi.C0, c)) {
.BEL => self.bell(),
.BS => self.backspace(),
.LF => self.linefeed(),
.CR => self.carriage_return(),
}
}
pub fn bell(self: *Terminal) void {
// TODO: bell
_ = self;
log.info("bell", .{});
}
/// Backspace moves the cursor back a column (but not less than 0).
pub fn backspace(self: *Terminal) void {
self.cursor.x -|= 1;

View File

@ -3,6 +3,8 @@
/// This is not complete, control characters are only added to this
/// as the terminal emulator handles them.
pub const C0 = enum(u7) {
/// Bell
BEL = 0x07,
/// Backspace
BS = 0x08,
/// Line feed