more text editor work

This commit is contained in:
koniifer 2024-11-08 13:47:24 +00:00
parent adbf32d970
commit 444fcdb0c4
4 changed files with 84 additions and 66 deletions

18
Cargo.lock generated
View file

@ -19,9 +19,9 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
[[package]]
name = "anyhow"
version = "1.0.92"
version = "1.0.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74f37166d7d48a0284b99dd824694c26119c700b53bf0d1540cdb147dbdaaf13"
checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775"
[[package]]
name = "autocfg"
@ -82,9 +82,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "cc"
version = "1.1.36"
version = "1.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baee610e9452a8f6f0a1b6194ec09ff9e2d85dea54432acdae41aa0761c95d70"
checksum = "40545c26d092346d8a8dab71ee48e7685a7a9cba76e634790c215b41a4a7b4cf"
dependencies = [
"shlex",
]
@ -228,12 +228,12 @@ dependencies = [
[[package]]
name = "hbbytecode"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0374848b283f29547625c76e7629d5d61bac3109"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a299bad75b068f565e6e10b6c3501a9422e283c4"
[[package]]
name = "hblang"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0374848b283f29547625c76e7629d5d61bac3109"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a299bad75b068f565e6e10b6c3501a9422e283c4"
dependencies = [
"hashbrown 0.15.1",
"hbbytecode",
@ -245,7 +245,7 @@ dependencies = [
[[package]]
name = "hbvm"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0374848b283f29547625c76e7629d5d61bac3109"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a299bad75b068f565e6e10b6c3501a9422e283c4"
dependencies = [
"hbbytecode",
]
@ -428,9 +428,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
version = "0.2.161"
version = "0.2.162"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1"
checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398"
[[package]]
name = "limine"

View file

@ -4,7 +4,7 @@
.{Vec2} := math
// safety: don't use before init() or you will get a memory access violation
framebuffer := memory.dangling(^Color)
framebuffer := memory.dangling(Color)
Surface := struct {
buf: ^Color,
@ -266,7 +266,7 @@ put_text := fn(surface: Surface, font: Font, pos: Vec2(uint), color: Color, str:
current_char := str
loop if *current_char == 0 break else {
glyph_data := memory.dangling(^u8)
glyph_data := memory.dangling(u8)
if font.unicode != null {
code_point := @as(uint, 0)

View file

@ -2,8 +2,8 @@ PAGE_SIZE := 4096
MAX_ALLOC := 0xFF
MAX_FREE := 0xFF
dangling := fn($Expr: type): Expr {
return @bitcast(@sizeof(Expr))
dangling := fn($Expr: type): ^Expr {
return @bitcast(@alignof(Expr))
}
calc_pages := fn($Expr: type, num: uint): uint {

View file

@ -13,46 +13,34 @@ render := @use("../../../../libraries/render/src/lib.hb")
psf := @embed("../../../../consolefonts/tamsyn/10x20r.psf")
handle_char := fn(char: u8, cursor: ^u8, buf: ^u8): ^u8 {
if char == 0 {
return cursor
}
if char != 0x8 {
*cursor = char
return cursor + 1
} else if char == 0xA {
*cursor = 32
cursor += 1;
*cursor = 92
return cursor + 1
} else if cursor > buf {
cursor -= 1;
*cursor = 32
return cursor
}
return cursor
}
is_shift_pressed := false
is_ctrl_pressed := false
$initial_delay := 50
$repeat_delay := 7
example := fn(): void {
screen := render.init(true)
window := render.new_surface(480, 340)
font := render.text.font_from_psf2(@bitcast(&psf), true)
font := render.text.font_from_psf2(@bitcast(&psf), false)
msg := "ableboard (tm) (patent pending):\n\0"
if font == null {
return
}
msg := "sticky note:\n\0"
msg_len := string.length(msg)
buf := memory.alloc(u8, 4096)
@inline(memory.copy, u8, msg, buf, msg_len)
cursor := buf + msg_len
bottom := buf + msg_len
if font == null {
return
};
@inline(memory.copy, u8, msg, buf, msg_len)
cursor := buf + msg_len;
*cursor = 95
draw(screen, window, font, buf);
*cursor = 0
draw_window(window, font, buf)
draw_screen(screen, window);
*cursor = 32
memory.outb(96, 238)
memory.outb(96, 238)
@ -60,32 +48,29 @@ example := fn(): void {
prev_input := @as(u8, 0xFF)
current_key := @as(u8, 0)
holding_timer := @as(u32, 0)
is_shift_pressed := @as(bool, false)
initial_delay := @as(u32, 50)
repeat_delay := @as(u32, 7)
holding_timer := 0
loop {
input := memory.inb(96)
is_release := (input & 0x80) != 0
key_code := input & 0x7F
if input != prev_input {
if is_release {
if key_code == current_key {
if (input & 0x80) != 0 {
if (input & 0x7F) == current_key {
current_key = 0
holding_timer = 0
} else if input == 0xAA | input == 0xB6 {
is_shift_pressed = false
} else if input == 0x9D {
is_ctrl_pressed = false
}
} else {
if input == 0x2A | input == 0x36 {
is_shift_pressed = true
} else if input == 0x1D {
is_ctrl_pressed = true
} else {
current_key = input
holding_timer = 1
cursor = handle_char(map_keys(current_key, is_shift_pressed), cursor, buf)
cursor = handle_char(map_keys(current_key), cursor, bottom)
}
}
prev_input = input
@ -95,13 +80,14 @@ example := fn(): void {
holding_timer += 1
if holding_timer >= initial_delay {
cursor = handle_char(map_keys(current_key, is_shift_pressed), cursor, buf)
cursor = handle_char(map_keys(current_key), cursor, bottom)
holding_timer = initial_delay - repeat_delay
}
};
*cursor = 95
draw(screen, window, font, buf);
*cursor = 0
draw_window(window, font, buf)
draw_screen(screen, window);
*cursor = 32
if holding_timer > 0 & current_key != 0 {
if (memory.inb(96) & 0x80) != 0 {
@ -114,20 +100,52 @@ example := fn(): void {
return
}
draw := fn(screen: render.Surface, window: render.Surface, font: render.text.Font, buf: ^u8): void {
render.clear(screen, render.black)
render.clear(window, render.black)
render.put_rect(window, .(0, 0), .(window.width - 1, window.height - 1), render.white)
render.put_text(window, font, .(7, 7), render.gray, buf)
render.put_surface(screen, window, .(100, 100), false)
render.sync(screen)
handle_char := fn(char: u8, cursor: ^u8, bottom: ^u8): ^u8 {
if char == 0 {
return cursor
}
if is_ctrl_pressed & char == 48 {
cursor = bottom
} else if char != 0x8 {
*cursor = char
return cursor + 1
} else if char == 0xA {
*cursor = 32
cursor += 1;
*cursor = 92
return cursor + 1
} else if cursor > bottom {
cursor -= 1;
*cursor = 32
return cursor
}
return cursor
}
ps2_table := [u8].(0x0, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x8, 0x9, 0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69, 0x6F, 0x70, 0x5B, 0x5D, 0xA, 0x0, 0x61, 0x73, 0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x3B, 0x27, 0x60, 0x0, 0x5C, 0x7A, 0x78, 0x63, 0x76, 0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2F, 0x0, 0x2A, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x8, 0x9, 0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49, 0x4F, 0x50, 0x7B, 0x7D, 0xA, 0x0, 0x41, 0x53, 0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x3A, 0x22, 0x7E, 0x0, 0x7C, 0x5A, 0x58, 0x43, 0x56, 0x42, 0x4E, 0x4D, 0x3C, 0x3E, 0x3F, 0x0, 0x0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
map_keys := fn(scancode: u8, shift: bool): u8 {
if shift {
map_keys := fn(scancode: u8): u8 {
if is_shift_pressed {
return ps2_table[scancode + 0x40]
}
return ps2_table[scancode]
}
ps2_table := [u8].(0x0, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x8, 0x9, 0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69, 0x6F, 0x70, 0x5B, 0x5D, 0xA, 0x0, 0x61, 0x73, 0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x3B, 0x27, 0x60, 0x0, 0x5C, 0x7A, 0x78, 0x63, 0x76, 0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2F, 0x0, 0x2A, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x8, 0x9, 0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49, 0x4F, 0x50, 0x7B, 0x7D, 0xA, 0x0, 0x41, 0x53, 0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x3A, 0x22, 0x7E, 0x0, 0x7C, 0x5A, 0x58, 0x43, 0x56, 0x42, 0x4E, 0x4D, 0x3C, 0x3E, 0x3F, 0x0, 0x0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
$padding := 7
draw_window := fn(window: render.Surface, font: render.text.Font, buf: ^u8): void {
render.clear(window, render.light_yellow)
line := font.height + font.line_gap + padding - 1
render.put_rect(window, .(0, 0), .(window.width - 1, window.height - 1), render.black)
loop if line >= window.height break else {
render.put_hline(window, line, padding, window.width - padding, render.yellow)
line += font.height + font.line_gap
}
render.put_text(window, font, .(padding, padding), render.black, buf)
}
draw_screen := fn(screen: render.Surface, window: render.Surface): void {
render.clear(screen, render.light_blue)
render.put_surface(screen, window, .(100, 100), false)
render.sync(screen)
}