You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enable scrolling through terminal history using the mouse wheel, providing a more intuitive way to review command output and logs.
Context
After mouse support is implemented (#143), the terminal should support scrolling through the scrollback buffer using the mouse wheel. This is a standard feature in modern terminals (xterm, GNOME Terminal, Windows Terminal, etc.) that significantly improves usability when reviewing long outputs, build logs, or debugging information.
Prerequisites:#143 (Mouse driver) must be complete
PS/2 Mouse Wheel Detection
// Mouse wheel events come as button 4 (scroll up) and button 5 (scroll down)// Or as Z-axis movement in IntelliMouse protocol#defineMOUSE_SCROLL_UP 4
#defineMOUSE_SCROLL_DOWN 5
structmouse_event {
intdx, dy; // Movement deltaintdz; // Wheel delta (IntelliMouse)uint8_tbuttons; // Button state
};
Event Delivery to Terminal
Mouse events delivered to /dev/mouse0 or /dev/input/mice
Terminal reads mouse events when in focus
Distinguish between wheel events and button clicks
#defineSCROLLBACK_LINES 1000 // Configurable
structterminal_scrollback {
char**lines; // Circular buffer of line pointerssize_tcapacity; // Total lines (default 1000)size_tcount; // Current number of linessize_thead; // Newest line indexsize_ttail; // Oldest line indexsize_tview_offset; // Current scroll position (0 = bottom)
};
Line Storage
Allocate lines dynamically as terminal output is generated
Oldest lines evicted when buffer full (circular buffer behavior)
Store line attributes (color, bold, etc.) alongside text
// When view_offset > 0, render from scrollback instead of current screenvoidterminal_render(structterminal*term) {
if (term->scrollback.view_offset>0) {
// Render from scrollback bufferrender_scrollback(term);
} else {
// Render current screen (normal operation)render_current_screen(term);
}
}
Phase 3: Mouse Wheel Scrolling Logic (2-3 days)
Scroll Handling
voidterminal_handle_mouse_event(structterminal*term, structmouse_event*evt) {
if (evt->dz>0|| (evt->buttons&MOUSE_SCROLL_UP)) {
// Scroll up (toward history)terminal_scroll_up(term, SCROLL_LINES_PER_TICK);
} elseif (evt->dz<0|| (evt->buttons&MOUSE_SCROLL_DOWN)) {
// Scroll down (toward present)terminal_scroll_down(term, SCROLL_LINES_PER_TICK);
}
}
#defineSCROLL_LINES_PER_TICK 3 // Lines per wheel notch
Scroll Constraints
Prevent scrolling past oldest line (top of buffer)
Auto-return to bottom on new output (configurable)
Reset scroll position on keyboard input (configurable)
Phase 4: Visual Indicators (1-2 days)
Scroll Position Indicator
[SCROLLBACK: -234 lines] ← Top-right corner when scrolled
[END] ← When at bottom (normal mode)
Scrollbar (Optional)
Vertical scrollbar on right edge
Position indicator showing current view relative to total history
Similar to tmux or screen scrollback
Phase 5: Keyboard Shortcuts (1-2 days)
In addition to mouse wheel, provide keyboard alternatives:
$ make build
# Lots of compiler output...# Scroll up with mouse wheel to review warnings# Auto-scrolls back to bottom when build finishes
2. Debugging Kernel Logs
$ dmesg | tail -100
# Scroll through boot messages# Identify where driver failed to load
3. Long File Listings
$ ls -la /HOME
# Hundreds of files# Scroll up to see files at the top
4. Interactive Programs
Doom startup messages
Test suite output
Git log review
Technical Considerations
Memory Management
Default buffer: 1000 lines × 80 chars = ~80 KB
Worst case: 10000 lines × 160 chars = ~1.6 MB
Use circular buffer to avoid reallocation
Free old lines when buffer wraps
Rendering Performance
Only re-render when scroll position changes
Use dirty flag to avoid unnecessary redraws
Consider double-buffering for smooth scrolling
Concurrency
Lock scrollback buffer during updates
Coordinate between output thread and input thread
Prevent race conditions on view_offset
Edge Cases
Handle terminal resize (reflow lines?)
Clear scrollback on clear command (optional)
Preserve scrollback across shell restarts?
Multiple terminals with independent scrollback
Example Terminal Workflow
User types: make build
Output: [100 lines of compiler output]
User scrolls mouse wheel up:
→ view_offset increases
→ Render shows lines -50 to -1 (50 lines back)
→ Indicator shows "[SCROLLBACK: -50 lines]"
User scrolls more:
→ view_offset = 100
→ Shows oldest lines in buffer
→ Indicator shows "[SCROLLBACK: -100 lines (TOP)]"
User presses a key:
→ view_offset resets to 0
→ Returns to current output
→ Indicator shows "[END]"
Testing Strategy
Unit Tests
Scrollback buffer insertion/eviction
Circular buffer wraparound
Line retrieval at various offsets
Integration Tests
Mouse wheel events → scroll position changes
Keyboard shortcuts work correctly
Auto-scroll on output
Reset scroll on input
Manual Testing
# Generate long output
$ seq 1 1000
# Scroll up with mouse wheel# Verify lines 1-50 visible# Scroll down to bottom# Type command → auto-returns to bottom# Test keyboard shortcuts# Shift+PgUp → scrolls up# Shift+Home → jumps to top# Shift+End → jumps to bottom
Goal
Enable scrolling through terminal history using the mouse wheel, providing a more intuitive way to review command output and logs.
Context
After mouse support is implemented (#143), the terminal should support scrolling through the scrollback buffer using the mouse wheel. This is a standard feature in modern terminals (xterm, GNOME Terminal, Windows Terminal, etc.) that significantly improves usability when reviewing long outputs, build logs, or debugging information.
Current State
Terminal Capabilities
Mouse Support Status
Proposed Implementation
Phase 1: Mouse Wheel Event Handling (2-3 days)
Prerequisites: #143 (Mouse driver) must be complete
PS/2 Mouse Wheel Detection
Event Delivery to Terminal
Phase 2: Scrollback Buffer Implementation (4-5 days)
Buffer Design
Line Storage
Integration with VGA Renderer
Phase 3: Mouse Wheel Scrolling Logic (2-3 days)
Scroll Handling
Scroll Constraints
Phase 4: Visual Indicators (1-2 days)
Scroll Position Indicator
Scrollbar (Optional)
Phase 5: Keyboard Shortcuts (1-2 days)
In addition to mouse wheel, provide keyboard alternatives:
Phase 6: Configuration and Polish (1-2 days)
Configurable Options
/dev/tty ioctl Extensions
Implementation Phases Summary
Total Effort: 2-3 weeks (12-17 days)
Definition of Done
Dependencies
Critical Blockers
Foundation (Complete)
Related (Optional)
Use Cases
1. Reviewing Build Output
2. Debugging Kernel Logs
3. Long File Listings
4. Interactive Programs
Technical Considerations
Memory Management
Rendering Performance
Concurrency
Edge Cases
clearcommand (optional)Example Terminal Workflow
Testing Strategy
Unit Tests
Integration Tests
Manual Testing
Timeline
Estimated effort: 2-3 weeks (12-17 days)
Blocked by: #143 (Mouse driver implementation)
Priority
Low - Nice-to-have quality-of-life feature, not critical for core functionality
User Experience Benefits
Before (Current)
After (With Scrollback)
References
Related Issues
Status: Blocked by #143 (Mouse driver)
Priority: Low (nice-to-have UX improvement)
Complexity: Medium (2-3 weeks with mouse driver complete)