mirror of
				https://github.com/charmbracelet/crush.git
				synced 2025-08-02 05:20:46 +03:00 
			
		
		
		
	fix(messages): properly measure width when rendering attachment paths
This commit is contained in:
		@@ -207,18 +207,27 @@ func (m *messageCmp) renderUserMessage() string {
 | 
			
		||||
 | 
			
		||||
	attachments := make([]string, len(m.message.BinaryContent()))
 | 
			
		||||
	for i, attachment := range m.message.BinaryContent() {
 | 
			
		||||
		file := filepath.Base(attachment.Path)
 | 
			
		||||
		var filename string
 | 
			
		||||
		runes := []rune(file)
 | 
			
		||||
		filename := filepath.Base(attachment.Path)
 | 
			
		||||
		var displayFilename string
 | 
			
		||||
		runes := []rune(filename)
 | 
			
		||||
 | 
			
		||||
		const truncatePathAt = 7
 | 
			
		||||
		if len(runes) > truncatePathAt {
 | 
			
		||||
			filename = fmt.Sprintf(" %s %s... ", styles.DocumentIcon, string(runes[0:truncatePathAt]))
 | 
			
		||||
		const truncateAtChars = 7
 | 
			
		||||
		const truncateSuffix = "..."
 | 
			
		||||
 | 
			
		||||
		// If the filename is too long, truncate it to fit within the maximum
 | 
			
		||||
		// width we’ve chosen.
 | 
			
		||||
		if lipgloss.Width(filename) > truncateAtChars+lipgloss.Width(truncateSuffix) {
 | 
			
		||||
			displayFilename = fmt.Sprintf(
 | 
			
		||||
				" %s %s%s ",
 | 
			
		||||
				styles.DocumentIcon,
 | 
			
		||||
				string(runes[0:truncateAtChars]),
 | 
			
		||||
				truncateSuffix,
 | 
			
		||||
			)
 | 
			
		||||
		} else {
 | 
			
		||||
			filename = fmt.Sprintf(" %s %s ", styles.DocumentIcon, file)
 | 
			
		||||
			displayFilename = fmt.Sprintf(" %s %s ", styles.DocumentIcon, filename)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		attachments[i] = attachmentStyles.Render(filename)
 | 
			
		||||
		attachments[i] = attachmentStyles.Render(displayFilename)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(attachments) > 0 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user