1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! Terminal User Interface for learnerd.
//!
//! This module provides an interactive terminal interface for managing and viewing academic papers,
//! built using the `ratatui` library. The interface offers:
//!
//! - A split-pane view with paper list and details
//! - Keyboard-driven navigation
//! - Real-time paper information display
//! - PDF availability status and opening
//! - Vim-style navigation controls
//!
//! # Navigation
//!
//! The interface supports both arrow keys and vim-style navigation:
//! - `↑`/`k`: Move selection up
//! - `↓`/`j`: Move selection down
//! - `←`/`h`: Focus left pane
//! - `→`/`l`: Focus right pane
//! - `o`: Open PDF (if available)
//! - `q`: Quit application
//!
//! # Layout
//!
//! The interface is divided into two main sections:
//! - Left: List of papers with title and count
//! - Right: Detailed view of the selected paper including:
//! - Title
//! - Authors
//! - Source information
//! - Abstract (scrollable)
//! - PDF status
//!
//! # Implementation Notes
//!
//! The UI is built using a modular approach with:
//! - State management ([`state::UIState`])
//! - Consistent styling ([`styles`])
//! - Drawing logic ([`ui::UIDrawer`])
//!
//! This separation allows for clear responsibility boundaries and easier maintenance.
use io;
use ;
use ;
use ;
use *;
use UIState;
use UIDrawer;
/// Runs the Terminal User Interface.
///
/// This function initializes the terminal, sets up the display, and manages the main event loop.
/// It handles:
/// - Terminal setup and cleanup
/// - State initialization
/// - Event processing
/// - Screen rendering
///
/// The interface is restored to its original state when the function returns,
/// regardless of how it exits.
///
/// # Terminal Setup
///
/// The function configures the terminal for full-screen operation by:
/// - Enabling raw mode for direct input handling
/// - Entering alternate screen to preserve the original terminal content
/// - Setting up mouse capture for potential future mouse support
///
/// # Event Loop
///
/// The main loop handles:
/// - Redraw requests through `needs_redraw` flag
/// - Input events (keyboard, resize)
/// - Graceful shutdown on quit command
///
/// # Errors
///
/// Returns an error if:
/// - Database operations fail
/// - Terminal initialization fails
/// - Event handling fails
/// - Screen drawing fails
///
/// # Cleanup
///
/// On exit (either through error or normal termination), the function:
/// - Disables raw mode
/// - Restores the original screen
/// - Shows the cursor
/// - Disables mouse capture
pub async