index: add this-week-time-format
Also allow specific time format for messages received within the last 7 days. Signed-off-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
02e7d8aca8
commit
84146e23b3
6 changed files with 36 additions and 8 deletions
|
@ -22,6 +22,13 @@ timestamp-format=2006-01-02 03:04 PM
|
||||||
# Default: ""
|
# Default: ""
|
||||||
this-day-time-format=
|
this-day-time-format=
|
||||||
|
|
||||||
|
#
|
||||||
|
# Index-only time format for messages that were received/sent within the last
|
||||||
|
# 7 days. If this is not specified, timestamp-format is used instead.
|
||||||
|
#
|
||||||
|
# Default: ""
|
||||||
|
this-week-time-format=
|
||||||
|
|
||||||
#
|
#
|
||||||
# Index-only time format for messages that were received/sent this year.
|
# Index-only time format for messages that were received/sent this year.
|
||||||
# If this is not specified, timestamp-format is used instead.
|
# If this is not specified, timestamp-format is used instead.
|
||||||
|
|
|
@ -30,6 +30,7 @@ type UIConfig struct {
|
||||||
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"`
|
||||||
ThisYearTimeFormat string `ini:"this-year-time-format"`
|
ThisYearTimeFormat string `ini:"this-year-time-format"`
|
||||||
ShowHeaders []string `delim:","`
|
ShowHeaders []string `delim:","`
|
||||||
RenderAccountTabs string `ini:"render-account-tabs"`
|
RenderAccountTabs string `ini:"render-account-tabs"`
|
||||||
|
@ -496,6 +497,7 @@ func LoadConfigFromFile(root *string, sharedir string) (*AercConfig, error) {
|
||||||
IndexFormat: "%D %-17.17n %s",
|
IndexFormat: "%D %-17.17n %s",
|
||||||
TimestampFormat: "2006-01-02 03:04 PM",
|
TimestampFormat: "2006-01-02 03:04 PM",
|
||||||
ThisDayTimeFormat: "",
|
ThisDayTimeFormat: "",
|
||||||
|
ThisWeekTimeFormat: "",
|
||||||
ThisYearTimeFormat: "",
|
ThisYearTimeFormat: "",
|
||||||
ShowHeaders: []string{
|
ShowHeaders: []string{
|
||||||
"From", "To", "Cc", "Bcc", "Subject", "Date",
|
"From", "To", "Cc", "Bcc", "Subject", "Date",
|
||||||
|
|
|
@ -39,6 +39,7 @@ func (trig *TriggersConfig) ExecNewEmail(account *AccountConfig,
|
||||||
formatstr, args, err := format.ParseMessageFormat(
|
formatstr, args, err := format.ParseMessageFormat(
|
||||||
part, conf.Ui.TimestampFormat,
|
part, conf.Ui.TimestampFormat,
|
||||||
conf.Ui.ThisDayTimeFormat,
|
conf.Ui.ThisDayTimeFormat,
|
||||||
|
conf.Ui.ThisWeekTimeFormat,
|
||||||
conf.Ui.ThisYearTimeFormat,
|
conf.Ui.ThisYearTimeFormat,
|
||||||
format.Ctx{
|
format.Ctx{
|
||||||
FromAddress: account.From,
|
FromAddress: account.From,
|
||||||
|
|
|
@ -93,6 +93,13 @@ These options are configured in the *[ui]* section of aerc.conf.
|
||||||
|
|
||||||
Default: ""
|
Default: ""
|
||||||
|
|
||||||
|
*this-week-time-format*
|
||||||
|
Index-only time format for messages that were received/sent within the
|
||||||
|
last 7 days. If this is not specified, *timestamp-format* is used
|
||||||
|
instead.
|
||||||
|
|
||||||
|
Default: ""
|
||||||
|
|
||||||
*this-year-time-format*
|
*this-year-time-format*
|
||||||
Index-only time format for messages that were received/sent this year.
|
Index-only time format for messages that were received/sent this year.
|
||||||
If this is not specified, *timestamp-format* is used instead.
|
If this is not specified, *timestamp-format* is used instead.
|
||||||
|
|
|
@ -48,7 +48,8 @@ type Ctx struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
|
func ParseMessageFormat(format string, timeFmt string, thisDayTimeFmt string,
|
||||||
thisYearTimeFmt string, ctx Ctx) (string, []interface{}, error) {
|
thisWeekTimeFmt string, thisYearTimeFmt string, ctx Ctx) (
|
||||||
|
string, []interface{}, error) {
|
||||||
retval := make([]byte, 0, len(format))
|
retval := make([]byte, 0, len(format))
|
||||||
var args []interface{}
|
var args []interface{}
|
||||||
|
|
||||||
|
@ -141,7 +142,8 @@ 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, thisYearTimeFmt))
|
timeFmt, thisDayTimeFmt,
|
||||||
|
thisWeekTimeFmt, thisYearTimeFmt))
|
||||||
case 'D':
|
case 'D':
|
||||||
date := envelope.Date
|
date := envelope.Date
|
||||||
if date.IsZero() {
|
if date.IsZero() {
|
||||||
|
@ -150,7 +152,8 @@ 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, thisYearTimeFmt))
|
timeFmt, thisDayTimeFmt,
|
||||||
|
thisWeekTimeFmt, thisYearTimeFmt))
|
||||||
case 'f':
|
case 'f':
|
||||||
if len(envelope.From) == 0 {
|
if len(envelope.From) == 0 {
|
||||||
return "", nil,
|
return "", nil,
|
||||||
|
@ -333,16 +336,22 @@ handle_end_error:
|
||||||
}
|
}
|
||||||
|
|
||||||
func dummyIfZeroDate(date time.Time, format string, todayFormat string,
|
func dummyIfZeroDate(date time.Time, format string, todayFormat string,
|
||||||
thisYearFormat string) string {
|
thisWeekFormat string, thisYearFormat string) string {
|
||||||
if date.IsZero() {
|
if date.IsZero() {
|
||||||
return strings.Repeat("?", len(format))
|
return strings.Repeat("?", len(format))
|
||||||
}
|
}
|
||||||
year, month, day := date.Date()
|
year := date.Year()
|
||||||
thisYear, thisMonth, thisDay := time.Now().Date()
|
day := date.YearDay()
|
||||||
|
now := time.Now()
|
||||||
|
thisYear := now.Year()
|
||||||
|
thisDay := now.YearDay()
|
||||||
if year == thisYear {
|
if year == thisYear {
|
||||||
if month == thisMonth && day == thisDay && todayFormat != "" {
|
if day == thisDay && todayFormat != "" {
|
||||||
return date.Format(todayFormat)
|
return date.Format(todayFormat)
|
||||||
}
|
}
|
||||||
|
if day > thisDay-7 && thisWeekFormat != "" {
|
||||||
|
return date.Format(thisWeekFormat)
|
||||||
|
}
|
||||||
if thisYearFormat != "" {
|
if thisYearFormat != "" {
|
||||||
return date.Format(thisYearFormat)
|
return date.Format(thisYearFormat)
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,9 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
|
||||||
ctx.Fill(0, row, ctx.Width(), 1, ' ', style)
|
ctx.Fill(0, row, ctx.Width(), 1, ' ', style)
|
||||||
fmtStr, args, err := format.ParseMessageFormat(
|
fmtStr, args, err := format.ParseMessageFormat(
|
||||||
uiConfig.IndexFormat, uiConfig.TimestampFormat,
|
uiConfig.IndexFormat, uiConfig.TimestampFormat,
|
||||||
uiConfig.ThisDayTimeFormat, uiConfig.ThisYearTimeFormat,
|
uiConfig.ThisDayTimeFormat,
|
||||||
|
uiConfig.ThisWeekTimeFormat,
|
||||||
|
uiConfig.ThisYearTimeFormat,
|
||||||
format.Ctx{
|
format.Ctx{
|
||||||
FromAddress: ml.aerc.SelectedAccount().acct.From,
|
FromAddress: ml.aerc.SelectedAccount().acct.From,
|
||||||
AccountName: ml.aerc.SelectedAccount().Name(),
|
AccountName: ml.aerc.SelectedAccount().Name(),
|
||||||
|
|
Loading…
Reference in a new issue