inquirerer 4.1.1 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/prompt.js +33 -0
- package/package.json +2 -2
- package/prompt.js +33 -0
package/esm/prompt.js
CHANGED
|
@@ -752,6 +752,19 @@ export class Inquirerer {
|
|
|
752
752
|
});
|
|
753
753
|
const updateFilteredOptions = () => {
|
|
754
754
|
filteredOptions = this.filterOptions(options, input);
|
|
755
|
+
// Clamp selectedIndex and startIndex when filtered results change
|
|
756
|
+
if (filteredOptions.length === 0) {
|
|
757
|
+
selectedIndex = 0;
|
|
758
|
+
startIndex = 0;
|
|
759
|
+
}
|
|
760
|
+
else {
|
|
761
|
+
if (selectedIndex >= filteredOptions.length) {
|
|
762
|
+
selectedIndex = filteredOptions.length - 1;
|
|
763
|
+
}
|
|
764
|
+
if (startIndex > Math.max(0, filteredOptions.length - maxLines)) {
|
|
765
|
+
startIndex = Math.max(0, filteredOptions.length - maxLines);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
755
768
|
};
|
|
756
769
|
const display = () => {
|
|
757
770
|
this.clearScreen();
|
|
@@ -788,6 +801,10 @@ export class Inquirerer {
|
|
|
788
801
|
});
|
|
789
802
|
});
|
|
790
803
|
this.keypress.on(KEY_CODES.UP_ARROW, () => {
|
|
804
|
+
if (filteredOptions.length === 0) {
|
|
805
|
+
display();
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
791
808
|
selectedIndex = selectedIndex > 0 ? selectedIndex - 1 : filteredOptions.length - 1;
|
|
792
809
|
if (selectedIndex < startIndex) {
|
|
793
810
|
startIndex = selectedIndex; // Scroll up
|
|
@@ -798,6 +815,10 @@ export class Inquirerer {
|
|
|
798
815
|
display();
|
|
799
816
|
});
|
|
800
817
|
this.keypress.on(KEY_CODES.DOWN_ARROW, () => {
|
|
818
|
+
if (filteredOptions.length === 0) {
|
|
819
|
+
display();
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
801
822
|
selectedIndex = (selectedIndex + 1) % filteredOptions.length;
|
|
802
823
|
if (selectedIndex >= startIndex + maxLines) {
|
|
803
824
|
startIndex = selectedIndex - maxLines + 1; // Scroll down
|
|
@@ -808,6 +829,10 @@ export class Inquirerer {
|
|
|
808
829
|
display();
|
|
809
830
|
});
|
|
810
831
|
this.keypress.on(KEY_CODES.SPACE, () => {
|
|
832
|
+
if (filteredOptions.length === 0 || !filteredOptions[selectedIndex]) {
|
|
833
|
+
display();
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
811
836
|
// Map filtered index back to the original index in options
|
|
812
837
|
selections[options.indexOf(filteredOptions[selectedIndex])] = !selections[options.indexOf(filteredOptions[selectedIndex])];
|
|
813
838
|
display();
|
|
@@ -907,6 +932,10 @@ export class Inquirerer {
|
|
|
907
932
|
});
|
|
908
933
|
// Navigation
|
|
909
934
|
this.keypress.on(KEY_CODES.UP_ARROW, () => {
|
|
935
|
+
if (filteredOptions.length === 0) {
|
|
936
|
+
display();
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
910
939
|
selectedIndex = selectedIndex - 1 >= 0 ? selectedIndex - 1 : filteredOptions.length - 1;
|
|
911
940
|
if (selectedIndex < startIndex) {
|
|
912
941
|
startIndex = selectedIndex; // Scroll up
|
|
@@ -917,6 +946,10 @@ export class Inquirerer {
|
|
|
917
946
|
display();
|
|
918
947
|
});
|
|
919
948
|
this.keypress.on(KEY_CODES.DOWN_ARROW, () => {
|
|
949
|
+
if (filteredOptions.length === 0) {
|
|
950
|
+
display();
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
920
953
|
selectedIndex = (selectedIndex + 1) % filteredOptions.length;
|
|
921
954
|
if (selectedIndex >= startIndex + maxLines) {
|
|
922
955
|
startIndex = selectedIndex - maxLines + 1; // Scroll down
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inquirerer",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "TypeScript-first library for building beautiful CLI interfaces with interactive prompts",
|
|
6
6
|
"main": "index.js",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"clean-ansi": "0.1.7",
|
|
42
42
|
"makage": "0.1.8"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "8f2e433e1feb28d23095ce761388a61a0e827bd0"
|
|
45
45
|
}
|
package/prompt.js
CHANGED
|
@@ -759,6 +759,19 @@ class Inquirerer {
|
|
|
759
759
|
});
|
|
760
760
|
const updateFilteredOptions = () => {
|
|
761
761
|
filteredOptions = this.filterOptions(options, input);
|
|
762
|
+
// Clamp selectedIndex and startIndex when filtered results change
|
|
763
|
+
if (filteredOptions.length === 0) {
|
|
764
|
+
selectedIndex = 0;
|
|
765
|
+
startIndex = 0;
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
if (selectedIndex >= filteredOptions.length) {
|
|
769
|
+
selectedIndex = filteredOptions.length - 1;
|
|
770
|
+
}
|
|
771
|
+
if (startIndex > Math.max(0, filteredOptions.length - maxLines)) {
|
|
772
|
+
startIndex = Math.max(0, filteredOptions.length - maxLines);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
762
775
|
};
|
|
763
776
|
const display = () => {
|
|
764
777
|
this.clearScreen();
|
|
@@ -795,6 +808,10 @@ class Inquirerer {
|
|
|
795
808
|
});
|
|
796
809
|
});
|
|
797
810
|
this.keypress.on(keypress_1.KEY_CODES.UP_ARROW, () => {
|
|
811
|
+
if (filteredOptions.length === 0) {
|
|
812
|
+
display();
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
798
815
|
selectedIndex = selectedIndex > 0 ? selectedIndex - 1 : filteredOptions.length - 1;
|
|
799
816
|
if (selectedIndex < startIndex) {
|
|
800
817
|
startIndex = selectedIndex; // Scroll up
|
|
@@ -805,6 +822,10 @@ class Inquirerer {
|
|
|
805
822
|
display();
|
|
806
823
|
});
|
|
807
824
|
this.keypress.on(keypress_1.KEY_CODES.DOWN_ARROW, () => {
|
|
825
|
+
if (filteredOptions.length === 0) {
|
|
826
|
+
display();
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
808
829
|
selectedIndex = (selectedIndex + 1) % filteredOptions.length;
|
|
809
830
|
if (selectedIndex >= startIndex + maxLines) {
|
|
810
831
|
startIndex = selectedIndex - maxLines + 1; // Scroll down
|
|
@@ -815,6 +836,10 @@ class Inquirerer {
|
|
|
815
836
|
display();
|
|
816
837
|
});
|
|
817
838
|
this.keypress.on(keypress_1.KEY_CODES.SPACE, () => {
|
|
839
|
+
if (filteredOptions.length === 0 || !filteredOptions[selectedIndex]) {
|
|
840
|
+
display();
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
818
843
|
// Map filtered index back to the original index in options
|
|
819
844
|
selections[options.indexOf(filteredOptions[selectedIndex])] = !selections[options.indexOf(filteredOptions[selectedIndex])];
|
|
820
845
|
display();
|
|
@@ -914,6 +939,10 @@ class Inquirerer {
|
|
|
914
939
|
});
|
|
915
940
|
// Navigation
|
|
916
941
|
this.keypress.on(keypress_1.KEY_CODES.UP_ARROW, () => {
|
|
942
|
+
if (filteredOptions.length === 0) {
|
|
943
|
+
display();
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
917
946
|
selectedIndex = selectedIndex - 1 >= 0 ? selectedIndex - 1 : filteredOptions.length - 1;
|
|
918
947
|
if (selectedIndex < startIndex) {
|
|
919
948
|
startIndex = selectedIndex; // Scroll up
|
|
@@ -924,6 +953,10 @@ class Inquirerer {
|
|
|
924
953
|
display();
|
|
925
954
|
});
|
|
926
955
|
this.keypress.on(keypress_1.KEY_CODES.DOWN_ARROW, () => {
|
|
956
|
+
if (filteredOptions.length === 0) {
|
|
957
|
+
display();
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
927
960
|
selectedIndex = (selectedIndex + 1) % filteredOptions.length;
|
|
928
961
|
if (selectedIndex >= startIndex + maxLines) {
|
|
929
962
|
startIndex = selectedIndex - maxLines + 1; // Scroll down
|