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