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

@ -33,44 +33,48 @@ type GeneralConfig struct {
} }
type UIConfig struct { type UIConfig struct {
AutoMarkRead bool `ini:"auto-mark-read"` AutoMarkRead bool `ini:"auto-mark-read"`
IndexFormat string `ini:"index-format"` IndexFormat string `ini:"index-format"`
TimestampFormat string `ini:"timestamp-format"` TimestampFormat string `ini:"timestamp-format"`
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"`
ShowHeaders []string `delim:","` MessageViewTimestampFormat string `ini:"message-view-timestamp-format"`
RenderAccountTabs string `ini:"render-account-tabs"` MessageViewThisDayTimeFormat string `ini:"message-view-this-day-time-format"`
PinnedTabMarker string `ini:"pinned-tab-marker"` MessageViewThisWeekTimeFormat string `ini:"message-view-this-week-time-format"`
SidebarWidth int `ini:"sidebar-width"` MessageViewThisYearTimeFormat string `ini:"message-view-this-year-time-format"`
PreviewHeight int `ini:"preview-height"` ShowHeaders []string `delim:","`
EmptyMessage string `ini:"empty-message"` RenderAccountTabs string `ini:"render-account-tabs"`
EmptyDirlist string `ini:"empty-dirlist"` PinnedTabMarker string `ini:"pinned-tab-marker"`
MouseEnabled bool `ini:"mouse-enabled"` SidebarWidth int `ini:"sidebar-width"`
ThreadingEnabled bool `ini:"threading-enabled"` PreviewHeight int `ini:"preview-height"`
ForceClientThreads bool `ini:"force-client-threads"` EmptyMessage string `ini:"empty-message"`
ClientThreadsDelay time.Duration `ini:"client-threads-delay"` EmptyDirlist string `ini:"empty-dirlist"`
FuzzyComplete bool `ini:"fuzzy-complete"` MouseEnabled bool `ini:"mouse-enabled"`
NewMessageBell bool `ini:"new-message-bell"` ThreadingEnabled bool `ini:"threading-enabled"`
Spinner string `ini:"spinner"` ForceClientThreads bool `ini:"force-client-threads"`
SpinnerDelimiter string `ini:"spinner-delimiter"` ClientThreadsDelay time.Duration `ini:"client-threads-delay"`
IconUnencrypted string `ini:"icon-unencrypted"` FuzzyComplete bool `ini:"fuzzy-complete"`
IconEncrypted string `ini:"icon-encrypted"` NewMessageBell bool `ini:"new-message-bell"`
IconSigned string `ini:"icon-signed"` Spinner string `ini:"spinner"`
IconSignedEncrypted string `ini:"icon-signed-encrypted"` SpinnerDelimiter string `ini:"spinner-delimiter"`
IconUnknown string `ini:"icon-unknown"` IconUnencrypted string `ini:"icon-unencrypted"`
IconInvalid string `ini:"icon-invalid"` IconEncrypted string `ini:"icon-encrypted"`
DirListFormat string `ini:"dirlist-format"` IconSigned string `ini:"icon-signed"`
DirListDelay time.Duration `ini:"dirlist-delay"` IconSignedEncrypted string `ini:"icon-signed-encrypted"`
DirListTree bool `ini:"dirlist-tree"` IconUnknown string `ini:"icon-unknown"`
DirListCollapse int `ini:"dirlist-collapse"` IconInvalid string `ini:"icon-invalid"`
Sort []string `delim:" "` DirListFormat string `ini:"dirlist-format"`
NextMessageOnDelete bool `ini:"next-message-on-delete"` DirListDelay time.Duration `ini:"dirlist-delay"`
CompletionDelay time.Duration `ini:"completion-delay"` DirListTree bool `ini:"dirlist-tree"`
CompletionPopovers bool `ini:"completion-popovers"` DirListCollapse int `ini:"dirlist-collapse"`
StyleSetDirs []string `ini:"stylesets-dirs" delim:":"` Sort []string `delim:" "`
StyleSetName string `ini:"styleset-name"` NextMessageOnDelete bool `ini:"next-message-on-delete"`
style StyleSet CompletionDelay time.Duration `ini:"completion-delay"`
CompletionPopovers bool `ini:"completion-popovers"`
StyleSetDirs []string `ini:"stylesets-dirs" delim:":"`
StyleSetName string `ini:"styleset-name"`
style StyleSet
// customize border appearance // customize border appearance
BorderCharVertical rune `ini:"-"` BorderCharVertical rune `ini:"-"`
BorderCharHorizontal rune `ini:"-"` BorderCharHorizontal rune `ini:"-"`
@ -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)