msgview: add separate date formatting

The ThisDayTimeFormat and friends are missing from the message view
which just uses the message list's default setting. This might not be
desirable since the amount of space available is different. Introduce
separate settings for formatting dates in the message view.

Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Bence Ferdinandy 2022-10-19 13:21:41 +02:00 committed by Robin Jarry
parent 6eed15c579
commit c3bb3aa2a8
4 changed files with 101 additions and 47 deletions

View file

@ -39,6 +39,10 @@ type UIConfig struct {
ThisDayTimeFormat string `ini:"this-day-time-format"` ThisDayTimeFormat string `ini:"this-day-time-format"`
ThisWeekTimeFormat string `ini:"this-week-time-format"` ThisWeekTimeFormat string `ini:"this-week-time-format"`
ThisYearTimeFormat string `ini:"this-year-time-format"` ThisYearTimeFormat string `ini:"this-year-time-format"`
MessageViewTimestampFormat string `ini:"message-view-timestamp-format"`
MessageViewThisDayTimeFormat string `ini:"message-view-this-day-time-format"`
MessageViewThisWeekTimeFormat string `ini:"message-view-this-week-time-format"`
MessageViewThisYearTimeFormat string `ini:"message-view-this-year-time-format"`
ShowHeaders []string `delim:","` ShowHeaders []string `delim:","`
RenderAccountTabs string `ini:"render-account-tabs"` RenderAccountTabs string `ini:"render-account-tabs"`
PinnedTabMarker string `ini:"pinned-tab-marker"` PinnedTabMarker string `ini:"pinned-tab-marker"`
@ -695,6 +699,19 @@ func parseUiConfig(section *ini.Section, config *UIConfig) error {
config.CompletionDelay = dur config.CompletionDelay = dur
} }
if config.MessageViewTimestampFormat == "" {
config.MessageViewTimestampFormat = config.TimestampFormat
}
if config.MessageViewThisDayTimeFormat == "" {
config.MessageViewThisDayTimeFormat = config.TimestampFormat
}
if config.MessageViewThisWeekTimeFormat == "" {
config.MessageViewThisWeekTimeFormat = config.TimestampFormat
}
if config.MessageViewThisDayTimeFormat == "" {
config.MessageViewThisDayTimeFormat = config.TimestampFormat
}
return nil return nil
} }

View file

@ -121,6 +121,29 @@ These options are configured in the *[ui]* section of aerc.conf.
Default: "" Default: ""
*message-view-timestamp-format*
If set, overrides *timestamp-format* for the message view.
Default: ""
*message-view-this-day-time-format*
If set, overrides *timestamp-format* in the message view for messages
that were received/sent today.
Default: ""
*message-view-this-week-time-format*
If set, overrides *timestamp-format* in the message view for messages
that were recieved/sent within the last 7 days.
Default: ""
*message-view-this-year-time-format*
If set, overrides *timestamp-format* in the message view for messages
that were received/sent this year.
Default: ""
*sidebar-width* *sidebar-width*
Width of the sidebar, including the border. Set to zero to disable the Width of the sidebar, including the border. Set to zero to disable the
sidebar. sidebar.

View file

@ -178,7 +178,7 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
} }
retval = append(retval, 's') retval = append(retval, 's')
args = append(args, args = append(args,
dummyIfZeroDate(date.Local(), DummyIfZeroDate(date.Local(),
timeFmt, thisDayTimeFmt, timeFmt, thisDayTimeFmt,
thisWeekTimeFmt, thisYearTimeFmt)) thisWeekTimeFmt, thisYearTimeFmt))
case 'D': case 'D':
@ -188,7 +188,7 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
} }
retval = append(retval, 's') retval = append(retval, 's')
args = append(args, args = append(args,
dummyIfZeroDate(date.Local(), DummyIfZeroDate(date.Local(),
timeFmt, thisDayTimeFmt, timeFmt, thisDayTimeFmt,
thisWeekTimeFmt, thisYearTimeFmt)) thisWeekTimeFmt, thisYearTimeFmt))
case 'f': case 'f':
@ -395,7 +395,7 @@ handle_end_error:
errors.New("reached end of string while parsing message format") errors.New("reached end of string while parsing message format")
} }
func dummyIfZeroDate(date time.Time, format string, todayFormat string, func DummyIfZeroDate(date time.Time, format string, todayFormat string,
thisWeekFormat string, thisYearFormat string, thisWeekFormat string, thisYearFormat string,
) string { ) string {
if date.IsZero() { if date.IsZero() {

View file

@ -52,7 +52,7 @@ func NewMessageViewer(acct *AccountView,
hf := HeaderLayoutFilter{ hf := HeaderLayoutFilter{
layout: HeaderLayout(conf.Viewer.HeaderLayout), layout: HeaderLayout(conf.Viewer.HeaderLayout),
keep: func(msg *models.MessageInfo, header string) bool { keep: func(msg *models.MessageInfo, header string) bool {
return fmtHeader(msg, header, "2") != "" return fmtHeader(msg, header, "2", "3", "4", "5") != ""
}, },
} }
layout := hf.forMessage(msg.MessageInfo()) layout := hf.forMessage(msg.MessageInfo())
@ -61,8 +61,14 @@ func NewMessageViewer(acct *AccountView,
hv := &HeaderView{ hv := &HeaderView{
conf: conf, conf: conf,
Name: header, Name: header,
Value: fmtHeader(msg.MessageInfo(), header, Value: fmtHeader(
acct.UiConfig().TimestampFormat), msg.MessageInfo(),
header,
acct.UiConfig().MessageViewTimestampFormat,
acct.UiConfig().MessageViewThisDayTimeFormat,
acct.UiConfig().MessageViewThisWeekTimeFormat,
acct.UiConfig().MessageViewThisYearTimeFormat,
),
uiConfig: acct.UiConfig(), uiConfig: acct.UiConfig(),
} }
showInfo := false showInfo := false
@ -142,7 +148,9 @@ func NewMessageViewer(acct *AccountView,
return mv return mv
} }
func fmtHeader(msg *models.MessageInfo, header string, timefmt string) string { func fmtHeader(msg *models.MessageInfo, header string,
timefmt string, todayFormat string, thisWeekFormat string, thisYearFormat string,
) string {
if msg == nil || msg.Envelope == nil { if msg == nil || msg.Envelope == nil {
return "error: no envelope for this message" return "error: no envelope for this message"
} }
@ -161,7 +169,13 @@ func fmtHeader(msg *models.MessageInfo, header string, timefmt string) string {
case "Bcc": case "Bcc":
return format.FormatAddresses(msg.Envelope.Bcc) return format.FormatAddresses(msg.Envelope.Bcc)
case "Date": case "Date":
return msg.Envelope.Date.Local().Format(timefmt) return format.DummyIfZeroDate(
msg.Envelope.Date.Local(),
timefmt,
todayFormat,
thisWeekFormat,
thisYearFormat,
)
case "Subject": case "Subject":
return msg.Envelope.Subject return msg.Envelope.Subject
case "Labels": case "Labels":
@ -686,7 +700,7 @@ func (pv *PartViewer) writeMailHeaders() {
} }
// virtual header // virtual header
if len(info.Labels) != 0 { if len(info.Labels) != 0 {
labels := fmtHeader(info, "Labels", "") labels := fmtHeader(info, "Labels", "", "", "", "")
_, err := pv.pagerin.Write([]byte(fmt.Sprintf("Labels: %s\n", labels))) _, err := pv.pagerin.Write([]byte(fmt.Sprintf("Labels: %s\n", labels)))
if err != nil { if err != nil {
logging.Errorf("failed to write to stdin of pager: %v", err) logging.Errorf("failed to write to stdin of pager: %v", err)