Compare commits
4 commits
f3dcd5acbc
...
f14982abf4
| Author | SHA1 | Date | |
|---|---|---|---|
| f14982abf4 | |||
| ccab4510ea | |||
| 360af2f0cb | |||
| e62832fde6 |
14 changed files with 437 additions and 310 deletions
105
README.md
105
README.md
|
|
@ -1,71 +1,92 @@
|
||||||
# wat
|
# wat
|
||||||
|
|
||||||
`wat` is a terminal UI wrapper around [Watson](https://tailordev.github.io/Watson/) that lets you browse and launch timers via a keyboard-driven interface.
|
`wat` is a TUI interface for [Watson](https://tailordev.github.io/Watson/)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Goals & Workflow
|
## Overview and screenshots
|
||||||
- Never type `watson start ...` again—start/stop timers with `Enter`.
|
|
||||||
- Maintain three panes simultaneously:
|
|
||||||
1. **Permanent Items** – curated recurring tasks defined in `state.yaml`.
|
|
||||||
2. **Recurring Items** – semi-regular tasks you hop between.
|
|
||||||
3. **Ad-Hoc Items** – last ~20 one-offs, automatically tracked.
|
|
||||||
- Highlight clearly when a timer is running (bold green) vs idle (yellow).
|
|
||||||
- Keep everything human-editable: YAML state/config under `~/.config/wat`.
|
|
||||||
|
|
||||||
---
|
### Main Interface
|
||||||
|
|
||||||
## Key Features
|
Wat's main screen consists of 3 groupings of tasks, each of which is optional and can be disabled via settings. The idea here is to provide an interface to toggle what task you are currently working on, with lots of options for editing, annotating, and reporting on that time spent later. When you track time on a task, it will show up in the `view` page (v), which is analogous to `watson log`.
|
||||||
- **Navigation**: `j/k` or arrows move within a pane; `h/l`, arrows, or `Ctrl+n/p` switch panes; `q` quits.
|
|
||||||
- **Timer control**: `Enter` toggles the selected item. Starting a different item automatically stops the previous timer.
|
|
||||||
- **New entries**: `n` launches a modal (project + optional tag). Item is added to the current pane.
|
|
||||||
- **Project reassignment**: `p` opens a modal to change the tags for the selected item.
|
|
||||||
- **Log viewing**: `v` opens Watson's log viewer with daily/weekly/monthly views. Use `d`/`w`/`m` to switch periods, `g` to toggle grouping by date/project, `j`/`k` to select entries, `e` to edit, `x` to delete, `c` to copy to clipboard.
|
|
||||||
- **Deletion**: `d` removes the selected entry; no noisy status message.
|
|
||||||
- **Config editing**:
|
|
||||||
- `Ctrl+e` edits task config (`state.yaml`).
|
|
||||||
- `c` edits app config (`config.yaml`).
|
|
||||||
- **Help overlays**: `?` for help, `c` inside help for config instructions.
|
|
||||||
|
|
||||||
---
|

|
||||||
|
|
||||||
## Files & Persistence
|
The three available categories of task are `Permanent Items`, for tasks that will likely be part of your workflow for the forseeable future, `Recurring Items` for scheduled weekly meetings or tasks which come and go, and `Ad-Hoc Items` for things that will not recur. Eventually, I plan to make the `Ad-Hoc` section display items in reverse order, and remove ones beyond 10 items. This will not delete past time entries for those items.
|
||||||
```
|
|
||||||
~/.config/wat/
|
|
||||||
├─ state.yaml # serialized AppState (items, selections, active timer)
|
|
||||||
└─ config.yaml # UI/app options (help hints, allowed projects, etc.)
|
|
||||||
```
|
|
||||||
- `state.yaml` and `config.yaml` use `serde_yaml` for readability.
|
|
||||||
|
|
||||||
---
|
### The 'View Entries' Interface
|
||||||
|
|
||||||
|
Pressing `v` on the main interface will take the user to the interface for viewing actual time entries, as created from the main interface. The default view is the 'day' view, which shows your entries for the current day. You can press `g` to `group` or `ungroup` your tasks by project. You can also navigate using `h,j,k,l` between entries, entries grouped by project, grouped by day, or all entries. You can press `y` to copy the selection to your clipboard.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Weekly and Monthly View
|
||||||
|
|
||||||
|
When in the `view` interface, you can switch to a weekly or monthly view using `w` or `m`. Grouping works the same way in these views as in the `daily` view. You can also press 'r' to reverse the order of the days in the display.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Individual entry editing
|
||||||
|
|
||||||
|
When an entry is selected, you can press `e` to edit the full `watson edit` configuration for your selected entry in your chosen `$EDITOR`
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Backfill gap and overlap correction
|
||||||
|
|
||||||
|
The `ungrouped` view can also be used as an error resolution and quick edit page using the `b` (backfill) key. Here, `backfill` roughly translates to 'take the current entry and make its start time equal to the stop time of the previous entry'. The `b` key will do nothing if the entry is the first entry of the day.
|
||||||
|
|
||||||
|
In the ungrouped view, entries are chronological. Entries with gaps betweent them are denoted by a blank line with three dashes (---). Entries which overlap with the previous entry (which is likely an error and should never happen) are colored yellow. In both cases, pressing `b` will resolve the issue. (You may want gaps in certain cases such as lunch breaks or short breaks, so don't do this without thinking about the context)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Rounding
|
||||||
|
|
||||||
|
The time tracking software I use at work only accepts logging for tasks and projects in 15m intervals, so I included a hotkey `R` to automatically round tasks to the nearest 15m. This reduces a little burden when reporting time, but keep in mind that if you get unlucky and many entries are rounded down you may end up under-reporting. Keep this in mind and always sanity check your time.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Annotation
|
||||||
|
|
||||||
|
Watson actually doesn't include any options for annotating time entries by default! However, it does allow you to technically assign multiple 'tags' to an entry. In `wat`, we've been treating the `tag` as the name of the time entry more-or-less. When an entry is completed, you can navigate to the view page and press `a` to add a second tag if you want to be more specific about that particular entry. In practice, it looks just fine in the final reporting.
|
||||||
|
|
||||||
## Building & Running
|
## Building & Running
|
||||||
```
|
```
|
||||||
cargo build
|
cargo build
|
||||||
cargo run
|
cargo run
|
||||||
```
|
```
|
||||||
Requires `watson` on your `PATH` with a configured workspace.
|
Requires `watson` on your `PATH` with a configured workspace. The application will automatically create the necessary `~/.config/watson` directory structure on first run if it doesn't exist.
|
||||||
|
|
||||||
|
Otherwise, just download the latest release for a relatively-stable binary.
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Keybindings (Summary)
|
## Keybindings (Summary)
|
||||||
| Keys | Action |
|
| Keys | Action |
|
||||||
|------|--------|
|
|-------------------|-------------------------------------------------------------------|
|
||||||
| `j` / `k`, arrows | Move selection |
|
| `j` / `k`, arrows | Move selection |
|
||||||
| `h` / `l`, arrows, `Ctrl+n` / `Ctrl+p` | Switch panes |
|
|
||||||
| `Enter` | Start/stop timer |
|
| `Enter` | Start/stop timer |
|
||||||
| `n` | New entry (project + optional tag) |
|
| `n` | New entry (project + optional tag) |
|
||||||
| `p` | Reassign tag for selected item |
|
| `p` | Reassign project for selected item |
|
||||||
| `v` | View Watson log (d/w/m period, g group, e edit, x delete, c copy) |
|
| `v` | View Watson log (d/w/m period, g group, e edit, x delete, y copy) |
|
||||||
| `d` | Delete entry |
|
| `x` | Delete entry |
|
||||||
| `Ctrl+e` | Edit task config (`state.yaml`) |
|
| `Ctrl+e` | Edit task config (`state.yaml`) |
|
||||||
| `c` | Edit app config (`config.yaml`) or show config help |
|
| `c` | Edit app config (`config.yaml`) or show config help |
|
||||||
| `?` | Help screen |
|
| `?` | Help screen |
|
||||||
| `q` | Quit |
|
| `q` | Quit |
|
||||||
|
|
||||||
---
|
## TODO
|
||||||
|
|
||||||
## TODO / Follow-ups
|
### Architecture
|
||||||
- Add inline editing of permanent/recurring items instead of dropping to `$EDITOR`.
|
Eventually I need to refactor this whole thing, which was mostly written by LLMs. I want to make the underlying data structure for the view display much more solidly defined so that it is more extensible. It should be stored in some kind of nested structure which is aware of ordering as well as grouping and can be dynamically (and optimistically) updated without refreshing the UI when appropriate. Once that is resolved, I can focus on the following upgrades:
|
||||||
- Consider status messaging for critical errors (currently unused after deleting the delete confirmation).
|
|
||||||
- Add tests/snapshots for UI components.
|
- Adding a `/` command to narrow down entries by fuzzy searching
|
||||||
|
- Perhaps having a universal interface for entries going back more than a month
|
||||||
|
- An option for people who don't want to copy / paste their hours into another interface
|
||||||
|
- Actually ordering the ad-hoc section by most recently used one-offs, and implementing a good way to auto-prune that list
|
||||||
|
- Print the time totals at the project-level for each day
|
||||||
|
- Some kind of API for the real weirdos out there (sean)
|
||||||
|
|
||||||
|
### Terminal interface
|
||||||
|
Another big reason I need to drill down and rewrite this with human hands is the difference between the mac and linux terminal handling. I need to learn to use ratatui well enough to understand how to develop for both platforms at once. I originally coded this on a linux machine, and I had a much smoother experience which was largely broken on Mac. This lead to a lot of spaghettification supporting mac, and some of the things I had working on linux are still not working on mac.
|
||||||
|
|
|
||||||
BIN
assets/0-track-time.webm
Normal file
BIN
assets/0-track-time.webm
Normal file
Binary file not shown.
BIN
assets/1-main-view.webm
Normal file
BIN
assets/1-main-view.webm
Normal file
Binary file not shown.
BIN
assets/2-daily-view-and-proj-selection.webm
Normal file
BIN
assets/2-daily-view-and-proj-selection.webm
Normal file
Binary file not shown.
BIN
assets/3-weekly-view-and-day-selection.webm
Normal file
BIN
assets/3-weekly-view-and-day-selection.webm
Normal file
Binary file not shown.
BIN
assets/4-full-individual-editing.webm
Normal file
BIN
assets/4-full-individual-editing.webm
Normal file
Binary file not shown.
BIN
assets/5-backfill-gap-and-overlap-correction.webm
Normal file
BIN
assets/5-backfill-gap-and-overlap-correction.webm
Normal file
Binary file not shown.
BIN
assets/6-rounding.webm
Normal file
BIN
assets/6-rounding.webm
Normal file
Binary file not shown.
BIN
assets/7-annotation.webm
Normal file
BIN
assets/7-annotation.webm
Normal file
Binary file not shown.
BIN
assets/add-task.webm
Normal file
BIN
assets/add-task.webm
Normal file
Binary file not shown.
1
assets/sample-conversion.sh
Normal file
1
assets/sample-conversion.sh
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ffmpeg -i add-task.mov -c:v libvpx-vp9 -b:v 0 -crf 30 -pix_fmt yuv420p add-task.webm
|
||||||
BIN
assets/wat.png
Normal file
BIN
assets/wat.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 161 KiB |
401
src/app.rs
401
src/app.rs
|
|
@ -28,7 +28,7 @@ pub enum Screen {
|
||||||
pub enum LogViewPeriod {
|
pub enum LogViewPeriod {
|
||||||
Day,
|
Day,
|
||||||
Week,
|
Week,
|
||||||
Month,
|
Month, // Represents the last 31 days
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum LogViewDayOrder {
|
pub enum LogViewDayOrder {
|
||||||
|
|
@ -36,11 +36,13 @@ pub enum LogViewDayOrder {
|
||||||
ReverseChronological, // Newest first (default)
|
ReverseChronological, // Newest first (default)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum LogViewGrouping {
|
pub enum LogViewGrouping {
|
||||||
ByDate,
|
ByDate,
|
||||||
ByProject,
|
ByProject,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum LogViewSelection {
|
pub enum LogViewSelection {
|
||||||
Entry, // Individual entry selected
|
Entry, // Individual entry selected
|
||||||
Project, // Whole project selected (ByProject mode only)
|
Project, // Whole project selected (ByProject mode only)
|
||||||
|
|
@ -101,7 +103,7 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to determine if a line is an entry line based on grouping mode
|
// Helper to determine if a line is an entry line based on grouping mode
|
||||||
fn is_entry_line(&self, line: &str) -> bool {
|
pub fn is_entry_line(&self, line: &str) -> bool {
|
||||||
// Exclude separator lines (time gap markers)
|
// Exclude separator lines (time gap markers)
|
||||||
if line.trim() == "---" {
|
if line.trim() == "---" {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -113,7 +115,30 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ensure_watson_directories() -> anyhow::Result<()> {
|
||||||
|
// Create watson config directory if it doesn't exist
|
||||||
|
let watson_dir = dirs::config_dir()
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("Could not find config directory"))?
|
||||||
|
.join("watson");
|
||||||
|
|
||||||
|
if !watson_dir.exists() {
|
||||||
|
std::fs::create_dir_all(&watson_dir)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure frames file exists
|
||||||
|
let frames_path = watson_dir.join("frames");
|
||||||
|
if !frames_path.exists() {
|
||||||
|
// Create an empty frames file (empty JSON array)
|
||||||
|
std::fs::write(&frames_path, "[]")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new() -> anyhow::Result<Self> {
|
pub fn new() -> anyhow::Result<Self> {
|
||||||
|
// Ensure watson directories and files exist
|
||||||
|
Self::ensure_watson_directories()?;
|
||||||
|
|
||||||
let config = Config::load()?;
|
let config = Config::load()?;
|
||||||
let mut state = AppState::load()?;
|
let mut state = AppState::load()?;
|
||||||
|
|
||||||
|
|
@ -466,6 +491,7 @@ impl App {
|
||||||
self.needs_clear = true;
|
self.needs_clear = true;
|
||||||
}
|
}
|
||||||
KeyCode::Char('j') | KeyCode::Down => {
|
KeyCode::Char('j') | KeyCode::Down => {
|
||||||
|
let old_selected = self.log_view_selected;
|
||||||
match self.log_view_selection_level {
|
match self.log_view_selection_level {
|
||||||
LogViewSelection::Entry => {
|
LogViewSelection::Entry => {
|
||||||
// Move to next entry
|
// Move to next entry
|
||||||
|
|
@ -485,8 +511,13 @@ impl App {
|
||||||
// No navigation at All level - already selecting everything
|
// No navigation at All level - already selecting everything
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Update scroll if selection changed
|
||||||
|
if self.log_view_selected != old_selected {
|
||||||
|
self.update_log_view_scroll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Char('k') | KeyCode::Up => {
|
KeyCode::Char('k') | KeyCode::Up => {
|
||||||
|
let old_selected = self.log_view_selected;
|
||||||
match self.log_view_selection_level {
|
match self.log_view_selection_level {
|
||||||
LogViewSelection::Entry => {
|
LogViewSelection::Entry => {
|
||||||
// Move to previous entry
|
// Move to previous entry
|
||||||
|
|
@ -506,6 +537,10 @@ impl App {
|
||||||
// No navigation at All level - already selecting everything
|
// No navigation at All level - already selecting everything
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Update scroll if selection changed
|
||||||
|
if self.log_view_selected != old_selected {
|
||||||
|
self.update_log_view_scroll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Char('e') => {
|
KeyCode::Char('e') => {
|
||||||
// Only allow edit when selecting individual entry
|
// Only allow edit when selecting individual entry
|
||||||
|
|
@ -538,6 +573,7 @@ impl App {
|
||||||
}
|
}
|
||||||
KeyCode::Char('h') | KeyCode::Left => {
|
KeyCode::Char('h') | KeyCode::Left => {
|
||||||
// Zoom out selection level
|
// Zoom out selection level
|
||||||
|
let old_level = self.log_view_selection_level;
|
||||||
self.log_view_selection_level = match (&self.log_view_selection_level, &self.log_view_grouping) {
|
self.log_view_selection_level = match (&self.log_view_selection_level, &self.log_view_grouping) {
|
||||||
(LogViewSelection::All, _) => LogViewSelection::All, // Already at highest
|
(LogViewSelection::All, _) => LogViewSelection::All, // Already at highest
|
||||||
(LogViewSelection::Day, _) => LogViewSelection::All,
|
(LogViewSelection::Day, _) => LogViewSelection::All,
|
||||||
|
|
@ -548,6 +584,7 @@ impl App {
|
||||||
}
|
}
|
||||||
KeyCode::Char('l') | KeyCode::Right => {
|
KeyCode::Char('l') | KeyCode::Right => {
|
||||||
// Zoom in selection level
|
// Zoom in selection level
|
||||||
|
let old_level = self.log_view_selection_level;
|
||||||
self.log_view_selection_level = match (&self.log_view_selection_level, &self.log_view_grouping) {
|
self.log_view_selection_level = match (&self.log_view_selection_level, &self.log_view_grouping) {
|
||||||
(LogViewSelection::Entry, _) => LogViewSelection::Entry, // Already at lowest
|
(LogViewSelection::Entry, _) => LogViewSelection::Entry, // Already at lowest
|
||||||
(LogViewSelection::Project, _) => LogViewSelection::Entry,
|
(LogViewSelection::Project, _) => LogViewSelection::Entry,
|
||||||
|
|
@ -589,9 +626,11 @@ impl App {
|
||||||
KeyCode::PageDown => {
|
KeyCode::PageDown => {
|
||||||
self.log_view_selected = (self.log_view_selected + 10)
|
self.log_view_selected = (self.log_view_selected + 10)
|
||||||
.min(self.log_view_frame_indices.len().saturating_sub(1));
|
.min(self.log_view_frame_indices.len().saturating_sub(1));
|
||||||
|
self.update_log_view_scroll();
|
||||||
}
|
}
|
||||||
KeyCode::PageUp => {
|
KeyCode::PageUp => {
|
||||||
self.log_view_selected = self.log_view_selected.saturating_sub(10);
|
self.log_view_selected = self.log_view_selected.saturating_sub(10);
|
||||||
|
self.update_log_view_scroll();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
|
|
@ -610,6 +649,9 @@ impl App {
|
||||||
LogViewGrouping::ByDate => self.format_by_date(),
|
LogViewGrouping::ByDate => self.format_by_date(),
|
||||||
LogViewGrouping::ByProject => self.format_by_project(),
|
LogViewGrouping::ByProject => self.format_by_project(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update scroll position after formatting
|
||||||
|
self.update_log_view_scroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_by_date(&mut self) {
|
fn format_by_date(&mut self) {
|
||||||
|
|
@ -1014,10 +1056,15 @@ impl App {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Debug what we're copying
|
||||||
|
std::fs::write("/tmp/wat_copy_debug.log", format!("Selection level: {:?}\nSelected index: {}\nText to copy:\n{}\n", self.log_view_selection_level, self.log_view_selected, text)).ok();
|
||||||
|
|
||||||
// Copy to clipboard using the persistent clipboard instance
|
// Copy to clipboard using the persistent clipboard instance
|
||||||
if let Some(ref mut clipboard) = self.clipboard {
|
if let Some(ref mut clipboard) = self.clipboard {
|
||||||
if let Err(e) = clipboard.set_text(&text) {
|
if let Err(e) = clipboard.set_text(&text) {
|
||||||
self.set_status_message(format!("Failed to copy: {}", e));
|
self.set_status_message(format!("Failed to copy: {}", e));
|
||||||
|
} else {
|
||||||
|
self.set_status_message(format!("Copied {} chars to clipboard", text.len()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Try to create a new clipboard if we don't have one
|
// Try to create a new clipboard if we don't have one
|
||||||
|
|
@ -1025,6 +1072,8 @@ impl App {
|
||||||
Ok(mut clipboard) => {
|
Ok(mut clipboard) => {
|
||||||
if let Err(e) = clipboard.set_text(&text) {
|
if let Err(e) = clipboard.set_text(&text) {
|
||||||
self.set_status_message(format!("Failed to copy: {}", e));
|
self.set_status_message(format!("Failed to copy: {}", e));
|
||||||
|
} else {
|
||||||
|
self.set_status_message(format!("Copied {} chars to clipboard", text.len()));
|
||||||
}
|
}
|
||||||
self.clipboard = Some(clipboard);
|
self.clipboard = Some(clipboard);
|
||||||
}
|
}
|
||||||
|
|
@ -1053,30 +1102,70 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_selected_project_text(&self) -> String {
|
fn get_selected_project_text(&self) -> String {
|
||||||
// Find which project group the selected entry belongs to
|
// Find all project headers and their entry ranges
|
||||||
let mut current_project_lines = Vec::new();
|
let mut projects = Vec::new(); // (first_entry_index, project_line_index)
|
||||||
let mut frame_count = 0;
|
let mut entry_count = 0;
|
||||||
let mut found = false;
|
let mut expecting_first_entry = false;
|
||||||
|
let mut current_project_line_index = 0;
|
||||||
|
|
||||||
for line in &self.log_view_content {
|
for (line_index, line) in self.log_view_content.iter().enumerate() {
|
||||||
if line.starts_with(" ") && !line.starts_with("\t") {
|
if line.starts_with(" ") && !line.starts_with(" ") && !line.starts_with("\t") {
|
||||||
// This is a project header
|
// This is a project header
|
||||||
if found {
|
current_project_line_index = line_index;
|
||||||
break; // We've collected the target project
|
expecting_first_entry = true;
|
||||||
}
|
|
||||||
current_project_lines.clear();
|
|
||||||
current_project_lines.push(line.clone());
|
|
||||||
} else if self.is_entry_line(line) {
|
} else if self.is_entry_line(line) {
|
||||||
// Entry within a project
|
if expecting_first_entry {
|
||||||
current_project_lines.push(line.clone());
|
// This is the first entry of a project
|
||||||
if frame_count == self.log_view_selected {
|
projects.push((entry_count, current_project_line_index));
|
||||||
found = true;
|
expecting_first_entry = false;
|
||||||
}
|
}
|
||||||
frame_count += 1;
|
entry_count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
current_project_lines.join("\n")
|
// Find which project contains our current selection
|
||||||
|
let mut target_project_line_index = None;
|
||||||
|
for i in 0..projects.len() {
|
||||||
|
let project_start = projects[i].0;
|
||||||
|
let project_end = if i + 1 < projects.len() {
|
||||||
|
projects[i + 1].0
|
||||||
|
} else {
|
||||||
|
entry_count
|
||||||
|
};
|
||||||
|
|
||||||
|
if project_start <= self.log_view_selected && self.log_view_selected < project_end {
|
||||||
|
target_project_line_index = Some(projects[i].1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(target_line_index) = target_project_line_index {
|
||||||
|
// Collect all lines for the target project by position
|
||||||
|
let mut project_lines = Vec::new();
|
||||||
|
let mut in_target_project = false;
|
||||||
|
let mut current_project_line_index = 0;
|
||||||
|
|
||||||
|
for (line_index, line) in self.log_view_content.iter().enumerate() {
|
||||||
|
if line.starts_with(" ") && !line.starts_with(" ") && !line.starts_with("\t") {
|
||||||
|
// This is a project header
|
||||||
|
current_project_line_index = line_index;
|
||||||
|
if line_index == target_line_index {
|
||||||
|
in_target_project = true;
|
||||||
|
project_lines.push(line.clone());
|
||||||
|
} else if in_target_project {
|
||||||
|
// Hit a different project header, we're done
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if in_target_project && self.is_entry_line(line) {
|
||||||
|
// Entry within our target project
|
||||||
|
project_lines.push(line.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
project_lines.join("\n")
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_selected_day_text(&self) -> String {
|
fn get_selected_day_text(&self) -> String {
|
||||||
|
|
@ -1111,178 +1200,180 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn jump_to_next_project(&mut self) {
|
fn jump_to_next_project(&mut self) {
|
||||||
// Find the current project, then jump to first entry of next project
|
// Find all project headers and their first entry positions
|
||||||
let mut current_date = String::new();
|
let mut projects = Vec::new(); // (first_entry_index)
|
||||||
let mut current_project = String::new();
|
let mut entry_count = 0;
|
||||||
let mut selected_project = String::new();
|
let mut expecting_first_entry = false;
|
||||||
let mut selected_date = String::new();
|
|
||||||
let mut frame_count = 0;
|
|
||||||
let mut found_current = false;
|
|
||||||
|
|
||||||
// Find which project we're currently in
|
for line in &self.log_view_content {
|
||||||
for line in &self.log_view_content.clone() {
|
if line.starts_with(" ") && !line.starts_with(" ") && !line.starts_with("\t") {
|
||||||
if !line.starts_with('\t') && !line.is_empty() && !line.starts_with(" ") {
|
// This is a project header - next entry will be first entry of this project
|
||||||
current_date = line.clone();
|
expecting_first_entry = true;
|
||||||
} else if line.starts_with(" ") && !line.starts_with("\t") {
|
} else if self.is_entry_line(line) {
|
||||||
current_project = line.clone();
|
if expecting_first_entry {
|
||||||
|
// This is the first entry of a project
|
||||||
|
projects.push(entry_count);
|
||||||
|
expecting_first_entry = false;
|
||||||
}
|
}
|
||||||
|
entry_count += 1;
|
||||||
if self.is_entry_line(line) {
|
|
||||||
if frame_count == self.log_view_selected {
|
|
||||||
selected_project = current_project.clone();
|
|
||||||
selected_date = current_date.clone();
|
|
||||||
found_current = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
frame_count += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !found_current {
|
// Find which project contains our current selection and jump to next
|
||||||
|
for i in 0..projects.len() {
|
||||||
|
let project_start = projects[i];
|
||||||
|
let project_end = if i + 1 < projects.len() {
|
||||||
|
projects[i + 1]
|
||||||
|
} else {
|
||||||
|
entry_count
|
||||||
|
};
|
||||||
|
|
||||||
|
if project_start <= self.log_view_selected && self.log_view_selected < project_end {
|
||||||
|
// Found current project, jump to next if it exists
|
||||||
|
if i + 1 < projects.len() {
|
||||||
|
self.log_view_selected = projects[i + 1];
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now find the next project within the same day first, then next day
|
|
||||||
current_project = String::new();
|
|
||||||
current_date = String::new();
|
|
||||||
let mut past_selected = false;
|
|
||||||
frame_count = 0;
|
|
||||||
|
|
||||||
for line in &self.log_view_content.clone() {
|
|
||||||
if !line.starts_with('\t') && !line.is_empty() && !line.starts_with(" ") {
|
|
||||||
current_date = line.clone();
|
|
||||||
} else if line.starts_with(" ") && !line.starts_with("\t") {
|
|
||||||
current_project = line.clone();
|
|
||||||
if past_selected && current_project != selected_project {
|
|
||||||
// This is the next project, select its first entry
|
|
||||||
self.log_view_selected = frame_count;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.is_entry_line(line) {
|
|
||||||
if current_project == selected_project && current_date == selected_date {
|
|
||||||
past_selected = true;
|
|
||||||
}
|
|
||||||
frame_count += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn jump_to_previous_project(&mut self) {
|
fn jump_to_previous_project(&mut self) {
|
||||||
// Find the previous project and jump to its first entry
|
// Find all project headers and their first entry positions
|
||||||
let mut current_project = String::new();
|
let mut projects = Vec::new(); // (first_entry_index)
|
||||||
let mut _selected_project = String::new();
|
let mut entry_count = 0;
|
||||||
let mut frame_count = 0;
|
let mut expecting_first_entry = false;
|
||||||
let mut previous_project_first_entry = None;
|
|
||||||
let mut last_different_project_entry = None;
|
|
||||||
|
|
||||||
// Find which project we're currently in
|
for line in &self.log_view_content {
|
||||||
for line in &self.log_view_content.clone() {
|
if line.starts_with(" ") && !line.starts_with(" ") && !line.starts_with("\t") {
|
||||||
if line.starts_with(" ") && !line.starts_with("\t") {
|
// This is a project header - next entry will be first entry of this project
|
||||||
if !current_project.is_empty() && current_project != _selected_project {
|
expecting_first_entry = true;
|
||||||
last_different_project_entry = previous_project_first_entry;
|
} else if self.is_entry_line(line) {
|
||||||
|
if expecting_first_entry {
|
||||||
|
// This is the first entry of a project
|
||||||
|
projects.push(entry_count);
|
||||||
|
expecting_first_entry = false;
|
||||||
|
}
|
||||||
|
entry_count += 1;
|
||||||
}
|
}
|
||||||
current_project = line.clone();
|
|
||||||
previous_project_first_entry = Some(frame_count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.is_entry_line(line) {
|
// Find which project contains our current selection and jump to previous
|
||||||
if frame_count == self.log_view_selected {
|
for i in 0..projects.len() {
|
||||||
_selected_project = current_project.clone();
|
let project_start = projects[i];
|
||||||
// Jump to the last different project we saw
|
let project_end = if i + 1 < projects.len() {
|
||||||
if let Some(entry) = last_different_project_entry {
|
projects[i + 1]
|
||||||
self.log_view_selected = entry;
|
} else {
|
||||||
|
entry_count
|
||||||
|
};
|
||||||
|
|
||||||
|
if project_start <= self.log_view_selected && self.log_view_selected < project_end {
|
||||||
|
// Found current project, jump to previous if it exists
|
||||||
|
if i > 0 {
|
||||||
|
self.log_view_selected = projects[i - 1];
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
frame_count += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn jump_to_next_day(&mut self) {
|
fn update_log_view_scroll(&mut self) {
|
||||||
// Find the current day, then jump to first entry of next day
|
// Calculate which content line the selected entry is on
|
||||||
let mut current_date = String::new();
|
let mut content_line: usize = 0;
|
||||||
let mut selected_date = String::new();
|
|
||||||
let mut frame_count = 0;
|
let mut frame_count = 0;
|
||||||
let mut found_current = false;
|
for line in &self.log_view_content {
|
||||||
|
|
||||||
// Find which day we're currently in
|
|
||||||
for line in &self.log_view_content.clone() {
|
|
||||||
if !line.starts_with('\t') && !line.is_empty() && !line.starts_with(" ") {
|
|
||||||
current_date = line.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.is_entry_line(line) {
|
if self.is_entry_line(line) {
|
||||||
if frame_count == self.log_view_selected {
|
if frame_count == self.log_view_selected {
|
||||||
selected_date = current_date.clone();
|
|
||||||
found_current = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
frame_count += 1;
|
frame_count += 1;
|
||||||
}
|
}
|
||||||
|
content_line += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !found_current {
|
// Center the selection in the viewport
|
||||||
return;
|
// Assume a reasonable viewport height for centering calculation
|
||||||
|
let viewport_center_offset: usize = 10; // Lines from top to center selection
|
||||||
|
self.log_view_scroll = content_line.saturating_sub(viewport_center_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now find the next day and jump to its first entry
|
fn jump_to_next_day(&mut self) {
|
||||||
current_date = String::new();
|
// Find all day headers and their first entry positions
|
||||||
let mut past_selected = false;
|
let mut days = Vec::new(); // (first_entry_index)
|
||||||
frame_count = 0;
|
let mut entry_count = 0;
|
||||||
|
let mut current_day_seen = false;
|
||||||
|
|
||||||
for line in &self.log_view_content.clone() {
|
for line in &self.log_view_content {
|
||||||
if !line.starts_with('\t') && !line.is_empty() && !line.starts_with(" ") {
|
if !line.starts_with('\t') && !line.is_empty() && !line.starts_with(" ") {
|
||||||
if past_selected && line != &selected_date {
|
// This is a day header - mark that we'll record the next entry
|
||||||
// This is the next day, continue to find its first entry
|
current_day_seen = true;
|
||||||
current_date = line.clone();
|
} else if self.is_entry_line(line) && current_day_seen {
|
||||||
} else if line == &selected_date {
|
// This is the first entry of a day
|
||||||
past_selected = true;
|
days.push(entry_count);
|
||||||
}
|
current_day_seen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.is_entry_line(line) {
|
if self.is_entry_line(line) {
|
||||||
if past_selected && !current_date.is_empty() && current_date != selected_date {
|
entry_count += 1;
|
||||||
// First entry of next day
|
|
||||||
self.log_view_selected = frame_count;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
frame_count += 1;
|
}
|
||||||
|
|
||||||
|
// Find which day contains our current selection and jump to next
|
||||||
|
for i in 0..days.len() {
|
||||||
|
let day_start = days[i];
|
||||||
|
let day_end = if i + 1 < days.len() {
|
||||||
|
days[i + 1]
|
||||||
|
} else {
|
||||||
|
entry_count
|
||||||
|
};
|
||||||
|
|
||||||
|
if day_start <= self.log_view_selected && self.log_view_selected < day_end {
|
||||||
|
// Found current day, jump to next if it exists
|
||||||
|
if i + 1 < days.len() {
|
||||||
|
self.log_view_selected = days[i + 1];
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn jump_to_previous_day(&mut self) {
|
fn jump_to_previous_day(&mut self) {
|
||||||
// Find the previous day and jump to its first entry
|
// Find all day headers and their first entry positions
|
||||||
let mut current_date = String::new();
|
let mut days = Vec::new(); // (first_entry_index)
|
||||||
let mut _selected_date = String::new();
|
let mut entry_count = 0;
|
||||||
let mut frame_count = 0;
|
let mut current_day_seen = false;
|
||||||
let mut last_different_day_entry = None;
|
|
||||||
let mut previous_day_first_entry = None;
|
|
||||||
|
|
||||||
// Find which day we're currently in
|
for line in &self.log_view_content {
|
||||||
for line in &self.log_view_content.clone() {
|
|
||||||
if !line.starts_with('\t') && !line.is_empty() && !line.starts_with(" ") {
|
if !line.starts_with('\t') && !line.is_empty() && !line.starts_with(" ") {
|
||||||
if !current_date.is_empty() && current_date != _selected_date {
|
// This is a day header - mark that we'll record the next entry
|
||||||
last_different_day_entry = previous_day_first_entry;
|
current_day_seen = true;
|
||||||
}
|
} else if self.is_entry_line(line) && current_day_seen {
|
||||||
current_date = line.clone();
|
// This is the first entry of a day
|
||||||
previous_day_first_entry = Some(frame_count);
|
days.push(entry_count);
|
||||||
|
current_day_seen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.is_entry_line(line) {
|
if self.is_entry_line(line) {
|
||||||
if frame_count == self.log_view_selected {
|
entry_count += 1;
|
||||||
_selected_date = current_date.clone();
|
}
|
||||||
// Jump to the last different day we saw
|
}
|
||||||
if let Some(entry) = last_different_day_entry {
|
|
||||||
self.log_view_selected = entry;
|
// Find which day contains our current selection and jump to previous
|
||||||
|
for i in 0..days.len() {
|
||||||
|
let day_start = days[i];
|
||||||
|
let day_end = if i + 1 < days.len() {
|
||||||
|
days[i + 1]
|
||||||
|
} else {
|
||||||
|
entry_count
|
||||||
|
};
|
||||||
|
|
||||||
|
if day_start <= self.log_view_selected && self.log_view_selected < day_end {
|
||||||
|
// Found current day, jump to previous if it exists
|
||||||
|
if i > 0 {
|
||||||
|
self.log_view_selected = days[i - 1];
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
frame_count += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1564,17 +1655,29 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_log_content(&mut self) -> anyhow::Result<()> {
|
fn load_log_content(&mut self) -> anyhow::Result<()> {
|
||||||
let flag = match self.log_view_period {
|
let mut command = Command::new("watson");
|
||||||
LogViewPeriod::Day => "--day",
|
command.arg("log").arg("--json");
|
||||||
LogViewPeriod::Week => "--week",
|
|
||||||
LogViewPeriod::Month => "--month",
|
// Handle different period options
|
||||||
|
match self.log_view_period {
|
||||||
|
LogViewPeriod::Day => {
|
||||||
|
command.arg("--day");
|
||||||
|
},
|
||||||
|
LogViewPeriod::Week => {
|
||||||
|
command.arg("--week");
|
||||||
|
},
|
||||||
|
LogViewPeriod::Month => {
|
||||||
|
// Use --from with date 31 days ago for month view
|
||||||
|
let thirty_one_days_ago = chrono::Local::now()
|
||||||
|
.checked_sub_signed(chrono::Duration::days(31))
|
||||||
|
.expect("Failed to calculate date from 31 days ago");
|
||||||
|
|
||||||
|
command.arg("--from");
|
||||||
|
command.arg(thirty_one_days_ago.format("%Y-%m-%d").to_string());
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let output = Command::new("watson")
|
let output = command.output()?;
|
||||||
.arg("log")
|
|
||||||
.arg(flag)
|
|
||||||
.arg("--json")
|
|
||||||
.output()?;
|
|
||||||
|
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
let json_str = String::from_utf8_lossy(&output.stdout);
|
let json_str = String::from_utf8_lossy(&output.stdout);
|
||||||
|
|
|
||||||
|
|
@ -679,7 +679,7 @@ fn render_log_view(frame: &mut Frame, app: &App) {
|
||||||
let period_str = match app.log_view_period {
|
let period_str = match app.log_view_period {
|
||||||
LogViewPeriod::Day => "Day",
|
LogViewPeriod::Day => "Day",
|
||||||
LogViewPeriod::Week => "Week",
|
LogViewPeriod::Week => "Week",
|
||||||
LogViewPeriod::Month => "Month",
|
LogViewPeriod::Month => "31 Days",
|
||||||
};
|
};
|
||||||
|
|
||||||
let grouping_str = match app.log_view_grouping {
|
let grouping_str = match app.log_view_grouping {
|
||||||
|
|
@ -901,9 +901,11 @@ fn render_log_view(frame: &mut Frame, app: &App) {
|
||||||
.collect()
|
.collect()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Use the scroll position calculated by the app
|
||||||
let paragraph = Paragraph::new(text_lines)
|
let paragraph = Paragraph::new(text_lines)
|
||||||
.block(block)
|
.block(block)
|
||||||
.wrap(ratatui::widgets::Wrap { trim: false });
|
.wrap(ratatui::widgets::Wrap { trim: false })
|
||||||
|
.scroll((app.log_view_scroll as u16, 0));
|
||||||
|
|
||||||
frame.render_widget(paragraph, chunks[0]);
|
frame.render_widget(paragraph, chunks[0]);
|
||||||
|
|
||||||
|
|
@ -928,7 +930,7 @@ fn render_log_view_help(frame: &mut Frame, app: &App) {
|
||||||
"Time Periods:",
|
"Time Periods:",
|
||||||
"- d: Switch to Day view (current day)",
|
"- d: Switch to Day view (current day)",
|
||||||
"- w: Switch to Week view (current week)",
|
"- w: Switch to Week view (current week)",
|
||||||
"- m: Switch to Month view (current month)",
|
"- m: Switch to Month view (last 31 days)",
|
||||||
"",
|
"",
|
||||||
"Grouping:",
|
"Grouping:",
|
||||||
"- g: Toggle between grouping by Date or by Project",
|
"- g: Toggle between grouping by Date or by Project",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue