Skip to content

Commit 308cd86

Browse files
committed
Fzf lib update
1 parent 80313c5 commit 308cd86

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

libs/fzf/haxelib.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "fzf",
3+
"description": "Haxe implementation of fzf-like picker",
4+
"version": "0.0.1",
5+
"releasenote": "Basic impl for eval",
6+
"url": "https://github.com/kLabz/haxe-manager/tree/master/libs/fzf",
7+
"license": "MIT",
8+
"tags": [],
9+
"classPath": "src",
10+
"contributors": [
11+
"klabz"
12+
]
13+
}

libs/fzf/src/fzf/Fzf.hx

+15-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ import fuzzaldrin.Filter;
1010
import fuzzaldrin.Scorer;
1111
import fzf.WordNav;
1212

13+
typedef FzfOptions = {
14+
@:optional var prompt:String;
15+
@:optional var geom:{width:Int, height:Int};
16+
}
17+
1318
class Fzf {
1419
final items:Array<String>;
1520
final cb:Option<String>->Void;
1621
final prompt:String;
1722
final strippedPrompt:String;
1823
final tty:Tty;
24+
final options:FzfOptions;
1925

2026
var scroll:Int = 0;
2127
var cursor:Int = 0;
@@ -58,9 +64,14 @@ class Fzf {
5864
static inline var Grey = ANSI.CSI + '38;5;241m';
5965
static inline var GreyBack = ANSI.CSI + '48;5;236m';
6066

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) {
6272
this.items = items;
6373
this.cb = cb;
74+
this.options = options ?? defaultOptions();
6475
this.filteredItems = items.map(i -> {
6576
candidate: i,
6677
string: i,
@@ -71,11 +82,12 @@ class Fzf {
7182
});
7283

7384
// TODO: strip sequences in prompt input?
85+
var prompt = options.prompt ?? "";
7486
this.strippedPrompt = (prompt == "" ? "" : prompt + " ") + "> ";
7587
this.prompt = ANSI.set(Bold) + LightBlue + this.strippedPrompt + ANSI.set(Off);
7688

7789
// 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();
7991

8092
var esc = [];
8193
while (true) {
@@ -195,7 +207,7 @@ class Fzf {
195207

196208
function redraw():Void {
197209
var screen = "";
198-
final geom = tty.getWinSize().resolve();
210+
final geom = options.geom ?? tty.getWinSize().resolve();
199211
final height = geom.height - 2;
200212
final hasScroll = height < filteredItems.length;
201213

src/HaxeSelect.hx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class HaxeSelect {
2121
public static function fzf():Void {
2222
final prompt = 'Current: ' + Utils.getCurrentFull().or('none');
2323

24-
new Fzf(Utils.getVersions(), prompt, res -> {
24+
new Fzf(Utils.getVersions(), {prompt: prompt}, res -> {
2525
switch res {
2626
case None: Sys.println('No Haxe version selected');
2727
case Some(v): select(v);

0 commit comments

Comments
 (0)