diff --git a/television/channels/channel.rs b/television/channels/channel.rs index 7d2b69e..b445c4a 100644 --- a/television/channels/channel.rs +++ b/television/channels/channel.rs @@ -256,20 +256,10 @@ impl Channel { let item = self.matcher.get_result(index); if let Some(item) = item { - let mut entry = Entry::new(item.inner.clone()) + let entry = Entry::new(item.inner.clone()) .with_display(item.matched_string) - .with_match_indices(&item.match_indices); - if let Some(p) = &self.prototype.preview { - // FIXME: this should be done by the previewer instead - if let Some(offset_expr) = &p.offset { - let offset_str = - offset_expr.format(&item.inner).unwrap_or_default(); - - entry = entry.with_line_number( - offset_str.parse::().unwrap_or(0), - ); - } - } + .with_match_indices(&item.match_indices) + .ansi(self.prototype.source.ansi); Some(entry) } else { None diff --git a/television/television.rs b/television/television.rs index 67f2c65..2c3a417 100644 --- a/television/television.rs +++ b/television/television.rs @@ -364,12 +364,45 @@ impl Television { } pub fn get_selected_entry(&mut self) -> Option { - if self.channel.result_count() == 0 { - return None; + match self.mode { + Mode::Channel => { + let entry = self + .results_picker + .selected() + .and_then(|idx| self.results_picker.entries.get(idx)) + .cloned()?; + Some(self.apply_preview_offset(entry)) + } + Mode::RemoteControl => { + if self + .remote_control + .as_ref() + .map_or(0, RemoteControl::result_count) + == 0 + { + return None; + } + let entry = self + .selected_index() + .map(|idx| self.channel.get_result(idx)) + .and_then(|entry| entry)?; + Some(self.apply_preview_offset(entry)) + } } - self.selected_index() - .map(|idx| self.channel.get_result(idx)) - .and_then(|entry| entry) + } + + /// Apply preview offset logic to an entry + fn apply_preview_offset(&self, mut entry: Entry) -> Entry { + if let Some(p) = &self.channel.prototype.preview { + if let Some(offset_expr) = &p.offset { + let offset_str = + offset_expr.format(&entry.raw).unwrap_or_default(); + entry = entry.with_line_number( + offset_str.parse::().unwrap_or(0), + ); + } + } + entry } pub fn get_selected_cable_entry(&mut self) -> Option {