Add optional date/time formatting

Fixes #84
This commit is contained in:
erroneousboat 2018-08-11 13:10:36 +02:00
parent 8af708b00b
commit fd5d8bdf8a
5 changed files with 48 additions and 34 deletions

View File

@ -35,7 +35,7 @@ Setup
1. Get a slack token, click [here](https://api.slack.com/docs/oauth-test-tokens)
2. Create a `.slack-term` file, and place it in your home directory. Below is
an an example file, you can leave out the `OPTIONAL` parts, you are only
an example file, you can leave out the `OPTIONAL` parts, you are only
required to specify a `slack_token`. Remember that your file should be
a valid json file so don't forget to remove the comments.
@ -47,7 +47,7 @@ Setup
"sidebar_width": 1,
// OPTIONAL: turn on desktop notifications for all incoming messages, set
// the value as: "all", and for only mentions and im messages set the
// the value as: "all". For only mentions and im messages set the
// value as: "mention", default is turned off: ""
"notify": "",
@ -112,7 +112,8 @@ Setup
"message": {
"time": "",
"name": "",
"text": ""
"text": "",
"time_format": "15:04"
}
}
}
@ -139,7 +140,7 @@ $ slack-term -config [path-to-config-file]
Default Key Mapping
-------------------
Below are the default key-mapping for `slack-term`, you can change them
Below are the default key-mappings for `slack-term`, you can change them
in your `slack-term.json` file.
| mode | key | action |

View File

@ -19,6 +19,8 @@ type Message struct {
StyleTime string
StyleName string
StyleText string
FormatTime string
}
// Chat is the definition of a Chat component
@ -54,7 +56,11 @@ func (c *Chat) Buffer() termui.Buffer {
if (msg.Time != time.Time{} && msg.Name != "") {
// Time
cells = append(cells, termui.DefaultTxBuilder.Build(
fmt.Sprintf("[[%s]](%s) ", msg.Time.Format("15:04"), msg.StyleTime),
fmt.Sprintf(
"[[%s]](%s) ",
msg.Time.Format(msg.FormatTime),
msg.StyleTime,
),
termui.ColorDefault, termui.ColorDefault)...,
)

View File

@ -124,9 +124,10 @@ func getDefaultConfig() Config {
Text: "",
},
Message: Message{
Time: "",
Name: "",
Text: "",
Time: "",
TimeFormat: "15:04",
Name: "",
Text: "",
},
},
}

View File

@ -16,9 +16,10 @@ type View struct {
}
type Message struct {
Time string `json:"time"`
Name string `json:"name"`
Text string `json:"text"`
Time string `json:"time"`
Name string `json:"name"`
Text string `json:"text"`
TimeFormat string `json:"time_format"`
}
type Channel struct {

View File

@ -453,12 +453,13 @@ func (s *SlackService) CreateMessage(message slack.Message) []components.Message
// Format message
msg := components.Message{
Time: time.Unix(intTime, 0),
Name: name,
Content: parseMessage(s, message.Text),
StyleTime: s.Config.Theme.Message.Time,
StyleName: s.Config.Theme.Message.Name,
StyleText: s.Config.Theme.Message.Text,
Time: time.Unix(intTime, 0),
Name: name,
Content: parseMessage(s, message.Text),
StyleTime: s.Config.Theme.Message.Time,
StyleName: s.Config.Theme.Message.Name,
StyleText: s.Config.Theme.Message.Text,
FormatTime: s.Config.Theme.Message.TimeFormat,
}
msgs = append(msgs, msg)
@ -525,12 +526,13 @@ func (s *SlackService) CreateMessageFromMessageEvent(message *slack.MessageEvent
// Format message
msg := components.Message{
Time: time.Unix(intTime, 0),
Name: name,
Content: parseMessage(s, message.Text),
StyleTime: s.Config.Theme.Message.Time,
StyleName: s.Config.Theme.Message.Name,
StyleText: s.Config.Theme.Message.Text,
Time: time.Unix(intTime, 0),
Name: name,
Content: parseMessage(s, message.Text),
StyleTime: s.Config.Theme.Message.Time,
StyleName: s.Config.Theme.Message.Name,
StyleText: s.Config.Theme.Message.Text,
FormatTime: s.Config.Theme.Message.TimeFormat,
}
msgs = append(msgs, msg)
@ -663,9 +665,10 @@ func (s *SlackService) CreateMessageFromAttachments(atts []slack.Attachment) []c
att.Fields[i].Title,
att.Fields[i].Value,
),
StyleTime: s.Config.Theme.Message.Time,
StyleName: s.Config.Theme.Message.Name,
StyleText: s.Config.Theme.Message.Text,
StyleTime: s.Config.Theme.Message.Time,
StyleName: s.Config.Theme.Message.Name,
StyleText: s.Config.Theme.Message.Text,
FormatTime: s.Config.Theme.Message.TimeFormat,
},
)
}
@ -674,10 +677,11 @@ func (s *SlackService) CreateMessageFromAttachments(atts []slack.Attachment) []c
msgs = append(
msgs,
components.Message{
Content: fmt.Sprintf("%s", att.Text),
StyleTime: s.Config.Theme.Message.Time,
StyleName: s.Config.Theme.Message.Name,
StyleText: s.Config.Theme.Message.Text,
Content: fmt.Sprintf("%s", att.Text),
StyleTime: s.Config.Theme.Message.Time,
StyleName: s.Config.Theme.Message.Name,
StyleText: s.Config.Theme.Message.Text,
FormatTime: s.Config.Theme.Message.TimeFormat,
},
)
}
@ -686,10 +690,11 @@ func (s *SlackService) CreateMessageFromAttachments(atts []slack.Attachment) []c
msgs = append(
msgs,
components.Message{
Content: fmt.Sprintf("%s", att.Title),
StyleTime: s.Config.Theme.Message.Time,
StyleName: s.Config.Theme.Message.Name,
StyleText: s.Config.Theme.Message.Text,
Content: fmt.Sprintf("%s", att.Title),
StyleTime: s.Config.Theme.Message.Time,
StyleName: s.Config.Theme.Message.Name,
StyleText: s.Config.Theme.Message.Text,
FormatTime: s.Config.Theme.Message.TimeFormat,
},
)
}