1package ui23import (4 "charm.land/lipgloss/v2"56 "src.rest/cat/012/internal/sheet"7 "src.rest/cat/012/internal/ui/rowtext"8 "src.rest/cat/012/internal/ui/theme"9)1011// Cells whose text is a URL, and HYPERLINK formulas, are drawn as OSC 812// hyperlinks: blue and underlined, and Cmd- or Ctrl-clickable in13// terminals that support them. Error values get a curly underline on top14// of their color, and the context line explains the active cell's error.1516// decorate marks a span's text as a link or an error, from the cell the17// text belongs to.18func (g *grid) decorate(sp *rowtext.Span, row int) {19 if sp.Text == "" {20 return21 }22 a := sheet.Addr{Col: sp.Owner, Row: row}23 switch v := g.sheet.Value(a); {24 case v.Kind == sheet.Error && !sheet.IsPending(v):25 sp.Error = true26 case v.Kind == sheet.Text:27 sp.Link = g.sheet.Link(a)28 }29}3031// spanStyle is the style of a span's text on base: the cell's text style,32// then the link or error mark. On a colored role (the pointer, the33// selection) a link keeps the role's colors and adds its underline.34func spanStyle(th *theme.Theme, base lipgloss.Style, sp rowtext.Span) lipgloss.Style {35 st := sp.Style36 st.Align = sheet.AlignAuto37 s := th.Text(base, st)38 switch {39 case sp.Link != "":40 s = s.Inherit(th.Link).Hyperlink(sp.Link)41 case sp.Error:42 s = s.Inherit(th.ErrorMark)43 case sp.Invalid:44 s = s.Inherit(th.Invalid)45 }46 return theme.Drawable(s)47}4849// spillLine says where the active cell's value comes from when an array50// formula spilled it, or where the active cell's array goes: "Spilled51// from B2", "Spills into B2:C9".52func (m *Model) spillLine() string {53 if anchor, ok := m.sheet.SpillAnchor(m.cur); ok {54 return m.th.Muted.Render("Spilled from ") + m.th.Key.Render(anchor.String()) +55 m.th.Muted.Render("; edit the formula there")56 }57 if area, ok := m.sheet.SpillArea(m.cur); ok {58 return m.th.Muted.Render("Spills into ") + m.th.Key.Render(area.String())59 }60 return ""61}