summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBence Ferdinandy <bence@ferdinandy.com>2022-10-19 13:21:41 +0200
committerRobin Jarry <robin@jarry.cc>2022-10-19 20:27:58 +0200
commitc3bb3aa2a8908eaeb201a740fb12d70968cc3bac (patch)
tree44cb8ade5dcbd03077b8a461f236b16149a25c9f
parent6eed15c579017099c31d73821e70bc363e0fe7b8 (diff)
downloadaerc-c3bb3aa2a8908eaeb201a740fb12d70968cc3bac.tar.gz
aerc-c3bb3aa2a8908eaeb201a740fb12d70968cc3bac.zip
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>
-rw-r--r--config/config.go93
-rw-r--r--doc/aerc-config.5.scd23
-rw-r--r--lib/format/format.go6
-rw-r--r--widgets/msgviewer.go26
4 files changed, 101 insertions, 47 deletions
diff --git a/config/config.go b/config/config.go
index 0de1780c..8b8d9d21 100644
--- a/config/config.go
+++ b/config/config.go
@@ -33,44 +33,48 @@ type GeneralConfig struct {
}
type UIConfig struct {
- AutoMarkRead bool `ini:"auto-mark-read"`
- IndexFormat string `ini:"index-format"`
- TimestampFormat string `ini:"timestamp-format"`
- ThisDayTimeFormat string `ini:"this-day-time-format"`
- ThisWeekTimeFormat string `ini:"this-week-time-format"`
- ThisYearTimeFormat string `ini:"this-year-time-format"`
- ShowHeaders []string `delim:","`
- RenderAccountTabs string `ini:"render-account-tabs"`
- PinnedTabMarker string `ini:"pinned-tab-marker"`
- SidebarWidth int `ini:"sidebar-width"`
- PreviewHeight int `ini:"preview-height"`
- EmptyMessage string `ini:"empty-message"`
- EmptyDirlist string `ini:"empty-dirlist"`
- MouseEnabled bool `ini:"mouse-enabled"`
- ThreadingEnabled bool `ini:"threading-enabled"`
- ForceClientThreads bool `ini:"force-client-threads"`
- ClientThreadsDelay time.Duration `ini:"client-threads-delay"`
- FuzzyComplete bool `ini:"fuzzy-complete"`
- NewMessageBell bool `ini:"new-message-bell"`
- Spinner string `ini:"spinner"`
- SpinnerDelimiter string `ini:"spinner-delimiter"`
- IconUnencrypted string `ini:"icon-unencrypted"`
- IconEncrypted string `ini:"icon-encrypted"`
- IconSigned string `ini:"icon-signed"`
- IconSignedEncrypted string `ini:"icon-signed-encrypted"`
- IconUnknown string `ini:"icon-unknown"`
- IconInvalid string `ini:"icon-invalid"`
- DirListFormat string `ini:"dirlist-format"`
- DirListDelay time.Duration `ini:"dirlist-delay"`
- DirListTree bool `ini:"dirlist-tree"`
- DirListCollapse int `ini:"dirlist-collapse"`
- Sort []string `delim:" "`
- NextMessageOnDelete bool `ini:"next-message-on-delete"`
- CompletionDelay time.Duration `ini:"completion-delay"`
- CompletionPopovers bool `ini:"completion-popovers"`
- StyleSetDirs []string `ini:"stylesets-dirs" delim:":"`
- StyleSetName string `ini:"styleset-name"`
- style StyleSet
+ AutoMarkRead bool `ini:"auto-mark-read"`
+ IndexFormat string `ini:"index-format"`
+ TimestampFormat string `ini:"timestamp-format"`
+ ThisDayTimeFormat string `ini:"this-day-time-format"`
+ ThisWeekTimeFormat string `ini:"this-week-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:","`
+ RenderAccountTabs string `ini:"render-account-tabs"`
+ PinnedTabMarker string `ini:"pinned-tab-marker"`
+ SidebarWidth int `ini:"sidebar-width"`
+ PreviewHeight int `ini:"preview-height"`
+ EmptyMessage string `ini:"empty-message"`
+ EmptyDirlist string `ini:"empty-dirlist"`
+ MouseEnabled bool `ini:"mouse-enabled"`
+ ThreadingEnabled bool `ini:"threading-enabled"`
+ ForceClientThreads bool `ini:"force-client-threads"`
+ ClientThreadsDelay time.Duration `ini:"client-threads-delay"`
+ FuzzyComplete bool `ini:"fuzzy-complete"`
+ NewMessageBell bool `ini:"new-message-bell"`
+ Spinner string `ini:"spinner"`
+ SpinnerDelimiter string `ini:"spinner-delimiter"`
+ IconUnencrypted string `ini:"icon-unencrypted"`
+ IconEncrypted string `ini:"icon-encrypted"`
+ IconSigned string `ini:"icon-signed"`
+ IconSignedEncrypted string `ini:"icon-signed-encrypted"`
+ IconUnknown string `ini:"icon-unknown"`
+ IconInvalid string `ini:"icon-invalid"`
+ DirListFormat string `ini:"dirlist-format"`
+ DirListDelay time.Duration `ini:"dirlist-delay"`
+ DirListTree bool `ini:"dirlist-tree"`
+ DirListCollapse int `ini:"dirlist-collapse"`
+ Sort []string `delim:" "`
+ NextMessageOnDelete bool `ini:"next-message-on-delete"`
+ 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
BorderCharVertical rune `ini:"-"`
BorderCharHorizontal rune `ini:"-"`
@@ -695,6 +699,19 @@ func parseUiConfig(section *ini.Section, config *UIConfig) error {
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
}
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index a09c5ab8..310721ad 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -121,6 +121,29 @@ These options are configured in the *[ui]* section of aerc.conf.
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*
Width of the sidebar, including the border. Set to zero to disable the
sidebar.
diff --git a/lib/format/format.go b/lib/format/format.go
index 055e2c73..e340c496 100644
--- a/lib/format/format.go
+++ b/lib/format/format.go
@@ -178,7 +178,7 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
}
retval = append(retval, 's')
args = append(args,
- dummyIfZeroDate(date.Local(),
+ DummyIfZeroDate(date.Local(),
timeFmt, thisDayTimeFmt,
thisWeekTimeFmt, thisYearTimeFmt))
case 'D':
@@ -188,7 +188,7 @@ func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
}
retval = append(retval, 's')
args = append(args,
- dummyIfZeroDate(date.Local(),
+ DummyIfZeroDate(date.Local(),
timeFmt, thisDayTimeFmt,
thisWeekTimeFmt, thisYearTimeFmt))
case 'f':
@@ -395,7 +395,7 @@ handle_end_error:
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,
) string {
if date.IsZero() {
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index 7475789d..f8b2816f 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -52,7 +52,7 @@ func NewMessageViewer(acct *AccountView,
hf := HeaderLayoutFilter{
layout: HeaderLayout(conf.Viewer.HeaderLayout),
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())
@@ -61,8 +61,14 @@ func NewMessageViewer(acct *AccountView,
hv := &HeaderView{
conf: conf,
Name: header,
- Value: fmtHeader(msg.MessageInfo(), header,
- acct.UiConfig().TimestampFormat),
+ Value: fmtHeader(
+ msg.MessageInfo(),
+ header,
+ acct.UiConfig().MessageViewTimestampFormat,
+ acct.UiConfig().MessageViewThisDayTimeFormat,
+ acct.UiConfig().MessageViewThisWeekTimeFormat,
+ acct.UiConfig().MessageViewThisYearTimeFormat,
+ ),
uiConfig: acct.UiConfig(),
}
showInfo := false
@@ -142,7 +148,9 @@ func NewMessageViewer(acct *AccountView,
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 {
return "error: no envelope for this message"
}
@@ -161,7 +169,13 @@ func fmtHeader(msg *models.MessageInfo, header string, timefmt string) string {
case "Bcc":
return format.FormatAddresses(msg.Envelope.Bcc)
case "Date":
- return msg.Envelope.Date.Local().Format(timefmt)
+ return format.DummyIfZeroDate(
+ msg.Envelope.Date.Local(),
+ timefmt,
+ todayFormat,
+ thisWeekFormat,
+ thisYearFormat,
+ )
case "Subject":
return msg.Envelope.Subject
case "Labels":
@@ -686,7 +700,7 @@ func (pv *PartViewer) writeMailHeaders() {
}
// virtual header
if len(info.Labels) != 0 {
- labels := fmtHeader(info, "Labels", "")
+ labels := fmtHeader(info, "Labels", "", "", "", "")
_, err := pv.pagerin.Write([]byte(fmt.Sprintf("Labels: %s\n", labels)))
if err != nil {
logging.Errorf("failed to write to stdin of pager: %v", err)