mirror of
https://github.com/tealdeer-rs/tealdeer.git
synced 2026-08-23 16:44:18 +02:00
parent
b19517097a
commit
b8f7c0cc2d
10 changed files with 171 additions and 37 deletions
|
|
@ -37,3 +37,35 @@ show_title = true
|
|||
|
||||
When enabled, the command name will be displayed at the top of the output,
|
||||
styled with the `command_name` style configuration.
|
||||
|
||||
## `indent`
|
||||
|
||||
Controls the indentation of the output via two sub-keys.
|
||||
|
||||
### `indent.base`
|
||||
|
||||
Specifies the number of spaces used to indent descriptions, example text, and titles (default `2`).
|
||||
|
||||
```toml
|
||||
[display.indent]
|
||||
base = 2
|
||||
```
|
||||
|
||||
### `indent.command`
|
||||
|
||||
Specifies the number of spaces used to indent example code lines (default `6`).
|
||||
|
||||
```toml
|
||||
[display.indent]
|
||||
command = 6
|
||||
```
|
||||
|
||||
You can also configure both subkeys in a single line like this:
|
||||
|
||||
```toml
|
||||
[display]
|
||||
indent = {
|
||||
base = 2,
|
||||
command = 6,
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -43,6 +43,14 @@ fn default_underline() -> bool {
|
|||
false
|
||||
}
|
||||
|
||||
const fn default_base_indent() -> usize {
|
||||
2
|
||||
}
|
||||
|
||||
const fn default_command_indent() -> usize {
|
||||
6
|
||||
}
|
||||
|
||||
fn default_bold() -> bool {
|
||||
false
|
||||
}
|
||||
|
|
@ -171,6 +179,25 @@ struct RawDisplayConfig {
|
|||
pub use_pager: bool,
|
||||
#[serde(default)]
|
||||
pub show_title: bool,
|
||||
#[serde(default)]
|
||||
pub indent: RawIndent,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
struct RawIndent {
|
||||
#[serde(default = "default_base_indent")]
|
||||
base: usize,
|
||||
#[serde(default = "default_command_indent")]
|
||||
command: usize,
|
||||
}
|
||||
|
||||
impl Default for RawIndent {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
base: 2,
|
||||
command: 6,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&RawDisplayConfig> for DisplayConfig {
|
||||
|
|
@ -179,6 +206,10 @@ impl From<&RawDisplayConfig> for DisplayConfig {
|
|||
compact: raw_display_config.compact,
|
||||
use_pager: raw_display_config.use_pager,
|
||||
show_title: raw_display_config.show_title,
|
||||
indent: Indent {
|
||||
base: raw_display_config.indent.base,
|
||||
command: raw_display_config.indent.command,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -331,6 +362,13 @@ pub struct DisplayConfig {
|
|||
pub compact: bool,
|
||||
pub use_pager: bool,
|
||||
pub show_title: bool,
|
||||
pub indent: Indent,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Indent {
|
||||
pub base: usize,
|
||||
pub command: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use log::debug;
|
||||
|
||||
use crate::{extensions::FindFrom, types::LineType};
|
||||
use crate::{config::Indent, extensions::FindFrom, types::LineType};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq)]
|
||||
/// Represents a snippet from a page of a specific highlighting class.
|
||||
|
|
@ -68,11 +68,14 @@ pub fn highlight_lines<L, F, E>(
|
|||
process_snippet: &mut F,
|
||||
keep_empty_lines: bool,
|
||||
show_title: bool,
|
||||
indent: Indent,
|
||||
) -> Result<(), E>
|
||||
where
|
||||
L: Iterator<Item = LineType>,
|
||||
F: for<'snip> FnMut(PageSnippet<&'snip str>) -> Result<(), E>,
|
||||
{
|
||||
let base_indent = " ".repeat(indent.base);
|
||||
let command_indent = " ".repeat(indent.command);
|
||||
let mut command = String::new();
|
||||
for line in lines {
|
||||
match line {
|
||||
|
|
@ -84,7 +87,9 @@ where
|
|||
LineType::Title(title) => {
|
||||
if show_title {
|
||||
process_snippet(PageSnippet::Linebreak)?;
|
||||
process_snippet(PageSnippet::Title(&base_indent))?;
|
||||
process_snippet(PageSnippet::Title(&title))?;
|
||||
process_snippet(PageSnippet::Linebreak)?;
|
||||
} else {
|
||||
debug!("Ignoring title");
|
||||
}
|
||||
|
|
@ -93,10 +98,18 @@ where
|
|||
command = title;
|
||||
debug!("Detected command name: {}", &command);
|
||||
}
|
||||
LineType::Description(text) => process_snippet(PageSnippet::Description(&text))?,
|
||||
LineType::ExampleText(text) => process_snippet(PageSnippet::Text(&text))?,
|
||||
LineType::Description(text) => {
|
||||
process_snippet(PageSnippet::Description(&base_indent))?;
|
||||
process_snippet(PageSnippet::Description(&text))?;
|
||||
process_snippet(PageSnippet::Linebreak)?;
|
||||
}
|
||||
LineType::ExampleText(text) => {
|
||||
process_snippet(PageSnippet::Text(&base_indent))?;
|
||||
process_snippet(PageSnippet::Text(&text))?;
|
||||
process_snippet(PageSnippet::Linebreak)?;
|
||||
}
|
||||
LineType::ExampleCode(text) => {
|
||||
process_snippet(PageSnippet::NormalCode(" "))?;
|
||||
process_snippet(PageSnippet::NormalCode(&command_indent))?;
|
||||
highlight_code(&command, &text, process_snippet)?;
|
||||
process_snippet(PageSnippet::Linebreak)?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ pub fn print_page(
|
|||
&mut process_snippet,
|
||||
!config.display.compact,
|
||||
config.display.show_title,
|
||||
config.display.indent,
|
||||
)
|
||||
.context("Could not write to stdout")?;
|
||||
}
|
||||
|
|
@ -89,9 +90,9 @@ fn print_snippet(
|
|||
CommandName(s) => write!(writer, "{}", s.paint(style.command_name)),
|
||||
Variable(s) => write!(writer, "{}", s.paint(style.example_variable)),
|
||||
NormalCode(s) => write!(writer, "{}", s.paint(style.example_code)),
|
||||
Description(s) => writeln!(writer, " {}", s.paint(style.description)),
|
||||
Text(s) => writeln!(writer, " {}", s.paint(style.example_text)),
|
||||
Title(s) => writeln!(writer, " {}", s.paint(style.command_name)),
|
||||
Description(s) => write!(writer, "{}", s.paint(style.description)),
|
||||
Text(s) => write!(writer, "{}", s.paint(style.example_text)),
|
||||
Title(s) => write!(writer, "{}", s.paint(style.command_name)),
|
||||
Linebreak => writeln!(writer),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
18
tests/lib.rs
18
tests/lib.rs
|
|
@ -821,6 +821,24 @@ fn test_rendering_color_never() {
|
|||
);
|
||||
}
|
||||
|
||||
/// An end-to-end integration test for the indent config option
|
||||
#[test]
|
||||
fn test_rendering_with_indentation() {
|
||||
let testenv = TestEnv::new().install_default_cache();
|
||||
let expected_custom_indentation = include_str!("rendered/inkscape-compact-no-color.expected");
|
||||
|
||||
// Configure to set base and command indents
|
||||
testenv.append_to_config("display.indent.base = 3\n");
|
||||
testenv.append_to_config("display.indent.command = 1\n");
|
||||
|
||||
testenv
|
||||
.command()
|
||||
.args(["--color", "never", "inkscape-v2"])
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(diff(expected_custom_indentation));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rendering_i18n() {
|
||||
_test_correct_rendering(
|
||||
|
|
|
|||
|
|
@ -3,35 +3,35 @@
|
|||
Ubuntuのバージョンが16.04か、それ以降で対話モードを使う場合`apt-get`の代わりとして使用します。
|
||||
詳しくはこちら: <https://manned.org/apt.8>
|
||||
|
||||
[32m利用可能なパーケージとバージョンのリストの更新(他の`apt`コマンドの前での実行を推奨):[0m
|
||||
[32m [0m[32m利用可能なパーケージとバージョンのリストの更新(他の`apt`コマンドの前での実行を推奨):[0m
|
||||
|
||||
[36m [0m[36msudo [0m[36mapt[0m[36m update[0m
|
||||
|
||||
[32m指定されたパッケージの検索:[0m
|
||||
[32m [0m[32m指定されたパッケージの検索:[0m
|
||||
|
||||
[36m [0m[36mapt[0m[36m search [0m[4;36mパッケージ[0m
|
||||
|
||||
[32mパッケージの情報を出力:[0m
|
||||
[32m [0m[32mパッケージの情報を出力:[0m
|
||||
|
||||
[36m [0m[36mapt[0m[36m show [0m[4;36mパッケージ[0m
|
||||
|
||||
[32mパッケージのインストール、または利用可能な最新バージョンに更新:[0m
|
||||
[32m [0m[32mパッケージのインストール、または利用可能な最新バージョンに更新:[0m
|
||||
|
||||
[36m [0m[36msudo [0m[36mapt[0m[36m install [0m[4;36mパッケージ[0m
|
||||
|
||||
[32mパッケージの削除(`sudo apt remove --purge`の場合設定ファイルも削除):[0m
|
||||
[32m [0m[32mパッケージの削除(`sudo apt remove --purge`の場合設定ファイルも削除):[0m
|
||||
|
||||
[36m [0m[36msudo [0m[36mapt[0m[36m remove [0m[4;36mパッケージ[0m
|
||||
|
||||
[32mインストールされている全てのパッケージを最新のバージョンにアップグレード:[0m
|
||||
[32m [0m[32mインストールされている全てのパッケージを最新のバージョンにアップグレード:[0m
|
||||
|
||||
[36m [0m[36msudo [0m[36mapt[0m[36m upgrade[0m
|
||||
|
||||
[32mインストールできるすべてのパッケージを表示:[0m
|
||||
[32m [0m[32mインストールできるすべてのパッケージを表示:[0m
|
||||
|
||||
[36m [0m[36mapt[0m[36m list[0m
|
||||
|
||||
[32mインストールされた全てのパッケージを表示(依存関係も表示):[0m
|
||||
[32m [0m[32mインストールされた全てのパッケージを表示(依存関係も表示):[0m
|
||||
|
||||
[36m [0m[36mapt[0m[36m list --installed[0m
|
||||
|
||||
|
|
|
|||
32
tests/rendered/inkscape-compact-no-color.expected
Normal file
32
tests/rendered/inkscape-compact-no-color.expected
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
An SVG (Scalable Vector Graphics) editing program.
|
||||
Use -z to not open the GUI and only process files in the console.
|
||||
|
||||
Open an SVG file in the Inkscape GUI:
|
||||
|
||||
inkscape filename.svg
|
||||
|
||||
Export an SVG file into a bitmap with the default format (PNG) and the default resolution (90 DPI):
|
||||
|
||||
inkscape filename.svg -e filename.png
|
||||
|
||||
Export an SVG file into a bitmap of 600x400 pixels (aspect ratio distortion may occur):
|
||||
|
||||
inkscape filename.svg -e filename.png -w 600 -h 400
|
||||
|
||||
Export a single object, given its ID, into a bitmap:
|
||||
|
||||
inkscape filename.svg -i id -e object.png
|
||||
|
||||
Export an SVG document to PDF, converting all texts to paths:
|
||||
|
||||
inkscape filename.svg | inkscape | inkscape --export-pdf=inkscape.pdf | inkscape | inkscape --export-text-to-path
|
||||
|
||||
Duplicate the object with id="path123", rotate the duplicate 90 degrees, save the file, and quit Inkscape:
|
||||
|
||||
inkscape filename.svg --select=path123 --verb=EditDuplicate --verb=ObjectRotate90 --verb=FileSave --verb=FileQuit
|
||||
|
||||
Some invalid command just to test the correct highlighting of the command name:
|
||||
|
||||
inkscape --use-inkscape=v3.0 file
|
||||
|
||||
|
|
@ -2,31 +2,31 @@
|
|||
An SVG (Scalable Vector Graphics) editing program.
|
||||
Use -z to not open the GUI and only process files in the console.
|
||||
|
||||
[32mOpen an SVG file in the Inkscape GUI:[0m
|
||||
[32m [0m[32mOpen an SVG file in the Inkscape GUI:[0m
|
||||
|
||||
[36m [0m[36minkscape[0m[36m [0m[4;36mfilename.svg[0m
|
||||
|
||||
[32mExport an SVG file into a bitmap with the default format (PNG) and the default resolution (90 DPI):[0m
|
||||
[32m [0m[32mExport an SVG file into a bitmap with the default format (PNG) and the default resolution (90 DPI):[0m
|
||||
|
||||
[36m [0m[36minkscape[0m[36m [0m[4;36mfilename.svg[0m[36m -e [0m[4;36mfilename.png[0m
|
||||
|
||||
[32mExport an SVG file into a bitmap of 600x400 pixels (aspect ratio distortion may occur):[0m
|
||||
[32m [0m[32mExport an SVG file into a bitmap of 600x400 pixels (aspect ratio distortion may occur):[0m
|
||||
|
||||
[36m [0m[36minkscape[0m[36m [0m[4;36mfilename.svg[0m[36m -e [0m[4;36mfilename.png[0m[36m -w [0m[4;36m600[0m[36m -h [0m[4;36m400[0m
|
||||
|
||||
[32mExport a single object, given its ID, into a bitmap:[0m
|
||||
[32m [0m[32mExport a single object, given its ID, into a bitmap:[0m
|
||||
|
||||
[36m [0m[36minkscape[0m[36m [0m[4;36mfilename.svg[0m[36m -i [0m[4;36mid[0m[36m -e [0m[4;36mobject.png[0m
|
||||
|
||||
[32mExport an SVG document to PDF, converting all texts to paths:[0m
|
||||
[32m [0m[32mExport an SVG document to PDF, converting all texts to paths:[0m
|
||||
|
||||
[36m [0m[36minkscape[0m[36m [0m[4;36mfilename.svg[0m[36m | [0m[36minkscape[0m[36m | [0m[36minkscape[0m[36m --export-pdf=[0m[4;36minkscape.pdf[0m[36m | [0m[36minkscape[0m[36m | [0m[36minkscape[0m[36m --export-text-to-path[0m
|
||||
|
||||
[32mDuplicate the object with id="path123", rotate the duplicate 90 degrees, save the file, and quit Inkscape:[0m
|
||||
[32m [0m[32mDuplicate the object with id="path123", rotate the duplicate 90 degrees, save the file, and quit Inkscape:[0m
|
||||
|
||||
[36m [0m[36minkscape[0m[36m [0m[4;36mfilename.svg[0m[36m --select=path123 --verb=EditDuplicate --verb=ObjectRotate90 --verb=FileSave --verb=FileQuit[0m
|
||||
|
||||
[32mSome invalid command just to test the correct highlighting of the command name:[0m
|
||||
[32m [0m[32mSome invalid command just to test the correct highlighting of the command name:[0m
|
||||
|
||||
[36m [0m[36minkscape[0m[36m --use-inkscape=v3.0 file[0m
|
||||
|
||||
|
|
|
|||
|
|
@ -2,31 +2,31 @@
|
|||
An SVG (Scalable Vector Graphics) editing program.
|
||||
Use -z to not open the GUI and only process files in the console.
|
||||
|
||||
[44;30mOpen an SVG file in the Inkscape GUI:[0m
|
||||
[44;30m [0m[44;30mOpen an SVG file in the Inkscape GUI:[0m
|
||||
|
||||
[1minkscape[0m [3;4mfilename.svg[0m
|
||||
|
||||
[44;30mExport an SVG file into a bitmap with the default format (PNG) and the default resolution (90 DPI):[0m
|
||||
[44;30m [0m[44;30mExport an SVG file into a bitmap with the default format (PNG) and the default resolution (90 DPI):[0m
|
||||
|
||||
[1minkscape[0m [3;4mfilename.svg[0m -e [3;4mfilename.png[0m
|
||||
|
||||
[44;30mExport an SVG file into a bitmap of 600x400 pixels (aspect ratio distortion may occur):[0m
|
||||
[44;30m [0m[44;30mExport an SVG file into a bitmap of 600x400 pixels (aspect ratio distortion may occur):[0m
|
||||
|
||||
[1minkscape[0m [3;4mfilename.svg[0m -e [3;4mfilename.png[0m -w [3;4m600[0m -h [3;4m400[0m
|
||||
|
||||
[44;30mExport a single object, given its ID, into a bitmap:[0m
|
||||
[44;30m [0m[44;30mExport a single object, given its ID, into a bitmap:[0m
|
||||
|
||||
[1minkscape[0m [3;4mfilename.svg[0m -i [3;4mid[0m -e [3;4mobject.png[0m
|
||||
|
||||
[44;30mExport an SVG document to PDF, converting all texts to paths:[0m
|
||||
[44;30m [0m[44;30mExport an SVG document to PDF, converting all texts to paths:[0m
|
||||
|
||||
[1minkscape[0m [3;4mfilename.svg[0m | [1minkscape[0m | [1minkscape[0m --export-pdf=[3;4minkscape.pdf[0m | [1minkscape[0m | [1minkscape[0m --export-text-to-path
|
||||
|
||||
[44;30mDuplicate the object with id="path123", rotate the duplicate 90 degrees, save the file, and quit Inkscape:[0m
|
||||
[44;30m [0m[44;30mDuplicate the object with id="path123", rotate the duplicate 90 degrees, save the file, and quit Inkscape:[0m
|
||||
|
||||
[1minkscape[0m [3;4mfilename.svg[0m --select=path123 --verb=EditDuplicate --verb=ObjectRotate90 --verb=FileSave --verb=FileQuit
|
||||
|
||||
[44;30mSome invalid command just to test the correct highlighting of the command name:[0m
|
||||
[44;30m [0m[44;30mSome invalid command just to test the correct highlighting of the command name:[0m
|
||||
|
||||
[1minkscape[0m --use-inkscape=v3.0 file
|
||||
|
||||
|
|
|
|||
|
|
@ -1,34 +1,34 @@
|
|||
|
||||
[36minkscape[0m
|
||||
[36m [0m[36minkscape[0m
|
||||
|
||||
An SVG (Scalable Vector Graphics) editing program.
|
||||
Use -z to not open the GUI and only process files in the console.
|
||||
|
||||
[32mOpen an SVG file in the Inkscape GUI:[0m
|
||||
[32m [0m[32mOpen an SVG file in the Inkscape GUI:[0m
|
||||
|
||||
[36m [0m[36minkscape[0m[36m [0m[4;36mfilename.svg[0m
|
||||
|
||||
[32mExport an SVG file into a bitmap with the default format (PNG) and the default resolution (90 DPI):[0m
|
||||
[32m [0m[32mExport an SVG file into a bitmap with the default format (PNG) and the default resolution (90 DPI):[0m
|
||||
|
||||
[36m [0m[36minkscape[0m[36m [0m[4;36mfilename.svg[0m[36m -e [0m[4;36mfilename.png[0m
|
||||
|
||||
[32mExport an SVG file into a bitmap of 600x400 pixels (aspect ratio distortion may occur):[0m
|
||||
[32m [0m[32mExport an SVG file into a bitmap of 600x400 pixels (aspect ratio distortion may occur):[0m
|
||||
|
||||
[36m [0m[36minkscape[0m[36m [0m[4;36mfilename.svg[0m[36m -e [0m[4;36mfilename.png[0m[36m -w [0m[4;36m600[0m[36m -h [0m[4;36m400[0m
|
||||
|
||||
[32mExport a single object, given its ID, into a bitmap:[0m
|
||||
[32m [0m[32mExport a single object, given its ID, into a bitmap:[0m
|
||||
|
||||
[36m [0m[36minkscape[0m[36m [0m[4;36mfilename.svg[0m[36m -i [0m[4;36mid[0m[36m -e [0m[4;36mobject.png[0m
|
||||
|
||||
[32mExport an SVG document to PDF, converting all texts to paths:[0m
|
||||
[32m [0m[32mExport an SVG document to PDF, converting all texts to paths:[0m
|
||||
|
||||
[36m [0m[36minkscape[0m[36m [0m[4;36mfilename.svg[0m[36m | [0m[36minkscape[0m[36m | [0m[36minkscape[0m[36m --export-pdf=[0m[4;36minkscape.pdf[0m[36m | [0m[36minkscape[0m[36m | [0m[36minkscape[0m[36m --export-text-to-path[0m
|
||||
|
||||
[32mDuplicate the object with id="path123", rotate the duplicate 90 degrees, save the file, and quit Inkscape:[0m
|
||||
[32m [0m[32mDuplicate the object with id="path123", rotate the duplicate 90 degrees, save the file, and quit Inkscape:[0m
|
||||
|
||||
[36m [0m[36minkscape[0m[36m [0m[4;36mfilename.svg[0m[36m --select=path123 --verb=EditDuplicate --verb=ObjectRotate90 --verb=FileSave --verb=FileQuit[0m
|
||||
|
||||
[32mSome invalid command just to test the correct highlighting of the command name:[0m
|
||||
[32m [0m[32mSome invalid command just to test the correct highlighting of the command name:[0m
|
||||
|
||||
[36m [0m[36minkscape[0m[36m --use-inkscape=v3.0 file[0m
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue