aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Campos <james.r.campos@gmail.com>2020-07-11 18:32:49 -0700
committerJames Campos <james.r.campos@gmail.com>2020-07-11 18:32:49 -0700
commit59b44cb27da33f3dc1aaab94cdbe500b99bb4c7d (patch)
treeb848c5fd873aad6ba703ec135d5e3457afa81265 /src
parent8bd01b478180523fb738416f5d74089a1b1e2782 (diff)
downloadbk-59b44cb27da33f3dc1aaab94cdbe500b99bb4c7d.tar.gz
attributes
Diffstat (limited to 'src')
-rw-r--r--src/main.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index f07ba1e..d977b12 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -309,15 +309,16 @@ fn render_page(bk: &Bk, offset: usize) -> Vec<String> {
let c = bk.chap();
let line_end = min(bk.line + bk.rows - offset, bk.chap().lines.len());
+ // TODO support inline tags (strong)
let attrs = {
let text_start = c.lines[bk.line].0;
let text_end = c.lines[line_end - 1].1;
let mut search = Vec::new();
- if bk.query != "" {
+ let qlen = bk.query.len();
+ if qlen > 0 {
for (pos, _) in c.text[text_start..text_end].match_indices(&bk.query) {
- search.push((text_start + pos, Attribute::Reverse));
- search.push((text_start + pos + bk.query.len(), Attribute::Reset));
+ search.push(text_start + pos);
}
}
let mut search_iter = search.into_iter();
@@ -343,8 +344,12 @@ fn render_page(bk: &Bk, offset: usize) -> Vec<String> {
match (sn, an) {
(None, None) => panic!("does this happen?"),
(Some(s), None) => {
- merged.push(s);
- merged.extend(search_iter);
+ merged.push((s, Attribute::Reverse));
+ merged.push((s + qlen, Attribute::Reset));
+ for s in search_iter {
+ merged.push((s, Attribute::Reverse));
+ merged.push((s + qlen, Attribute::Reset));
+ }
break;
}
(None, Some(&a)) => {
@@ -353,8 +358,11 @@ fn render_page(bk: &Bk, offset: usize) -> Vec<String> {
break;
}
(Some(s), Some(&a)) => {
- if s.0 < a.0 {
- merged.push(s);
+ if s < a.0 {
+ merged.push((s, Attribute::Reverse));
+ merged.push((s + qlen, Attribute::Reset));
+ // this match arm is inside a header tag
+ merged.push((s + qlen, Attribute::Bold));
sn = search_iter.next();
} else {
merged.push(a);