mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
add DelItem method to Menu
This commit is contained in:
@ -66,12 +66,26 @@ func (m *Menu) AddItems(items ...MenuItem) {
|
|||||||
m.refresh()
|
m.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove menu item by value or label
|
||||||
|
func (m *Menu) DelItem(s string) (success bool) {
|
||||||
|
for n, i := range m.Items {
|
||||||
|
if i.Val == s || i.Label == s {
|
||||||
|
m.Items = append(m.Items[:n], m.Items[n+1:]...)
|
||||||
|
success = true
|
||||||
|
m.refresh()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return success
|
||||||
|
}
|
||||||
|
|
||||||
// Sort menu items(if enabled) and re-calculate window size
|
// Sort menu items(if enabled) and re-calculate window size
|
||||||
func (m *Menu) refresh() {
|
func (m *Menu) refresh() {
|
||||||
if m.SortItems {
|
if m.SortItems {
|
||||||
sort.Sort(m.Items)
|
sort.Sort(m.Items)
|
||||||
}
|
}
|
||||||
m.calcSize()
|
m.calcSize()
|
||||||
|
ui.Render(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Menu) SelectedItem() MenuItem {
|
func (m *Menu) SelectedItem() MenuItem {
|
||||||
|
Reference in New Issue
Block a user