瀏覽代碼

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.
jumps are op 2 年之前
父節點
當前提交
c8a9c6ecdd
共有 2 個文件被更改,包括 16 次插入7 次删除
  1. 9 3
      cmd/run/messages_text.go
  2. 7 4
      config/config.go

+ 9 - 3
cmd/run/messages_text.go

@@ -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)
 	}
 }
 

+ 7 - 4
config/config.go

@@ -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(),