Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpasmantier committed Oct 3, 2024
1 parent a00015b commit 546ac39
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 56 deletions.
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
- [x] environment variables
- [ ] aliases
- [ ] shell history
- [ ] grep (maybe also inside pdfs and other files (see rga))
- [x] text
- [ ] text in documents (pdfs, archives, ...) (rga, adapters)
- [x] fd
- [ ] recent directories
- [ ] git
Expand Down
2 changes: 1 addition & 1 deletion src/components/finders/grep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl Finder for GrepFinder {
snapshot.get_matched_item(index).and_then(|item| {
let display_path = item.data.path.to_string_lossy().to_string();
Some(Entry {
name: display_path.clone() + &item.data.line_number.to_string(),
name: display_path.clone() + ":" + &item.data.line_number.to_string(),
display_name: Some(display_path),
preview: None,
name_match_ranges: None,
Expand Down
44 changes: 23 additions & 21 deletions src/components/television.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ impl Component for Television {

fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
let (results_area, input_area, preview_title_area, preview_area) = self.create_layout(area);

self.results_area_height = results_area.height as u32;
self.preview_pane_height = preview_area.height;

Expand Down Expand Up @@ -546,6 +547,7 @@ impl Television {

fn create_layout(&self, area: Rect) -> (Rect, Rect, Rect, Rect) {
let main_block = centered_rect(UI_WIDTH_PERCENT, UI_HEIGHT_PERCENT, area);

// split the main block into two vertical chunks
let chunks = Layout::default()
.direction(Direction::Horizontal)
Expand Down Expand Up @@ -683,29 +685,26 @@ impl Television {
let mut lines = Vec::new();
for (i, line) in content.iter().enumerate() {
lines.push(Line::from(vec![
build_line_number_span(i + 1)
.style(Style::default().fg(DEFAULT_PREVIEW_GUTTER_FG)),
build_line_number_span(i + 1).style(Style::default().fg(
if matches!(preview.target_line, Some(l) if l == i as u16 + 1) {
DEFAULT_PREVIEW_GUTTER_SELECTED_FG
} else {
DEFAULT_PREVIEW_GUTTER_FG
},
)),
Span::styled(" │ ", Style::default().fg(DEFAULT_PREVIEW_GUTTER_FG).dim()),
Span::styled(
line.to_string(),
Style::default().fg(DEFAULT_RESULT_PREVIEW_FG),
Style::default().fg(DEFAULT_RESULT_PREVIEW_FG).bg(
if matches!(preview.target_line, Some(l) if l == i as u16 + 1) {
DEFAULT_SELECTED_PREVIEW_BG
} else {
Color::Reset
},
),
),
]));
}
if let Some(target_line) = preview.target_line {
let target_line = target_line as usize;
if target_line < lines.len() {
lines[target_line] = Line::from(vec![
build_line_number_span(target_line + 1)
.style(Style::default().fg(DEFAULT_PREVIEW_GUTTER_SELECTED_FG)),
Span::styled(" │ ", Style::default().fg(DEFAULT_PREVIEW_GUTTER_FG)),
Span::styled(
content[target_line].to_string(),
Style::default().bg(DEFAULT_SELECTED_PREVIEW_BG),
),
]);
}
}
let text = Text::from(lines);
Paragraph::new(text)
.block(preview_block)
Expand All @@ -725,10 +724,13 @@ impl Television {
.wrap(Wrap { trim: true })
}
PreviewContent::HighlightedText(highlighted_lines) => {
compute_paragraph_from_highlighted_lines(highlighted_lines, None)
.block(preview_block)
.alignment(Alignment::Left)
.scroll((self.preview_scroll.unwrap_or(0), 0))
compute_paragraph_from_highlighted_lines(
highlighted_lines,
preview.target_line.map(|l| l as usize),
)
.block(preview_block)
.alignment(Alignment::Left)
.scroll((self.preview_scroll.unwrap_or(0), 0))
}
// meta
PreviewContent::Loading => self
Expand Down
2 changes: 2 additions & 0 deletions src/components/utils/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub fn walk_builder(path: &Path, n_threads: usize) -> WalkBuilder {
types_builder.add_defaults();
builder.types(types_builder.build().unwrap());

builder.hidden(false);

builder.threads(n_threads);
builder
}
Expand Down
33 changes: 0 additions & 33 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
///
/// ________ ______ _____ _____
/// ___ __/_______ /_______ ____(_)_________(_)____________
/// __ / _ _ \_ /_ _ \_ | / /_ /__ ___/_ /_ __ \_ __ \
/// _ / / __/ / / __/_ |/ /_ / _(__ )_ / / /_/ / / / /
/// /_/ \___//_/ \___/_____/ /_/ /____/ /_/ \____//_/ /_/
///
///
/// __ __
/// __ __ (_) (_)
/// / /____ / /__ _ __ _ ____ _ ___ ____
/// / __/ _ \/ / _ \ | / / / ___/ / __ \/ __ \
/// / /_/ __/ / __/ |/ / (__ ) / /_/ / / / /
/// \__/\___/_/\___/|___/_/____/_/\____/_/ /_/
///
///
/// __ __ _ _
/// / /____ / /__ _ __(_)__ (_)__ ___
/// / __/ -_) / -_) |/ / (_-</ / _ \/ _ \
/// \__/\__/_/\__/|___/_/___/_/\___/_//_/
///
/// 888 888 d8b d8b
/// 888 888 Y8P Y8P
/// 888 888
/// 888888 .d88b. 888 .d88b. 888 888 888 .d8888b 888 .d88b. 88888b.
/// 888 d8P Y8b 888 d8P Y8b 888 888 888 88K 888 d88""88b 888 "88b
/// 888 88888888 888 88888888 Y88 88P 888 "Y8888b. 888 888 888 888 888
/// Y88b. Y8b. 888 Y8b. Y8bd8P 888 X88 888 Y88..88P 888 888
/// "Y888 "Y8888 888 "Y8888 Y88P 888 88888P' 888 "Y88P" 888 888
///
use clap::Parser;
use cli::Cli;
use color_eyre::Result;
Expand Down

0 comments on commit 546ac39

Please sign in to comment.