Context
Add mouse-based text selection, copy and paste functionality to meniOS console and mosh shell.
Difficulty Assessment
8/10 - Complex, multi-layered feature requiring coordination across several subsystems.
Architecture Overview
This feature requires changes across multiple layers:
Hardware Layer → Input Events → Console → Clipboard → Shell
Prerequisites
1. Mouse Hardware Support
2. Console/Framebuffer Enhancements
3. Clipboard Implementation
4. Terminal Emulation
5. Shell Integration (mosh)
Implementation Phases
Phase 1: Console Text Selection (Core Feature)
Mouse Selection Logic
typedef struct console_selection {
int start_row , start_col ;
int end_row , end_col ;
bool active ;
bool complete ;
} console_selection_t ;
Selection Rendering
Invert colors for selected text
Update selection in real-time as mouse drags
Support both character-by-character and rectangular selection
User Experience
[Left-click and drag to select text]
[Text highlights as you drag]
[Release button to complete selection]
Phase 2: Clipboard Operations
Copy Operation
Left-click drag + release - Auto-copy on selection complete
Or: Require Ctrl+C while selected
Or: Middle-click copies (X11 style)
Clipboard Structure
typedef struct clipboard {
char * text ;
size_t length ;
size_t capacity ;
uint64_t timestamp ;
} clipboard_t ;
Copy Implementation
// Extract selected text from console buffer
int console_copy_selection (console_selection_t * sel , clipboard_t * clip );
Phase 3: Paste Operation
Paste Trigger
Middle-click - Traditional Unix paste
Or: Shift+Insert - Windows/modern style
Or: Ctrl+V - Alternative
Paste to Shell
// Insert clipboard text into mosh line buffer
int mosh_paste_from_clipboard (clipboard_t * clip );
Paste Handling
Insert at current cursor position
Handle multi-line paste
Filter dangerous characters (avoid auto-exec)
Show paste preview for large pastes?
Phase 4: Advanced Features (Optional)
Word selection : Double-click selects word
Line selection : Triple-click selects line
Rectangular selection : Alt+drag for column selection
Scrollback selection : Select from scrollback buffer
Copy formatting : Preserve color/attributes (future)
Technical Challenges
1. Character Grid Tracking
The console needs to know:
What character is at position (x, y)
Character attributes (color, bold, etc.)
Mapping pixel coordinates → character cells
typedef struct console_cell {
char ch ;
uint8_t fg_color ;
uint8_t bg_color ;
uint8_t attrs ;
} console_cell_t ;
console_cell_t console_buffer [ROWS ][COLS ];
2. Selection Rendering
Need to:
Redraw selection region efficiently
Handle partial character cells at edges
Update in real-time without flicker
Clear old selection before new one
3. Mouse Coordinate Mapping
// Convert mouse coordinates to console position
typedef struct mouse_to_console {
int pixel_x , pixel_y ; // Mouse position
int col , row ; // Console cell
int char_width , char_height ; // Font metrics
} mouse_to_console_t ;
void map_mouse_to_console (int x , int y , int * row , int * col ) {
* col = x / CHAR_WIDTH ;
* row = y / CHAR_HEIGHT ;
}
4. Clipboard Size Management
Limit clipboard to reasonable size (64KB?)
Handle clipboard overflow
Clear old clipboard on new copy
5. Multi-line Paste Safety
// Filter clipboard before paste
bool is_safe_char (char c ) {
return c >= 32 && c < 127 ; // Printable ASCII
}
void filter_clipboard (char * text ) {
// Remove newlines or warn user
// Filter control characters
// Handle special cases
}
User Experience Design
Selection UX (X11 Style - Recommended)
Left-click drag - Select text (auto-copy on release)
Middle-click - Paste at cursor
Right-click - Context menu (future)
Alternative: Windows Style
Left-click drag - Select text only
Ctrl+C - Copy selection
Ctrl+V or Shift+Insert** - Paste
Visual Feedback
Selected text: inverted colors
Paste operation: brief highlight of pasted text
Cursor position: visible caret
Dependencies
Hard Requirements
Soft Requirements
Acceptance Criteria
Timeline Estimate
With Prerequisites Complete
Phase 1 (Selection): 2-3 weeks
Phase 2 (Clipboard): 1 week
Phase 3 (Paste): 1-2 weeks
Phase 4 (Polish): 1 week
Total : 5-7 weeks
Without Prerequisites
Alternative: Simpler Approach
Keyboard-Only Copy/Paste (Easier)
Skip mouse entirely, use keyboard:
Shift+Arrow keys - Select text
Ctrl+C - Copy
Ctrl+V - Paste
This requires:
Selection mode in shell
No mouse support needed
Much simpler implementation
Timeline : 1-2 weeks
Recommendation
Short term : Implement keyboard-based copy/paste (1-2 weeks)
Medium term : Add mouse drivers (Implement PS/2 mouse driver and input support #143 )
Long term : Add mouse selection (after drivers stable)
Or skip entirely if keyboard shortcuts sufficient for users.
Priority
Medium-Low - Nice to have, but not critical for shell milestone.
Mouse selection is standard in modern terminals (xterm, GNOME Terminal, Windows Terminal) but not essential for basic OS functionality.
Context
Add mouse-based text selection, copy and paste functionality to meniOS console and mosh shell.
Difficulty Assessment
8/10 - Complex, multi-layered feature requiring coordination across several subsystems.
Architecture Overview
This feature requires changes across multiple layers:
Prerequisites
1. Mouse Hardware Support
2. Console/Framebuffer Enhancements
3. Clipboard Implementation
4. Terminal Emulation
5. Shell Integration (mosh)
Implementation Phases
Phase 1: Console Text Selection (Core Feature)
Mouse Selection Logic
Selection Rendering
User Experience
Phase 2: Clipboard Operations
Copy Operation
Clipboard Structure
Copy Implementation
Phase 3: Paste Operation
Paste Trigger
Paste to Shell
Paste Handling
Phase 4: Advanced Features (Optional)
Technical Challenges
1. Character Grid Tracking
The console needs to know:
2. Selection Rendering
Need to:
3. Mouse Coordinate Mapping
4. Clipboard Size Management
5. Multi-line Paste Safety
User Experience Design
Selection UX (X11 Style - Recommended)
Alternative: Windows Style
Visual Feedback
Dependencies
Hard Requirements
Soft Requirements
Acceptance Criteria
Timeline Estimate
With Prerequisites Complete
Without Prerequisites
Alternative: Simpler Approach
Keyboard-Only Copy/Paste (Easier)
Skip mouse entirely, use keyboard:
This requires:
Recommendation
Or skip entirely if keyboard shortcuts sufficient for users.
Priority
Medium-Low - Nice to have, but not critical for shell milestone.
Mouse selection is standard in modern terminals (xterm, GNOME Terminal, Windows Terminal) but not essential for basic OS functionality.