Skip to content

Commit acf709e

Browse files
unhappychoiceclaude
andcommitted
feat: improve file path display and add repository context to challenges
- Add relative path display in Challenge::get_display_title() - Add Challenge::get_display_title_with_repo() for repository-aware display - Update GameDisplayRatatui to show repository info with challenges - Convert absolute paths to parent_dir/filename format for better readability 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 307ad02 commit acf709e

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

src/game/challenge.rs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::stage_builder::DifficultyLevel;
2+
use crate::extractor::GitRepositoryInfo;
23

34
#[derive(Debug, Clone)]
45
pub struct Challenge {
@@ -55,13 +56,62 @@ impl Challenge {
5556

5657
pub fn get_display_title(&self) -> String {
5758
if let Some(ref path) = self.source_file_path {
59+
// Convert absolute path to relative path for cleaner display
60+
let relative_path = self.get_relative_path(path);
5861
if let (Some(start), Some(end)) = (self.start_line, self.end_line) {
59-
format!("{}:{}-{}", path, start, end)
62+
format!("{}:{}-{}", relative_path, start, end)
6063
} else {
61-
path.clone()
64+
relative_path
6265
}
6366
} else {
6467
format!("Challenge {}", self.id)
6568
}
6669
}
70+
71+
pub fn get_display_title_with_repo(&self, repo_info: &Option<GitRepositoryInfo>) -> String {
72+
if let Some(ref path) = self.source_file_path {
73+
let relative_path = self.get_relative_path(path);
74+
let file_info = if let (Some(start), Some(end)) = (self.start_line, self.end_line) {
75+
format!("{}:{}-{}", relative_path, start, end)
76+
} else {
77+
relative_path
78+
};
79+
80+
if let Some(repo) = repo_info {
81+
format!(
82+
"[{}/{}] {}",
83+
repo.user_name, repo.repository_name, file_info
84+
)
85+
} else {
86+
file_info
87+
}
88+
} else {
89+
format!("Challenge {}", self.id)
90+
}
91+
}
92+
93+
fn get_relative_path(&self, path: &str) -> String {
94+
use std::path::Path;
95+
96+
// Try to extract just the filename if it's a full path
97+
if let Some(file_name) = Path::new(path).file_name() {
98+
if let Some(parent) = Path::new(path).parent() {
99+
if let Some(parent_name) = parent.file_name() {
100+
// Show parent_dir/filename for better context
101+
format!(
102+
"{}/{}",
103+
parent_name.to_string_lossy(),
104+
file_name.to_string_lossy()
105+
)
106+
} else {
107+
file_name.to_string_lossy().to_string()
108+
}
109+
} else {
110+
file_name.to_string_lossy().to_string()
111+
}
112+
} else {
113+
// Fallback to original path if extraction fails
114+
path.to_string()
115+
}
116+
}
67117
}

src/game/display_ratatui.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::{challenge::Challenge, text_processor::TextProcessor};
2-
use crate::Result;
2+
use crate::{extractor::GitRepositoryInfo, Result};
33
use ratatui::{
44
backend::CrosstermBackend,
55
layout::{Constraint, Direction, Layout},
@@ -44,6 +44,7 @@ impl GameDisplayRatatui {
4444
skips_remaining: usize,
4545
dialog_shown: bool,
4646
scoring_engine: &crate::scoring::engine::ScoringEngine,
47+
repo_info: &Option<GitRepositoryInfo>,
4748
) -> Result<()> {
4849
// Update character cache if needed
4950
if self.chars.len() != challenge_text.chars().count() {
@@ -62,7 +63,11 @@ impl GameDisplayRatatui {
6263
Some(difficulty) => format!("{:?}", difficulty),
6364
None => "Unknown".to_string(),
6465
};
65-
format!("[{}] [{}]", challenge.get_display_title(), difficulty_text)
66+
format!(
67+
"[{}] [{}]",
68+
challenge.get_display_title_with_repo(repo_info),
69+
difficulty_text
70+
)
6671
} else {
6772
"[Challenge]".to_string()
6873
};

0 commit comments

Comments
 (0)