Add timestamps_before_author field to configuration file (#303)

If the `timestamps_before_author` field in the configuration file is set to `true` (defaults to `false`), the timestamps are drawn before the username of the author.
This commit is contained in:
jumps are op 2023-06-30 19:24:01 +03:00 • committed by GitHub
parent 1f1a8970dd
commit c8a9c6ecdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View file

@ -83,14 +83,20 @@ func (mt *MessagesText) createMessage(m discord.Message) {
}
func (mt *MessagesText) createHeader(w io.Writer, m discord.Message, isReply bool) {
time := m.Timestamp.Format(time.Kitchen)
if config.Current.Timestamps && config.Current.TimestampsBeforeAuthor {
fmt.Fprintf(w, "[::d]%7s[::-] ", time)
}
if isReply {
fmt.Fprintf(mt, "[::d]%s", config.Current.Theme.MessagesText.ReplyIndicator)
}
fmt.Fprintf(w, "[%s]%s[-] ", config.Current.Theme.MessagesText.AuthorColor, m.Author.Username)
fmt.Fprintf(w, "[%s]%s[-:-:-] ", config.Current.Theme.MessagesText.AuthorColor, m.Author.Username)
if config.Current.Timestamps {
fmt.Fprintf(w, "[::d]%s[::-] ", m.Timestamp.Format(time.Kitchen))
if config.Current.Timestamps && !config.Current.TimestampsBeforeAuthor {
fmt.Fprintf(w, "[::d]%s[::-] ", time)
}
}

View file

@ -16,6 +16,8 @@ type Config struct {
Mouse bool `yaml:"mouse"`
// MessagesLimit is the number of messages to fetch when a text-based channel is selected.
MessagesLimit uint `yaml:"messages_limit"`
// TimestampsBeforeAuthor indicates whether to draw the timestamp before or after the author.
TimestampsBeforeAuthor bool `yaml:"timestamps_before_author"`
// Timestamps indicates whether to draw the timestamp in front of the message or not.
Timestamps bool `yaml:"timestamps"`
// Editor is the program to open when the `LaunchEditor` key is pressed. If the value of the field is "default", the `$EDITOR` environment variable is used instead.
@ -27,10 +29,11 @@ type Config struct {
func defConfig() Config {
return Config{
Mouse: true,
Timestamps: false,
MessagesLimit: 50,
Editor: "default",
Mouse: true,
TimestampsBeforeAuthor: false,
Timestamps: false,
MessagesLimit: 50,
Editor: "default",
Keys: defKeys(),
Theme: defTheme(),