@@ -10,12 +10,18 @@ import fuzzaldrin.Filter;
10
10
import fuzzaldrin .Scorer ;
11
11
import fzf .WordNav ;
12
12
13
+ typedef FzfOptions = {
14
+ @:optional var prompt : String ;
15
+ @:optional var geom : {width : Int , height : Int };
16
+ }
17
+
13
18
class Fzf {
14
19
final items : Array <String >;
15
20
final cb : Option <String >-> Void ;
16
21
final prompt : String ;
17
22
final strippedPrompt : String ;
18
23
final tty : Tty ;
24
+ final options : FzfOptions ;
19
25
20
26
var scroll : Int = 0 ;
21
27
var cursor : Int = 0 ;
@@ -58,9 +64,14 @@ class Fzf {
58
64
static inline var Grey = ANSI .CSI + ' 38;5;241m' ;
59
65
static inline var GreyBack = ANSI .CSI + ' 48;5;236m' ;
60
66
61
- public function new (items : Array <String >, ? prompt : String = " " , cb : Option <String >-> Void ) {
67
+ static function defaultOptions (): FzfOptions {
68
+ return {};
69
+ }
70
+
71
+ public function new (items : Array <String >, ? options : FzfOptions , cb : Option <String >-> Void ) {
62
72
this .items = items ;
63
73
this .cb = cb ;
74
+ this .options = options ?? defaultOptions ();
64
75
this .filteredItems = items .map (i -> {
65
76
candidate : i ,
66
77
string : i ,
@@ -71,11 +82,12 @@ class Fzf {
71
82
});
72
83
73
84
// TODO: strip sequences in prompt input?
85
+ var prompt = options .prompt ?? " " ;
74
86
this .strippedPrompt = (prompt == " " ? " " : prompt + " " ) + " > " ;
75
87
this .prompt = ANSI .set (Bold ) + LightBlue + this .strippedPrompt + ANSI .set (Off );
76
88
77
89
// TODO: find a way to have a proper _new_ tty
78
- this .tty = Tty .init (Loop .defaultLoop (), File .stderr ).resolve ();
90
+ if ( options . geom == null ) this .tty = Tty .init (Loop .defaultLoop (), File .stderr ).resolve ();
79
91
80
92
var esc = [];
81
93
while (true ) {
@@ -195,7 +207,7 @@ class Fzf {
195
207
196
208
function redraw (): Void {
197
209
var screen = " " ;
198
- final geom = tty .getWinSize ().resolve ();
210
+ final geom = options . geom ?? tty .getWinSize ().resolve ();
199
211
final height = geom .height - 2 ;
200
212
final hasScroll = height < filteredItems .length ;
201
213
0 commit comments