2020-05-26 15:51:08 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-05-26 16:36:14 +00:00
|
|
|
"strings"
|
2020-05-26 15:51:08 +00:00
|
|
|
|
2020-05-26 17:42:25 +00:00
|
|
|
"github.com/charmbracelet/bubbles/textinput"
|
2020-05-26 15:51:08 +00:00
|
|
|
"github.com/charmbracelet/charm/ui/common"
|
2020-07-15 00:25:51 +00:00
|
|
|
rw "github.com/mattn/go-runewidth"
|
2020-05-26 15:51:08 +00:00
|
|
|
te "github.com/muesli/termenv"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-08-25 13:56:17 +00:00
|
|
|
newsPrefix = "News: "
|
|
|
|
verticalLine = "│"
|
|
|
|
noMemoTitle = "No Memo"
|
|
|
|
fileListingStashIcon = "• "
|
2020-05-26 15:51:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-07-15 16:07:15 +00:00
|
|
|
greenFg = te.Style{}.Foreground(common.NewColorPair("#04B575", "#04B575").Color()).Styled
|
|
|
|
fuchsiaFg = te.Style{}.Foreground(common.Fuschia.Color()).Styled
|
|
|
|
dullFuchsiaFg = te.Style{}.Foreground(common.NewColorPair("#AD58B4", "#F793FF").Color()).Styled
|
|
|
|
yellowFg = te.Style{}.Foreground(common.YellowGreen.Color()).Styled // renders light green on light backgrounds
|
|
|
|
dullYellowFg = te.Style{}.Foreground(common.NewColorPair("#9BA92F", "#6BCB94").Color()).Styled // renders light green on light backgrounds
|
|
|
|
subtleIndigoFg = te.Style{}.Foreground(common.NewColorPair("#514DC1", "#7D79F6").Color()).Styled
|
|
|
|
redFg = te.Style{}.Foreground(common.Red.Color()).Styled
|
|
|
|
faintRedFg = te.Style{}.Foreground(common.FaintRed.Color()).Styled
|
|
|
|
warmGrayFg = te.Style{}.Foreground(common.NewColorPair("#979797", "#847A85").Color()).Styled
|
2020-05-26 15:51:08 +00:00
|
|
|
)
|
|
|
|
|
2020-05-26 19:10:45 +00:00
|
|
|
func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) {
|
2020-08-25 17:32:49 +00:00
|
|
|
var (
|
|
|
|
truncateTo = m.terminalWidth - stashViewHorizontalPadding*2
|
|
|
|
gutter string
|
|
|
|
title = md.Note
|
|
|
|
date = relativeTime(md.CreatedAt)
|
|
|
|
icon = ""
|
|
|
|
)
|
2020-05-26 15:51:08 +00:00
|
|
|
|
2020-07-15 00:25:51 +00:00
|
|
|
switch md.markdownType {
|
|
|
|
case newsMarkdown:
|
2020-05-26 15:51:08 +00:00
|
|
|
if title == "" {
|
|
|
|
title = "News"
|
|
|
|
} else {
|
2020-07-15 00:25:51 +00:00
|
|
|
title = newsPrefix + truncate(title, truncateTo-rw.StringWidth(newsPrefix))
|
2020-05-26 15:51:08 +00:00
|
|
|
}
|
2020-08-24 18:56:23 +00:00
|
|
|
case stashedMarkdown, convertedMarkdown:
|
2020-08-25 13:56:17 +00:00
|
|
|
icon = fileListingStashIcon
|
2020-05-26 15:51:08 +00:00
|
|
|
if title == "" {
|
|
|
|
title = noMemoTitle
|
|
|
|
}
|
2020-07-15 00:25:51 +00:00
|
|
|
title = truncate(title, truncateTo-rw.StringWidth(icon))
|
|
|
|
default:
|
2020-05-26 15:51:08 +00:00
|
|
|
title = truncate(title, truncateTo)
|
|
|
|
}
|
|
|
|
|
|
|
|
if index == m.index {
|
|
|
|
switch m.state {
|
|
|
|
case stashStatePromptDelete:
|
|
|
|
// Deleting
|
2020-07-15 16:07:15 +00:00
|
|
|
gutter = faintRedFg(verticalLine)
|
|
|
|
icon = faintRedFg(icon)
|
|
|
|
title = redFg(title)
|
|
|
|
date = faintRedFg(date)
|
2020-05-26 15:51:08 +00:00
|
|
|
case stashStateSettingNote:
|
|
|
|
// Setting note
|
2020-07-15 16:07:15 +00:00
|
|
|
gutter = dullYellowFg(verticalLine)
|
2020-07-15 00:25:51 +00:00
|
|
|
icon = ""
|
2020-05-26 15:51:08 +00:00
|
|
|
title = textinput.View(m.noteInput)
|
2020-07-15 16:07:15 +00:00
|
|
|
date = dullYellowFg(date)
|
2020-05-26 15:51:08 +00:00
|
|
|
default:
|
|
|
|
// Selected
|
2020-07-15 16:07:15 +00:00
|
|
|
gutter = dullFuchsiaFg(verticalLine)
|
|
|
|
icon = dullFuchsiaFg(icon)
|
|
|
|
title = fuchsiaFg(title)
|
|
|
|
date = dullFuchsiaFg(date)
|
2020-05-26 15:51:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Normal
|
|
|
|
if md.markdownType == newsMarkdown {
|
|
|
|
gutter = " "
|
|
|
|
title = te.String(title).Foreground(common.Indigo.Color()).String()
|
2020-07-15 16:07:15 +00:00
|
|
|
date = subtleIndigoFg(date)
|
2020-05-26 15:51:08 +00:00
|
|
|
} else {
|
2020-07-15 16:07:15 +00:00
|
|
|
icon = greenFg(icon)
|
2020-05-26 15:51:08 +00:00
|
|
|
if title == noMemoTitle {
|
2020-07-15 16:07:15 +00:00
|
|
|
title = warmGrayFg(title)
|
2020-05-26 15:51:08 +00:00
|
|
|
}
|
|
|
|
gutter = " "
|
2020-07-15 16:07:15 +00:00
|
|
|
date = warmGrayFg(date)
|
2020-05-26 15:51:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:25:51 +00:00
|
|
|
fmt.Fprintf(b, "%s %s%s\n", gutter, icon, title)
|
2020-05-26 16:36:14 +00:00
|
|
|
fmt.Fprintf(b, "%s %s", gutter, date)
|
2020-05-26 15:51:08 +00:00
|
|
|
}
|