tangled
alpha
login
or
join now
eldridge.cam
/
paper-terminal
0
fork
atom
Print Markdown to a paper in your terminal
0
fork
atom
overview
issues
pulls
pipelines
Update for new syncat-stylesheet
Cameron Eldridge
6 years ago
5925f0d8
4b6938aa
+43
-25
5 changed files
expand all
collapse all
unified
split
Cargo.lock
Cargo.toml
src
default.syncat
main.rs
printer.rs
+13
-7
Cargo.lock
···
194
194
source = "registry+https://github.com/rust-lang/crates.io-index"
195
195
196
196
[[package]]
197
197
+
name = "enquote"
198
198
+
version = "1.0.3"
199
199
+
source = "registry+https://github.com/rust-lang/crates.io-index"
200
200
+
201
201
+
[[package]]
197
202
name = "getopts"
198
203
version = "0.2.21"
199
204
source = "registry+https://github.com/rust-lang/crates.io-index"
···
372
377
"image 0.21.3 (registry+https://github.com/rust-lang/crates.io-index)",
373
378
"pulldown-cmark 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
374
379
"structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
375
375
-
"syncat-stylesheet 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
380
380
+
"syncat-stylesheet 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
376
381
"terminal_size 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
377
382
]
378
383
···
608
613
609
614
[[package]]
610
615
name = "syncat-stylesheet"
611
611
-
version = "0.2.2"
616
616
+
version = "2.1.3"
612
617
source = "registry+https://github.com/rust-lang/crates.io-index"
613
618
dependencies = [
614
619
"ansi_term 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
615
620
"cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
621
621
+
"enquote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
616
622
"hex 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
617
617
-
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
618
623
"regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
619
619
-
"tree-sitter 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)",
624
624
+
"tree-sitter 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
620
625
]
621
626
622
627
[[package]]
···
665
670
666
671
[[package]]
667
672
name = "tree-sitter"
668
668
-
version = "0.3.10"
673
673
+
version = "0.6.2"
669
674
source = "registry+https://github.com/rust-lang/crates.io-index"
670
675
dependencies = [
671
676
"cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
···
757
762
"checksum directories 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "72d337a64190607d4fcca2cb78982c5dd57f4916e19696b48a575fa746b6cb0f"
758
763
"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
759
764
"checksum encode_unicode 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
765
765
+
"checksum enquote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ec878a5d2f3b6e9eaee72373dd23414cfc7d353104741471bec712ef241a66e"
760
766
"checksum getopts 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
761
767
"checksum gif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "471d90201b3b223f3451cd4ad53e34295f16a1df17b1edf3736d47761c3981af"
762
768
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
···
806
812
"checksum structopt-derive 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "53010261a84b37689f9ed7d395165029f9cc7abb9f56bbfe86bee2597ed25107"
807
813
"checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
808
814
"checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5"
809
809
-
"checksum syncat-stylesheet 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6f92ae762ed216b0cd9d04eb18b7f1b37437e40327c813f5700fb96af21a5172"
815
815
+
"checksum syncat-stylesheet 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7ce14cf1686251f4da8b99ab03bd092c100db93beb7d97d779417fe1dbd94f44"
810
816
"checksum terminal_size 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "e25a60e3024df9029a414be05f46318a77c22538861a22170077d0388c0e926e"
811
817
"checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625"
812
818
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
813
819
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
814
820
"checksum tiff 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1e4834f28a0330cb9f3f2c87d2649dca723cb33802e2bdcf18da32759fbec7ce"
815
815
-
"checksum tree-sitter 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)" = "fda2848555d2e422760538de9efa1ffcadc42b56b9f2f7993299820ba904eba2"
821
821
+
"checksum tree-sitter 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "66a01ebfff2de8b613a089d4c0c11d161a7548f166318d9fb228a3539b7a8a4a"
816
822
"checksum unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
817
823
"checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
818
824
"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
+1
-1
Cargo.toml
···
23
23
image = "0.21"
24
24
console = "0.7"
25
25
directories = "1.0"
26
26
-
syncat-stylesheet = "0.2"
26
26
+
syncat-stylesheet = { version = "2.1.3", features = ["ansi_term"] }
+3
-3
src/default.syncat
···
4
4
}
5
5
6
6
shadow {
7
7
-
background-color: 8;
7
7
+
background-color: brblack;
8
8
}
9
9
10
10
li "prefix",
11
11
blockquote "prefix" {
12
12
-
color: 8;
12
12
+
color: brblack;
13
13
dim: true;
14
14
}
15
15
···
71
71
}
72
72
73
73
footnote-def, footnote-ref {
74
74
-
color: 8;
74
74
+
color: brblack;
75
75
dim: true;
76
76
}
77
77
+7
-7
src/main.rs
···
1
1
-
use std::path::PathBuf;
1
1
+
use std::convert::TryInto;
2
2
use std::io::{self, Read};
3
3
-
use std::fs::{self, File};
3
3
+
use std::fs;
4
4
+
use std::path::PathBuf;
5
5
+
use ansi_term::Style;
4
6
use structopt::StructOpt;
5
7
use terminal_size::{Width, terminal_size};
6
8
use console::strip_ansi_codes;
···
108
110
109
111
let centering = " ".repeat((terminal_width - width) / 2);
110
112
111
111
-
let stylesheet = File::open(dirs::active_color().join("paper.syncat"))
112
112
-
.map_err(Into::into)
113
113
-
.and_then(|mut file| Stylesheet::from_reader(&mut file))
113
113
+
let stylesheet = Stylesheet::from_file(dirs::active_color().join("paper.syncat"))
114
114
.unwrap_or_else(|_| include_str!("default.syncat").parse::<Stylesheet>().unwrap());
115
115
-
let paper_style = stylesheet.resolve_basic(&["paper"], None).build();
116
116
-
let shadow_style = stylesheet.resolve_basic(&["shadow"], None).build();
115
115
+
let paper_style: Style = stylesheet.style(&"paper".into()).unwrap_or_default().try_into().unwrap_or_default();
116
116
+
let shadow_style: Style = stylesheet.style(&"shadow".into()).unwrap_or_default().try_into().unwrap_or_default();
117
117
let blank_line = format!("{}", paper_style.paint(" ".repeat(width)));
118
118
let end_shadow = format!("{}", shadow_style.paint(" "));
119
119
let margin = format!("{}", paper_style.paint(" ".repeat(h_margin)));
+19
-7
src/printer.rs
···
1
1
+
use std::convert::{TryInto, TryFrom};
2
2
+
use std::io::{Read as _, Write as _};
1
3
use std::process::{Command, Stdio};
2
2
-
use std::io::{Read as _, Write as _};
3
4
use ansi_term::Style;
4
5
use pulldown_cmark::{Alignment, Event, Tag};
5
6
use image::{self, GenericImageView as _};
6
7
use console::{measure_text_width, AnsiCodeIterator};
7
7
-
use syncat_stylesheet::Stylesheet;
8
8
+
use syncat_stylesheet::{Stylesheet, Query};
8
9
use crate::termpix;
9
10
use crate::words::Words;
10
11
use crate::table::Table;
···
183
184
let prefix = scope.prefix();
184
185
let mut all_scopes = scopes.clone();
185
186
all_scopes.append(&mut extra_scopes.unwrap_or(&[]).to_vec());
186
186
-
let style = stylesheet.resolve_basic(&all_scopes[..], Some("prefix")).build();
187
187
+
let style = Self::resolve_scopes(&stylesheet, &all_scopes, Some("prefix"));
187
188
Some((format!("{}", style.paint(&prefix)), prefix.chars().count()))
188
189
})
189
190
.fold((String::new(), 0), |(s, c), (s2, c2)| (s + &s2, c + c2))
···
202
203
let suffix = scope.suffix();
203
204
let mut all_scopes = scopes.clone();
204
205
all_scopes.append(&mut extra_scopes.unwrap_or(&[]).to_vec());
205
205
-
let style = stylesheet.resolve_basic(&all_scopes[..], Some("suffix")).build();
206
206
+
let style = Self::resolve_scopes(&stylesheet, &all_scopes, Some("suffix"));
206
207
Some((format!("{}", style.paint(&suffix)), suffix.chars().count()))
207
208
})
208
209
.fold((String::new(), 0), |(s, c), (s2, c2)| (s2 + &s, c + c2))
···
213
214
if let Some(extras) = extra_scopes {
214
215
scope_names.append(&mut extras.to_vec());
215
216
}
216
216
-
self.stylesheet.resolve_basic(&scope_names, token).build()
217
217
+
Self::resolve_scopes(&self.stylesheet, &scope_names, token)
218
218
+
}
219
219
+
220
220
+
fn resolve_scopes(stylesheet: &Stylesheet, scopes: &[&str], token: Option<&str>) -> Style {
221
221
+
if scopes.is_empty() { return Style::default(); }
222
222
+
let mut query = Query::new(scopes[0], token.unwrap_or(scopes[0]));
223
223
+
let mut index = vec![];
224
224
+
for scope in &scopes[1..] {
225
225
+
query[&index[..]].add_child(Query::new(*scope, token.unwrap_or(scope)));
226
226
+
index.push(0);
227
227
+
}
228
228
+
stylesheet.style(&query).unwrap_or_default().try_into().unwrap_or_default()
217
229
}
218
230
219
231
fn style2(&self, token: Option<&str>) -> Style {
···
225
237
}
226
238
227
239
fn shadow(&self) -> String {
228
228
-
format!("{}", self.stylesheet.resolve_basic(&["shadow"], None).build().paint(" "))
240
240
+
format!("{}", Style::try_from(self.stylesheet.style(&"shadow".into()).unwrap_or_default()).unwrap_or_default().paint(" "))
229
241
}
230
242
231
243
fn paper_style(&self) -> Style {
232
232
-
self.stylesheet.resolve_basic(&["paper"], None).build()
244
244
+
Style::try_from(self.stylesheet.style(&"paper".into()).unwrap_or_default()).unwrap_or_default()
233
245
}
234
246
235
247
fn queue_empty(&mut self) {