fix(tui): stream layout density and alignment #37
@@ -108,12 +108,14 @@ func (a absorbModel) visibleCount() int {
|
|||||||
|
|
||||||
func renderAbsorbSource(e *db.Entity, maxWidth int) string {
|
func renderAbsorbSource(e *db.Entity, maxWidth int) string {
|
||||||
glyph := glyphStyle.Render(display.DisplayGlyph(e.Glyph, e.CardType))
|
glyph := glyphStyle.Render(display.DisplayGlyph(e.Glyph, e.CardType))
|
||||||
id := idStyle.Render("[" + display.FormatID(e.ID) + "]")
|
|
||||||
|
|
||||||
body := e.Body
|
body := e.Body
|
||||||
if e.Title != nil {
|
if e.Title != nil {
|
||||||
body = *e.Title
|
body = *e.Title
|
||||||
}
|
}
|
||||||
|
if idx := strings.IndexByte(body, '\n'); idx >= 0 {
|
||||||
|
body = body[:idx]
|
||||||
|
}
|
||||||
|
|
||||||
var tags string
|
var tags string
|
||||||
if len(e.Tags) > 0 {
|
if len(e.Tags) > 0 {
|
||||||
@@ -125,11 +127,12 @@ func renderAbsorbSource(e *db.Entity, maxWidth int) string {
|
|||||||
tags = " " + strings.Join(tagParts, " ")
|
tags = " " + strings.Join(tagParts, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
line := fmt.Sprintf("%s %s%s %s", glyph, body, tags, id)
|
line := fmt.Sprintf("%s %s%s", glyph, body, tags)
|
||||||
|
|
||||||
if maxWidth > 0 && len(stripAnsi(line)) > maxWidth {
|
if maxWidth > 0 && len(stripAnsi(line)) > maxWidth {
|
||||||
body = truncate(body, maxWidth-20)
|
overhead := len(stripAnsi(line)) - len([]rune(body))
|
||||||
line = fmt.Sprintf("%s %s%s %s", glyph, body, tags, id)
|
body = truncate(body, maxWidth-overhead)
|
||||||
|
line = fmt.Sprintf("%s %s%s", glyph, body, tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
return line
|
return line
|
||||||
|
|||||||
@@ -301,12 +301,14 @@ func (c cardsModel) visibleCount() int {
|
|||||||
|
|
||||||
func renderCard(e *db.Entity, maxWidth int) string {
|
func renderCard(e *db.Entity, maxWidth int) string {
|
||||||
glyph := glyphStyle.Render(display.DisplayGlyph(e.Glyph, e.CardType))
|
glyph := glyphStyle.Render(display.DisplayGlyph(e.Glyph, e.CardType))
|
||||||
id := idStyle.Render("[" + display.FormatID(e.ID) + "]")
|
|
||||||
|
|
||||||
body := e.Body
|
body := e.Body
|
||||||
if e.Title != nil {
|
if e.Title != nil {
|
||||||
body = *e.Title
|
body = *e.Title
|
||||||
}
|
}
|
||||||
|
if idx := strings.IndexByte(body, '\n'); idx >= 0 {
|
||||||
|
body = body[:idx]
|
||||||
|
}
|
||||||
|
|
||||||
affordance := detectAffordance(e)
|
affordance := detectAffordance(e)
|
||||||
affordStr := ""
|
affordStr := ""
|
||||||
@@ -335,11 +337,12 @@ func renderCard(e *db.Entity, maxWidth int) string {
|
|||||||
useStr = " " + useCountStyle.Render(fmt.Sprintf("%d×", e.UseCount))
|
useStr = " " + useCountStyle.Render(fmt.Sprintf("%d×", e.UseCount))
|
||||||
}
|
}
|
||||||
|
|
||||||
line := fmt.Sprintf("%s %s%s%s%s %s", glyph, body, affordStr, extraStr, useStr, id)
|
line := fmt.Sprintf("%s %s%s%s%s", glyph, body, affordStr, extraStr, useStr)
|
||||||
|
|
||||||
if maxWidth > 0 && len(stripAnsi(line)) > maxWidth {
|
if maxWidth > 0 && len(stripAnsi(line)) > maxWidth {
|
||||||
body = truncate(body, maxWidth-30)
|
overhead := len(stripAnsi(line)) - len([]rune(body))
|
||||||
line = fmt.Sprintf("%s %s%s%s%s %s", glyph, body, affordStr, extraStr, useStr, id)
|
body = truncate(body, maxWidth-overhead)
|
||||||
|
line = fmt.Sprintf("%s %s%s%s%s", glyph, body, affordStr, extraStr, useStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return line
|
return line
|
||||||
|
|||||||
+10
-9
@@ -204,23 +204,23 @@ func renderEntity(e *db.Entity, maxWidth int) string {
|
|||||||
}
|
}
|
||||||
glyph := style.Render(glyphStr)
|
glyph := style.Render(glyphStr)
|
||||||
|
|
||||||
id := idStyle.Render("[" + display.FormatID(e.ID) + "]")
|
|
||||||
|
|
||||||
body := e.Body
|
body := e.Body
|
||||||
if e.Title != nil {
|
if e.Title != nil {
|
||||||
body = *e.Title
|
body = *e.Title
|
||||||
}
|
}
|
||||||
|
if idx := strings.IndexByte(body, '\n'); idx >= 0 {
|
||||||
|
body = body[:idx]
|
||||||
|
}
|
||||||
|
|
||||||
var extras []string
|
var extras []string
|
||||||
if e.Pinned {
|
if e.Pinned {
|
||||||
extras = append(extras, pinnedStyle.Render("•"))
|
extras = append(extras, pinnedStyle.Render("•"))
|
||||||
}
|
}
|
||||||
if len(e.Tags) > 0 {
|
if len(e.Tags) > 0 {
|
||||||
tagParts := make([]string, len(e.Tags))
|
limit := min(2, len(e.Tags))
|
||||||
for i, t := range e.Tags {
|
for _, t := range e.Tags[:limit] {
|
||||||
tagParts[i] = tagStyle.Render("#" + t)
|
extras = append(extras, tagStyle.Render("#"+t))
|
||||||
}
|
}
|
||||||
extras = append(extras, strings.Join(tagParts, " "))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extraStr := ""
|
extraStr := ""
|
||||||
@@ -228,11 +228,12 @@ func renderEntity(e *db.Entity, maxWidth int) string {
|
|||||||
extraStr = " " + strings.Join(extras, " ")
|
extraStr = " " + strings.Join(extras, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
line := fmt.Sprintf("%s %s%s %s", glyph, body, extraStr, id)
|
line := fmt.Sprintf("%s %s%s", glyph, body, extraStr)
|
||||||
|
|
||||||
if maxWidth > 0 && len(stripAnsi(line)) > maxWidth {
|
if maxWidth > 0 && len(stripAnsi(line)) > maxWidth {
|
||||||
body = truncate(body, maxWidth-20)
|
overhead := len(stripAnsi(line)) - len([]rune(body))
|
||||||
line = fmt.Sprintf("%s %s%s %s", glyph, body, extraStr, id)
|
body = truncate(body, maxWidth-overhead)
|
||||||
|
line = fmt.Sprintf("%s %s%s", glyph, body, extraStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return line
|
return line
|
||||||
|
|||||||
@@ -455,6 +455,9 @@ func (m model) updateBrowse(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
|||||||
m.focus = focusList
|
m.focus = focusList
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
m.splitDetail = false
|
||||||
|
m.recalcSizes()
|
||||||
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.focus == focusDetail {
|
if m.focus == focusDetail {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ var (
|
|||||||
PaddingLeft(1)
|
PaddingLeft(1)
|
||||||
|
|
||||||
listItemStyle = lipgloss.NewStyle().
|
listItemStyle = lipgloss.NewStyle().
|
||||||
PaddingLeft(2)
|
PaddingLeft(4)
|
||||||
|
|
||||||
selectedItemStyle = lipgloss.NewStyle().
|
selectedItemStyle = lipgloss.NewStyle().
|
||||||
PaddingLeft(1).
|
PaddingLeft(1).
|
||||||
|
|||||||
Reference in New Issue
Block a user