added the fields for drawing the hyperlinks
This commit is contained in:
parent
5cd56584b4
commit
0584b2f5f0
2 changed files with 45 additions and 14 deletions
|
@ -387,7 +387,6 @@ impl TerminalBuilder {
|
||||||
foreground_process_info: None,
|
foreground_process_info: None,
|
||||||
breadcrumb_text: String::new(),
|
breadcrumb_text: String::new(),
|
||||||
scroll_px: 0.,
|
scroll_px: 0.,
|
||||||
last_hovered_hyperlink: None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(TerminalBuilder {
|
Ok(TerminalBuilder {
|
||||||
|
@ -474,6 +473,7 @@ pub struct TerminalContent {
|
||||||
cursor: RenderableCursor,
|
cursor: RenderableCursor,
|
||||||
cursor_char: char,
|
cursor_char: char,
|
||||||
size: TerminalSize,
|
size: TerminalSize,
|
||||||
|
last_hovered_hyperlink: Option<(String, RangeInclusive<Point>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for TerminalContent {
|
impl Default for TerminalContent {
|
||||||
|
@ -490,6 +490,7 @@ impl Default for TerminalContent {
|
||||||
},
|
},
|
||||||
cursor_char: Default::default(),
|
cursor_char: Default::default(),
|
||||||
size: Default::default(),
|
size: Default::default(),
|
||||||
|
last_hovered_hyperlink: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -502,7 +503,6 @@ pub struct Terminal {
|
||||||
pub matches: Vec<RangeInclusive<Point>>,
|
pub matches: Vec<RangeInclusive<Point>>,
|
||||||
last_content: TerminalContent,
|
last_content: TerminalContent,
|
||||||
last_synced: Instant,
|
last_synced: Instant,
|
||||||
last_hovered_hyperlink: Option<(String, RangeInclusive<Point>)>,
|
|
||||||
sync_task: Option<Task<()>>,
|
sync_task: Option<Task<()>>,
|
||||||
selection_head: Option<Point>,
|
selection_head: Option<Point>,
|
||||||
breadcrumb_text: String,
|
breadcrumb_text: String,
|
||||||
|
@ -653,7 +653,7 @@ impl Terminal {
|
||||||
}
|
}
|
||||||
InternalEvent::ScrollToPoint(point) => term.scroll_to_point(*point),
|
InternalEvent::ScrollToPoint(point) => term.scroll_to_point(*point),
|
||||||
InternalEvent::Hyperlink(position, open) => {
|
InternalEvent::Hyperlink(position, open) => {
|
||||||
self.last_hovered_hyperlink = None;
|
self.last_content.last_hovered_hyperlink = None;
|
||||||
|
|
||||||
let point = grid_point(
|
let point = grid_point(
|
||||||
*position,
|
*position,
|
||||||
|
@ -663,12 +663,11 @@ impl Terminal {
|
||||||
|
|
||||||
if let Some(url_match) = regex_match_at(term, point, &URL_REGEX) {
|
if let Some(url_match) = regex_match_at(term, point, &URL_REGEX) {
|
||||||
let url = term.bounds_to_string(*url_match.start(), *url_match.end());
|
let url = term.bounds_to_string(*url_match.start(), *url_match.end());
|
||||||
dbg!(&url, &url_match, open);
|
|
||||||
|
|
||||||
if *open {
|
if *open {
|
||||||
open_uri(&url).log_err();
|
open_uri(&url).log_err();
|
||||||
} else {
|
} else {
|
||||||
self.last_hovered_hyperlink = Some((url, url_match));
|
self.last_content.last_hovered_hyperlink = Some((url, url_match));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -779,11 +778,11 @@ impl Terminal {
|
||||||
self.process_terminal_event(&e, &mut terminal, cx)
|
self.process_terminal_event(&e, &mut terminal, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.last_content = Self::make_content(&terminal, self.last_content.size);
|
self.last_content = Self::make_content(&terminal, &self.last_content);
|
||||||
self.last_synced = Instant::now();
|
self.last_synced = Instant::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_content(term: &Term<ZedListener>, last_size: TerminalSize) -> TerminalContent {
|
fn make_content(term: &Term<ZedListener>, last_content: &TerminalContent) -> TerminalContent {
|
||||||
let content = term.renderable_content();
|
let content = term.renderable_content();
|
||||||
TerminalContent {
|
TerminalContent {
|
||||||
cells: content
|
cells: content
|
||||||
|
@ -806,7 +805,8 @@ impl Terminal {
|
||||||
selection: content.selection,
|
selection: content.selection,
|
||||||
cursor: content.cursor,
|
cursor: content.cursor,
|
||||||
cursor_char: term.grid()[content.cursor.point].c,
|
cursor_char: term.grid()[content.cursor.point].c,
|
||||||
size: last_size,
|
size: last_content.size,
|
||||||
|
last_hovered_hyperlink: last_content.last_hovered_hyperlink.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -844,7 +844,7 @@ impl Terminal {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mouse_move(&mut self, e: &MouseMovedEvent, origin: Vector2F) {
|
pub fn mouse_move(&mut self, e: &MouseMovedEvent, origin: Vector2F) {
|
||||||
self.last_hovered_hyperlink = None;
|
self.last_content.last_hovered_hyperlink = None;
|
||||||
let position = e.position.sub(origin);
|
let position = e.position.sub(origin);
|
||||||
if self.mouse_mode(e.shift) {
|
if self.mouse_mode(e.shift) {
|
||||||
let point = grid_point(
|
let point = grid_point(
|
||||||
|
@ -882,7 +882,7 @@ impl Terminal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.last_hovered_hyperlink = link.map(|link| {
|
self.last_content.last_hovered_hyperlink = link.map(|link| {
|
||||||
(
|
(
|
||||||
link.uri().to_owned(),
|
link.uri().to_owned(),
|
||||||
self.last_content.cells[min_index].point
|
self.last_content.cells[min_index].point
|
||||||
|
|
|
@ -237,7 +237,7 @@ impl TerminalElement {
|
||||||
//Layout current cell text
|
//Layout current cell text
|
||||||
{
|
{
|
||||||
let cell_text = &cell.c.to_string();
|
let cell_text = &cell.c.to_string();
|
||||||
if cell_text != " " {
|
if !is_blank(&cell) {
|
||||||
let cell_style = TerminalElement::cell_style(
|
let cell_style = TerminalElement::cell_style(
|
||||||
&cell,
|
&cell,
|
||||||
fg,
|
fg,
|
||||||
|
@ -257,8 +257,8 @@ impl TerminalElement {
|
||||||
Point::new(line_index as i32, cell.point.column.0 as i32),
|
Point::new(line_index as i32, cell.point.column.0 as i32),
|
||||||
layout_cell,
|
layout_cell,
|
||||||
))
|
))
|
||||||
}
|
};
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cur_rect.is_some() {
|
if cur_rect.is_some() {
|
||||||
|
@ -308,7 +308,7 @@ impl TerminalElement {
|
||||||
let flags = indexed.cell.flags;
|
let flags = indexed.cell.flags;
|
||||||
let fg = convert_color(&fg, &style.colors, modal);
|
let fg = convert_color(&fg, &style.colors, modal);
|
||||||
|
|
||||||
let underline = flags
|
let mut underline = flags
|
||||||
.intersects(Flags::ALL_UNDERLINES)
|
.intersects(Flags::ALL_UNDERLINES)
|
||||||
.then(|| Underline {
|
.then(|| Underline {
|
||||||
color: Some(fg),
|
color: Some(fg),
|
||||||
|
@ -317,6 +317,13 @@ impl TerminalElement {
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
if indexed.cell.hyperlink().is_some() {
|
||||||
|
underline.squiggly = true;
|
||||||
|
if underline.thickness == OrderedFloat(0.) {
|
||||||
|
underline.thickness = OrderedFloat(1.);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut properties = Properties::new();
|
let mut properties = Properties::new();
|
||||||
if indexed
|
if indexed
|
||||||
.flags
|
.flags
|
||||||
|
@ -569,6 +576,7 @@ impl Element for TerminalElement {
|
||||||
cursor_char,
|
cursor_char,
|
||||||
selection,
|
selection,
|
||||||
cursor,
|
cursor,
|
||||||
|
last_hovered_hyperlink,
|
||||||
..
|
..
|
||||||
} = &terminal_handle.read(cx).last_content;
|
} = &terminal_handle.read(cx).last_content;
|
||||||
|
|
||||||
|
@ -824,6 +832,29 @@ impl Element for TerminalElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_blank(cell: &IndexedCell) -> bool {
|
||||||
|
if cell.c != ' ' {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if cell.bg != AnsiColor::Named(NamedColor::Background) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if cell.hyperlink().is_some() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if cell
|
||||||
|
.flags
|
||||||
|
.intersects(Flags::ALL_UNDERLINES | Flags::INVERSE | Flags::STRIKEOUT)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
fn to_highlighted_range_lines(
|
fn to_highlighted_range_lines(
|
||||||
range: &RangeInclusive<Point>,
|
range: &RangeInclusive<Point>,
|
||||||
layout: &LayoutState,
|
layout: &LayoutState,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue