-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathplugin_entry.rs
146 lines (138 loc) · 4.12 KB
/
plugin_entry.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#[allow(unused_imports)]
use crate::clapflags::CLAP_FLAGS;
use crate::drw::Drw;
#[allow(unused_imports)]
use crate::item::{Item, MatchCode};
#[allow(unused_imports)]
use crate::result::*;
use overrider::*;
#[allow(unused_imports)]
use regex::{Regex, RegexBuilder};
use crate::config::ConfigDefault;
use crate::config::DefaultWidth;
use crate::config::Schemes::*;
#[default]
impl Drw {
/**
* When taking input from stdin, apply post-processing
*/
pub fn format_stdin(&mut self, lines: Vec<String>) -> CompResult<Vec<String>> {
Ok(lines)
}
/**
* Every time the input is drawn, how should it be presented?
* Does it need additional processing?
*/
pub fn format_input(&mut self) -> CompResult<String> {
Ok(self.input.clone())
}
/**
* What to do when printing to stdout / program termination?
*
* Args:
* - output: what's being processed
* - recommendation: is exiting recommended? C-Enter will not normally exit
*
* Returns - true if program should exit
*/
pub fn dispose(&mut self, output: String, recommendation: bool) -> CompResult<bool> {
println!("{}", output);
Ok(recommendation)
}
/**
* The following is called immediatly after gen_matches, taking its unwrapped output
*
* This is particularly useful for doing something based on a match method defined
* elsewhere. For example, if any matched items contain a key, highlight them,
* but still allow a custom matching algorithm (such as from the fuzzy plugin)
*/
pub fn postprocess_matches(&mut self, items: Vec<Item>) -> CompResult<Vec<Item>> {
Ok(items)
}
/**
* Every time the input changes, what items should be shown
* And, how should they be shown?
*
* Returns - Vector of items to be drawn
*/
pub fn gen_matches(&mut self) -> CompResult<Vec<Item>> {
let re = RegexBuilder::new(®ex::escape(&self.input))
.case_insensitive(!self.config.case_sensitive)
.build()
.map_err(|_| Die::Stderr("Could not build regex".to_owned()))?;
let mut exact: Vec<Item> = Vec::new();
let mut prefix: Vec<Item> = Vec::new();
let mut substring: Vec<Item> = Vec::new();
for item in self.get_items() {
match item.matches(&re) {
MatchCode::Exact => exact.push(item.clone()),
MatchCode::Prefix => prefix.push(item.clone()),
MatchCode::Substring => substring.push(item.clone()),
MatchCode::None => {}
}
}
exact.reserve(prefix.len() + substring.len());
for item in prefix {
// extend is broken for pointers
exact.push(item);
}
for item in substring {
exact.push(item);
}
Ok(exact)
}
}
/// The following are the default config values, loaded just after program init
#[default]
impl ConfigDefault {
pub fn lines() -> u32 {
0
}
pub fn topbar() -> bool {
true
}
pub fn prompt() -> String {
String::new()
}
pub fn fontstrings() -> Vec<String> {
vec!["mono:size=10".to_owned()]
}
pub fn fast() -> bool {
false
}
pub fn embed() -> u64 {
0
}
pub fn case_sensitive() -> bool {
true
}
pub fn mon() -> i32 {
-1
}
pub fn colors() -> [[[u8; 8]; 2]; SchemeLast as usize] {
/* [ fg bg ]*/
let mut arr = [[[0; 8]; 2]; SchemeLast as usize];
arr[SchemeNorm as usize] = [*b"#bbbbbb\0", *b"#222222\0"];
arr[SchemeSel as usize] = [*b"#eeeeee\0", *b"#005577\0"];
arr[SchemeOut as usize] = [*b"#000000\0", *b"#00ffff\0"];
arr
}
pub fn nostdin() -> bool {
false
}
pub fn render_minheight() -> u32 {
4
}
pub fn render_overrun() -> bool {
false
}
pub fn render_flex() -> bool {
false
}
pub fn render_rightalign() -> bool {
false
}
pub fn render_default_width() -> DefaultWidth {
DefaultWidth::Items
}
}