Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc848b47

Browse files
committed
Separate marks for unicode
1 parenta3f9ba3 commitc848b47

File tree

6 files changed

+61
-11
lines changed

6 files changed

+61
-11
lines changed

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ criterion = "0.3"
1717
default = []
1818
color = ["ansi_term"]
1919
color2 = ["termcolor"]
20+
unicode = []
2021

2122
[[bench]]
2223
name ="simple"

‎src/display_list/line.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ pub struct DisplayMark {
4747
pubenumDisplayMarkType{
4848
AnnotationThrough,
4949
AnnotationStart,
50+
AnnotationEnd,
5051
}

‎src/display_list/list.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'d> From<&Slice<'d>> for DisplayList<'d> {
113113
};
114114
let inline_marks =if ann.range.start < line_start_pos{
115115
vec![DisplayMark{
116-
mark_type:DisplayMarkType::AnnotationThrough,
116+
mark_type:DisplayMarkType::AnnotationEnd,
117117
annotation_type: ann.annotation_type.clone(),
118118
}]
119119
}else{
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
pubenumMarkKind{
2+
Vertical,
3+
Horizontal,
4+
DownRight,
5+
UpRight,
6+
UpLeft,
7+
}
8+
9+
#[cfg(not(feature ="unicode"))]
10+
implMarkKind{
11+
pubfnget(t:MarkKind) ->char{
12+
match t{
13+
MarkKind::Vertical =>'|',
14+
MarkKind::Horizontal =>'-',
15+
MarkKind::DownRight =>'/',
16+
MarkKind::UpRight =>'|',
17+
MarkKind::UpLeft =>'^',
18+
}
19+
}
20+
}
21+
22+
#[cfg(feature ="unicode")]
23+
implMarkKind{
24+
pubfnget(t:MarkKind) ->char{
25+
match t{
26+
MarkKind::Vertical =>'│',
27+
MarkKind::Horizontal =>'─',
28+
MarkKind::DownRight =>'┌',
29+
MarkKind::UpRight =>'└',
30+
MarkKind::UpLeft =>'┘',
31+
}
32+
}
33+
}

‎src/renderers/ascii_default/mod.rs‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
pubmod styles;
1+
mod marks;
2+
mod styles;
23

34
#[cfg(feature ="ansi_term")]
45
usecrate::renderers::ascii_default::styles::color::Style;
@@ -15,8 +16,10 @@ use crate::display_list::line::DisplayMarkType;
1516
usecrate::display_list::line::DisplayRawLine;
1617
usecrate::display_list::line::DisplaySourceLine;
1718
usecrate::DisplayList;
19+
use marks::MarkKind;
1820
use std::cmp;
1921
use std::io::Write;
22+
use std::iter::repeat;
2023
use std::marker::PhantomData;
2124
use styles::StyleasStyleTrait;
2225
use styles::StyleType;
@@ -81,16 +84,17 @@ impl<S: StyleTrait> Renderer<S> {
8184
line,
8285
} =>{
8386
let style =&[StyleType::LineNo,StyleType::Emphasis];
87+
let vertical_mark =MarkKind::get(MarkKind::Vertical);
8488
ifletSome(lineno) = lineno{
8589
S::fmt(
8690
w,
87-
format_args!("{:>width$}| ", lineno, width = lineno_max),
91+
format_args!("{:>width$}{} ", lineno, vertical_mark, width = lineno_max),
8892
style,
8993
)?;
9094
}else{
9195
S::fmt(
9296
w,
93-
format_args!("{:>width$}| ","", width = lineno_max),
97+
format_args!("{:>width$}{} ","", vertical_mark, width = lineno_max),
9498
style,
9599
)?;
96100
}
@@ -123,13 +127,14 @@ impl<S: StyleTrait> Renderer<S> {
123127
let indent =if range.start ==0{0}else{ range.start +1};
124128
write!(w,"{:>width$}","", width = indent)?;
125129
if range.start ==0{
130+
let horizontal_mark =MarkKind::get(MarkKind::Horizontal);
126131
S::fmt(
127132
w,
128133
format_args!(
129-
"{:_>width$} {}",
130-
"^",
134+
"{}{} {}",
135+
repeat(horizontal_mark).take(5).collect::<String>(),
136+
MarkKind::get(MarkKind::UpLeft),
131137
annotation.label,
132-
width = range.len() +1
133138
),
134139
&styles,
135140
)
@@ -154,7 +159,15 @@ impl<S: StyleTrait> Renderer<S> {
154159
match line{
155160
DisplayRawLine::Origin{ path, pos} =>{
156161
write!(w,"{:>width$}","", width = lineno_max)?;
157-
S::fmt(w,"-->",&[StyleType::Emphasis,StyleType::LineNo])?;
162+
S::fmt(
163+
w,
164+
format_args!(
165+
"{}{}>",
166+
MarkKind::get(MarkKind::Horizontal),
167+
MarkKind::get(MarkKind::Horizontal),
168+
),
169+
&[StyleType::Emphasis,StyleType::LineNo],
170+
)?;
158171
write!(w," {}", path)?;
159172
ifletSome(line) = pos.0{
160173
write!(w,":{}", line)?;
@@ -198,10 +211,11 @@ impl<S: StyleTrait> Renderer<S> {
198211
) -> std::io::Result<()>{
199212
let(_, style) =self.get_annotation_type_style(&display_mark.annotation_type);
200213
let ch =match display_mark.mark_type{
201-
DisplayMarkType::AnnotationStart =>'/',
202-
DisplayMarkType::AnnotationThrough =>'|',
214+
DisplayMarkType::AnnotationStart =>MarkKind::get(MarkKind::DownRight),
215+
DisplayMarkType::AnnotationEnd =>MarkKind::get(MarkKind::UpRight),
216+
DisplayMarkType::AnnotationThrough =>MarkKind::get(MarkKind::Vertical),
203217
};
204-
S::fmt(w, ch,&[style])
218+
S::fmt(w, ch,&[StyleType::Emphasis,style])
205219
}
206220
}
207221

‎src/renderers/ascii_default/styles/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
pubmod color;
33
#[cfg(feature ="termcolor")]
44
pubmod color2;
5+
#[cfg(all(not(feature ="ansi_term"), not(feature ="termcolor")))]
56
pubmod plain;
67

78
use std::fmt;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp