diff options
| author | Gabriel Schneider <[email protected]> | 2026-06-29 11:07:01 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-06-29 12:06:49 -0300 |
| commit | a44d2c53cae8f39975a7e2ecb7c254618aec4ae8 (patch) | |
| tree | 0e2e4768d98922368615265a543a30b096ead856 | |
| parent | 8c0bce4983915b8fa079cc218fae93a2adcf4b0e (diff) | |
| download | pardes-a44d2c53cae8f39975a7e2ecb7c254618aec4ae8.tar.gz pardes-a44d2c53cae8f39975a7e2ecb7c254618aec4ae8.zip | |
scrollbar
| -rw-r--r-- | main.zig | 46 |
1 files changed, 43 insertions, 3 deletions
@@ -81,6 +81,7 @@ fn readPty(io: std.Io, gpa: std.mem.Allocator, pty: std.Io.File, loop: *Loop) !v const nrows = 64; const ncols = 100; +const term_x_padding = 3; pub fn main(init: std.process.Init) !void { const io = init.io; @@ -139,6 +140,15 @@ pub fn main(init: std.process.Init) !void { if (mouse.button == .wheel_up) { term.screens.active.scroll(.{ .delta_row = -1 }); } + + if (mouse.type == .press) { + if (mouse.button == .left and mouse.col <= term_x_padding) { + term.screens.active.scroll(.{ .delta_row = -(mouse.row) }); + } + if (mouse.button == .right and mouse.col <= term_x_padding) { + term.screens.active.scroll(.{ .delta_row = mouse.row }); + } + } }, .key_press => |key| { if (key.matches('c', .{ .ctrl = true })) { @@ -191,12 +201,37 @@ pub fn main(init: std.process.Init) !void { const win_child = win.child(.{ .border = .{ .where = .bottom }, + .x_off = term_x_padding, .height = nrows + 2, .width = ncols + 2, }); + + const win_scroll = win.child(.{ + .border = .{ .where = .none }, + .height = nrows + 2, + .width = term_x_padding - 1, + }); + + const scroll_pos = (@as(usize, win_scroll.height) * term.screens.active.pages.scrollbar().offset) / term.screens.active.pages.scrollbar().total; + const scroll_height = @max(1, (@as(usize, win_scroll.height) * term.screens.active.pages.scrollbar().len) / term.screens.active.pages.scrollbar().total); + + win_scroll.fill(.{ + .char = .{ .grapheme = " " }, + .style = .{ .bg = .{ .index = 4 } }, + }); + + for (0..term_x_padding) |col| { + for (0..scroll_height) |row| { + win_scroll.writeCell(@intCast(col), @intCast(scroll_pos + row), .{ + .char = .{ .grapheme = " " }, + .style = .{ .bg = .{ .index = 0 }, .fg = .{ .index = 6 } }, + }); + } + } + const win_dbg = win.child(.{ .border = .{ .where = .all }, - .x_off = ncols + 2, + .x_off = ncols + 2 + term_x_padding, .height = nrows + 2, .width = ncols + 2, }); @@ -207,9 +242,14 @@ pub fn main(init: std.process.Init) !void { const dbg_str = try std.fmt.bufPrintSentinel( &dbg_print_buf, - "c {} {}\npty pid {}\nwow it's working! debugging things will show here", + "c {} {}\npty pid {}\n wow it's working! debugging things will show here\n scroll {}/{} vis: {}\n", .{ - pty_master.handle, term.screens.active.cursor.x, term.screens.active.cursor.y, + pty_master.handle, + term.screens.active.cursor.x, + term.screens.active.cursor.y, + term.screens.active.pages.scrollbar().offset, + term.screens.active.pages.scrollbar().total, + term.screens.active.pages.scrollbar().len, }, 0, ); |
