-
Notifications
You must be signed in to change notification settings - Fork 35
Improve internals to allow having much smaller HTML generated #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GuillaumeGomez
wants to merge
7
commits into
rust-cli:main
Choose a base branch
from
GuillaumeGomez:improve-internals
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
429664a
Add new `use_html5` API in `Term`
GuillaumeGomez 348b6c6
Create new `SpanKind` type to be used in `write_bg_span` and `write_f…
GuillaumeGomez 797e225
Add new `write_classes` utility function
GuillaumeGomez 839ef19
Don't create a tag element if there is no style to apply
GuillaumeGomez 6ba4c30
Split rendering of `SpanKind::Tspan` and `SpanKind::Span`
GuillaumeGomez 87825e6
Remove `<span>` tag wrapping if it contains a link (`<a>`)
GuillaumeGomez d0462a3
Remove some unneeded extra backlines and indent
GuillaumeGomez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ pub struct Term { | |
| font_family: &'static str, | ||
| min_width_px: usize, | ||
| padding_px: usize, | ||
| use_html5: bool, | ||
| } | ||
|
|
||
| impl Term { | ||
|
|
@@ -54,6 +55,7 @@ impl Term { | |
| font_family: "SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace", | ||
| min_width_px: 720, | ||
| padding_px: 10, | ||
| use_html5: true, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -87,6 +89,12 @@ impl Term { | |
| self | ||
| } | ||
|
|
||
| /// Whether or not to generate HTML5 compatible tags. Enabled by default. | ||
| pub const fn use_html5(mut self, use_html5: bool) -> Self { | ||
| self.use_html5 = use_html5; | ||
| self | ||
| } | ||
|
|
||
| /// Render the SVG with the terminal defined | ||
| /// | ||
| /// **Note:** Lines are not wrapped. This is intentional as this attempts to convey the exact | ||
|
|
@@ -296,6 +304,7 @@ impl Term { | |
| fn render_content(&self, buffer: &mut String, styled_lines: Vec<Vec<adapter::Element>>) { | ||
| use std::fmt::Write as _; | ||
|
|
||
| let br = if self.use_html5 { "<br>" } else { "<br />" }; | ||
| writeln!(buffer, r#" <div class="container {FG}">"#).unwrap(); | ||
| for line in &styled_lines { | ||
| if line.iter().any(|e| e.style.get_bg_color().is_some()) { | ||
|
|
@@ -305,7 +314,7 @@ impl Term { | |
| } | ||
| write_bg_span(buffer, "span", &element.style, &element.text); | ||
| } | ||
| writeln!(buffer, r#"<br />"#).unwrap(); | ||
| buffer.write_str(br).unwrap(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please restore the use of |
||
| } | ||
|
|
||
| for element in line { | ||
|
|
@@ -314,7 +323,7 @@ impl Term { | |
| } | ||
| write_fg_span(buffer, "span", element, &element.text); | ||
| } | ||
| writeln!(buffer, r#"<br />"#).unwrap(); | ||
| buffer.write_str(br).unwrap(); | ||
| } | ||
| writeln!(buffer, r#" </div>"#).unwrap(); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.