Skip to content

Commit 8f35cf4

Browse files
committed
Added method to detect when ESC is pressed during menu selection.
1 parent 44180ef commit 8f35cf4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

input_menu.go

+17
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ chosen.
122122
*/
123123
func GetSelectionFromProportionalHorizontalMenu(layerAlias string, styleEntry memory.TuiStyleEntryType, selectionEntry memory.SelectionEntryType, xLocation int, yLocation int, menuWidth int, numberOfItemsOnRow int, defaultItemSelected int) string {
124124
selectionIndex := GetSelectionFromProportionalHorizontalMenuByIndex(layerAlias, styleEntry, selectionEntry, xLocation, yLocation, menuWidth, numberOfItemsOnRow, defaultItemSelected)
125+
if selectionIndex == constants.NullSelectionIndex {
126+
return ""
127+
}
125128
return selectionEntry.SelectionAlias[selectionIndex]
126129
}
127130

@@ -207,6 +210,10 @@ func GetSelectionFromProportionalHorizontalMenuByIndex(layerAlias string, styleE
207210
returnValue = selectedItem
208211
isItemSelected = true
209212
}
213+
if currentKeyPressed == "esc" {
214+
returnValue = constants.NullSelectionIndex
215+
isItemSelected = true
216+
}
210217
if previouslySelectedItem != selectedItem {
211218
if selectedItem >= len(selectionEntry.SelectionValue) {
212219
selectedItem = len(selectionEntry.SelectionValue) - 1
@@ -237,6 +244,9 @@ chosen.
237244
*/
238245
func GetSelectionFromHorizontalMenu(layerAlias string, styleEntry memory.TuiStyleEntryType, selectionEntry memory.SelectionEntryType, xLocation int, yLocation int, defaultItemSelected int) string {
239246
selectionIndex := GetSelectionFromHorizontalMenuByIndex(layerAlias, styleEntry, selectionEntry, xLocation, yLocation, defaultItemSelected)
247+
if selectionIndex == constants.NullSelectionIndex {
248+
return ""
249+
}
240250
return selectionEntry.SelectionAlias[selectionIndex]
241251
}
242252

@@ -297,6 +307,10 @@ func GetSelectionFromHorizontalMenuByIndex(layerAlias string, styleEntry memory.
297307
returnValue = selectedItem
298308
isItemSelected = true
299309
}
310+
if currentKeyPressed == "esc" {
311+
returnValue = constants.NullSelectionIndex
312+
isItemSelected = true
313+
}
300314
if previouslySelectedItem != selectedItem {
301315
if selectedItem >= len(selectionEntry.SelectionValue) {
302316
selectedItem = len(selectionEntry.SelectionValue) - 1
@@ -360,6 +374,9 @@ chosen.
360374
*/
361375
func GetSelectionFromVerticalMenu (layerAlias string, styleEntry memory.TuiStyleEntryType, selectionEntry memory.SelectionEntryType, xLocation int, yLocation int, menuWidth int, menuHeight int, defaultItemSelected int) string {
362376
selectionIndex := GetSelectionFromVerticalMenuByIndex(layerAlias, styleEntry , selectionEntry, xLocation, yLocation, menuWidth, menuHeight, defaultItemSelected)
377+
if selectionIndex == constants.NullSelectionIndex {
378+
return ""
379+
}
363380
return selectionEntry.SelectionAlias[selectionIndex]
364381
}
365382

0 commit comments

Comments
 (0)