mirror of
				https://github.com/shokinn/hosts-go.git
				synced 2025-11-04 04:28:34 +00:00 
			
		
		
		
	Fix pane border overflow
This commit is contained in:
		
							parent
							
								
									a24041d664
								
							
						
					
					
						commit
						0bcb821c33
					
				
					 2 changed files with 44 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -42,9 +42,27 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 | 
			
		|||
	case tea.WindowSizeMsg:
 | 
			
		||||
		m.width = msg.Width
 | 
			
		||||
		m.height = msg.Height - 1
 | 
			
		||||
		m.list.SetSize(msg.Width/2, m.height)
 | 
			
		||||
		m.detail.Width = msg.Width - msg.Width/2
 | 
			
		||||
		m.detail.Height = m.height
 | 
			
		||||
 | 
			
		||||
		leftWidth := msg.Width / 2
 | 
			
		||||
		rightWidth := msg.Width - leftWidth
 | 
			
		||||
		leftHeight := m.height
 | 
			
		||||
		rightHeight := m.height
 | 
			
		||||
 | 
			
		||||
		if m.focus == listPane {
 | 
			
		||||
			leftWidth -= 2
 | 
			
		||||
			leftHeight -= 2
 | 
			
		||||
		} else {
 | 
			
		||||
			rightWidth -= 2
 | 
			
		||||
			rightHeight -= 2
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		leftWidth -= 2
 | 
			
		||||
		rightWidth -= 2
 | 
			
		||||
 | 
			
		||||
		m.list.SetSize(leftWidth, leftHeight)
 | 
			
		||||
		m.detail.Width = rightWidth
 | 
			
		||||
		m.detail.Height = rightHeight
 | 
			
		||||
 | 
			
		||||
		if m.focus == listPane {
 | 
			
		||||
			m.list, cmd = m.list.Update(msg)
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,15 +18,35 @@ func (m Model) View() string {
 | 
			
		|||
	listView := m.list.View()
 | 
			
		||||
	detailView := m.detail.View()
 | 
			
		||||
 | 
			
		||||
	left := listStyle.Width(m.width / 2).Height(m.height).Render(listView)
 | 
			
		||||
	right := detailStyle.Width(m.width - m.width/2).Height(m.height).Render(detailView)
 | 
			
		||||
	// compute dimensions for each pane accounting for padding and focus border
 | 
			
		||||
	leftWidth := m.width / 2
 | 
			
		||||
	rightWidth := m.width - leftWidth
 | 
			
		||||
	leftHeight := m.height
 | 
			
		||||
	rightHeight := m.height
 | 
			
		||||
 | 
			
		||||
	if m.focus == listPane {
 | 
			
		||||
		leftWidth -= 2 // border
 | 
			
		||||
		leftHeight -= 2
 | 
			
		||||
	} else {
 | 
			
		||||
		rightWidth -= 2
 | 
			
		||||
		rightHeight -= 2
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// account for horizontal padding
 | 
			
		||||
	leftWidth -= 2
 | 
			
		||||
	rightWidth -= 2
 | 
			
		||||
 | 
			
		||||
	left := listStyle.Width(leftWidth).Height(leftHeight).Render(listView)
 | 
			
		||||
	right := detailStyle.Width(rightWidth).Height(rightHeight).Render(detailView)
 | 
			
		||||
 | 
			
		||||
	if m.focus == listPane {
 | 
			
		||||
		left = focusedStyle.Render(left)
 | 
			
		||||
	} else {
 | 
			
		||||
		right = focusedStyle.Render(right)
 | 
			
		||||
	}
 | 
			
		||||
	panes := lipgloss.JoinHorizontal(lipgloss.Top, left, right)
 | 
			
		||||
 | 
			
		||||
	// join panes and status bar
 | 
			
		||||
	panes := lipgloss.JoinHorizontal(lipgloss.Top, left, right)
 | 
			
		||||
	status := fmt.Sprintf("VIEW MODE • %d entries", 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