mirror of
				https://github.com/shokinn/hosts-go.git
				synced 2025-11-04 12:38:34 +00:00 
			
		
		
		
	Add edit mode toggle and entry activation
This commit is contained in:
		
							parent
							
								
									0c60248d75
								
							
						
					
					
						commit
						51966f766c
					
				
					 6 changed files with 69 additions and 17 deletions
				
			
		| 
						 | 
				
			
			@ -111,3 +111,8 @@ func (m Model) SelectedEntry() *core.HostEntry {
 | 
			
		|||
	}
 | 
			
		||||
	return m.hosts.Entries[idx]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Mode returns the current operating mode of the TUI.
 | 
			
		||||
func (m Model) Mode() Mode {
 | 
			
		||||
	return m.mode
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,6 +18,20 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 | 
			
		|||
			} else {
 | 
			
		||||
				m.focus = listPane
 | 
			
		||||
			}
 | 
			
		||||
		case "e":
 | 
			
		||||
			if m.mode == ViewMode {
 | 
			
		||||
				m.mode = EditMode
 | 
			
		||||
			} else {
 | 
			
		||||
				m.mode = ViewMode
 | 
			
		||||
			}
 | 
			
		||||
		case "a":
 | 
			
		||||
			if m.mode == EditMode {
 | 
			
		||||
				if entry := m.SelectedEntry(); entry != nil {
 | 
			
		||||
					entry.Active = !entry.Active
 | 
			
		||||
					m.list.SetItem(m.list.Index(), entryItem{entry})
 | 
			
		||||
					m.refreshDetail()
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		case "up", "k":
 | 
			
		||||
			if m.focus == detailPane {
 | 
			
		||||
				m.detail.LineUp(1)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,7 +47,11 @@ func (m Model) View() string {
 | 
			
		|||
 | 
			
		||||
	// join panes and status bar
 | 
			
		||||
	panes := lipgloss.JoinHorizontal(lipgloss.Top, left, right)
 | 
			
		||||
	status := fmt.Sprintf("VIEW MODE • %d entries", len(m.hosts.Entries))
 | 
			
		||||
	modeLabel := "VIEW"
 | 
			
		||||
	if m.mode == EditMode {
 | 
			
		||||
		modeLabel = "EDIT"
 | 
			
		||||
	}
 | 
			
		||||
	status := fmt.Sprintf("%s MODE • %d entries", modeLabel, len(m.hosts.Entries))
 | 
			
		||||
	bar := statusStyle.Width(m.width).Render(status)
 | 
			
		||||
	return lipgloss.JoinVertical(lipgloss.Left, panes, bar)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue