Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bin/
slack-term
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ in your `config` file.
| command | `/` | search mode |
| command | `k` | move channel cursor up |
| command | `j` | move channel cursor down |
| command | `K` | move 30 channel cursor up |
| command | `J` | move 30 channel cursor down|
| command | `g` | move channel cursor top |
| command | `G` | move channel cursor bottom |
| command | `K` | thread up |
| command | `J` | thread down |
| command | `l` | thread up |
| command | `h` | thread down |
| command | `G` | move channel cursor bottom |
| command | `pg-up` | scroll chat pane up |
| command | `ctrl-b` | scroll chat pane up |
Expand Down
27 changes: 26 additions & 1 deletion components/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
IconGroup = "☰"
IconIM = "●"
IconMpIM = "☰"
IconMuted = "x"
IconNotification = "*"

PresenceAway = "away"
Expand All @@ -24,6 +25,7 @@ const (
ChannelTypeGroup = "group"
ChannelTypeIM = "im"
ChannelTypeMpIM = "mpim"
ChannelTypeMuted = "mute"
)

type ChannelItem struct {
Expand All @@ -34,6 +36,7 @@ type ChannelItem struct {
UserID string
Presence string
Notification bool
Muted bool

StylePrefix string
StyleIcon string
Expand All @@ -59,6 +62,8 @@ func (c ChannelItem) ToString() string {
icon = IconGroup
case ChannelTypeMpIM:
icon = IconMpIM
case ChannelTypeMuted:
icon = IconMuted
case ChannelTypeIM:
switch c.Presence {
case PresenceActive:
Expand Down Expand Up @@ -248,6 +253,16 @@ func (c *Channels) MoveCursorUp() {
}
}

// MoveCursorUpFast will decrease the SelectedChannel by 10
func (c *Channels) MoveCursorUpFast() {
j := 30
if c.SelectedChannel > j {
c.GotoPosition(c.SelectedChannel - j)
} else {
c.GotoPosition(0)
}
}

// MoveCursorDown will increase the SelectedChannel by 1
func (c *Channels) MoveCursorDown() {
if c.SelectedChannel < len(c.ChannelItems)-1 {
Expand All @@ -256,6 +271,16 @@ func (c *Channels) MoveCursorDown() {
}
}

// MoveCursorDownFast will increase the SelectedChannel by 10
func (c *Channels) MoveCursorDownFast() {
j := 30
if c.SelectedChannel < len(c.ChannelItems)-j {
c.GotoPosition(c.SelectedChannel + j)
} else {
c.GotoPosition(len(c.ChannelItems) - 1)
}
}

// MoveCursorTop will move the cursor to the top of the channels
func (c *Channels) MoveCursorTop() {
c.SetSelectedChannel(0)
Expand Down Expand Up @@ -387,7 +412,7 @@ func (c *Channels) SearchPrev() {
// Jump to the first channel with a notification
func (c *Channels) Jump() {
for i, channel := range c.ChannelItems {
if channel.Notification {
if channel.Notification && !channel.Muted {
c.GotoPosition(i)
break
}
Expand Down
8 changes: 5 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ func getDefaultConfig() Config {
"i": "mode-insert",
"/": "mode-search",
"k": "channel-up",
"K": "channel-up-fast",
"j": "channel-down",
"J": "channel-down-fast",
"g": "channel-top",
"G": "channel-bottom",
"K": "thread-up",
"J": "thread-down",
"l": "thread-up",
"h": "thread-down",
"<previous>": "chat-up",
"C-b": "chat-up",
"C-u": "chat-up",
Expand All @@ -122,7 +124,7 @@ func getDefaultConfig() Config {
"N": "channel-search-prev",
"'": "channel-jump",
"q": "quit",
"<f1>": "help",
"?": "help",
},
"insert": {
"<left>": "cursor-left",
Expand Down
10 changes: 8 additions & 2 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ type AppContext struct {

// CreateAppContext creates an application context which can be passed
// and referenced througout the application
func CreateAppContext(flgConfig string, flgToken string, flgDebug bool, version string, usage string) (*AppContext, error) {
func CreateAppContext(
flgConfig string,
flgToken string,
flgDebug bool,
version string,
usage string,
) (*AppContext, error) {
if flgDebug {
go func() {
http.ListenAndServe(":6060", nil)
Expand Down Expand Up @@ -147,7 +153,7 @@ func CreateAppContext(flgConfig string, flgToken string, flgDebug bool, version
return &AppContext{
Version: version,
Usage: usage,
EventQueue: make(chan termbox.Event, 20),
EventQueue: make(chan termbox.Event, 40),
Service: svc,
Body: termui.Body,
View: view,
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ require (
github.com/maruel/panicparse v1.1.1 // indirect
github.com/mattn/go-runewidth v0.0.7
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/nlopes/slack v0.6.0 // indirect
github.com/nsf/termbox-go v0.0.0-20191229070316-58d4fcbce2a7
github.com/pkg/errors v0.9.1 // indirect
github.com/slack-go/slack v0.6.3
github.com/slack-go/slack v0.10.0
github.com/stretchr/testify v1.4.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.4 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+tw
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA=
github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk=
github.com/nsf/termbox-go v0.0.0-20191229070316-58d4fcbce2a7 h1:OkWEy7aQeQTbgdrcGi9bifx+Y6bMM7ae7y42hDFaBvA=
github.com/nsf/termbox-go v0.0.0-20191229070316-58d4fcbce2a7/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
Expand All @@ -36,6 +35,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/slack-go/slack v0.6.3 h1:qU037g8gQ71EuH6S9zYKnvYrEUj0fLFH4HFekFqBoRU=
github.com/slack-go/slack v0.6.3/go.mod h1:HE4RwNe7YpOg/F0vqo5PwXH3Hki31TplTvKRW9dGGaw=
github.com/slack-go/slack v0.10.0 h1:L16Eqg3QZzRKGXIVsFSZdJdygjOphb2FjRUwH6VrFu8=
github.com/slack-go/slack v0.10.0/go.mod h1:wWL//kk0ho+FcQXcBTmEafUI5dz4qz5f4mMk8oIkioQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
48 changes: 44 additions & 4 deletions handlers/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ var actionMap = map[string]func(*context.AppContext){
"mode-search": actionSearchMode,
"clear-input": actionClearInput,
"channel-up": actionMoveCursorUpChannels,
"channel-up-fast": actionMoveCursorUpFastChannels,
"channel-down": actionMoveCursorDownChannels,
"channel-down-fast": actionMoveCursorDownFastChannels,
"channel-top": actionMoveCursorTopChannels,
"channel-bottom": actionMoveCursorBottomChannels,
"channel-search-next": actionSearchNextChannels,
Expand Down Expand Up @@ -81,8 +83,9 @@ func eventHandler(ctx *context.AppContext) {

// Place your debugging statements here
if ctx.Debug {
ctx.View.Debug.Println(
"event received",
ctx.View.Debug.Sprintf(
"event received: channel %d, offset %d, pos %d",
ctx.View.Channels.SelectedChannel, ctx.View.Channels.Offset, ctx.View.Channels.CursorPosition,
)
}
}
Expand Down Expand Up @@ -453,7 +456,24 @@ func actionMoveCursorUpChannels(ctx *context.AppContext) {
ctx.View.Channels.MoveCursorUp()
termui.Render(ctx.View.Channels)

scrollTimer = time.NewTimer(time.Second / 4)
scrollTimer = time.NewTimer(time.Second / 2)
<-scrollTimer.C

// Only actually change channel when the timer expires
actionChangeChannel(ctx)
}()
}

func actionMoveCursorUpFastChannels(ctx *context.AppContext) {
go func() {
if scrollTimer != nil {
scrollTimer.Stop()
}

ctx.View.Channels.MoveCursorUpFast()
termui.Render(ctx.View.Channels)

scrollTimer = time.NewTimer(time.Second / 2)
<-scrollTimer.C

// Only actually change channel when the timer expires
Expand All @@ -473,7 +493,27 @@ func actionMoveCursorDownChannels(ctx *context.AppContext) {
ctx.View.Channels.MoveCursorDown()
termui.Render(ctx.View.Channels)

scrollTimer = time.NewTimer(time.Second / 4)
scrollTimer = time.NewTimer(time.Second / 2)
<-scrollTimer.C

// Only actually change channel when the timer expires
actionChangeChannel(ctx)
}()
}

// actionMoveCursorDownFastChannels will execute the actionChangeChannel
// function. A timer is implemented to support fast scrolling through
// the list without executing the actionChangeChannel event
func actionMoveCursorDownFastChannels(ctx *context.AppContext) {
go func() {
if scrollTimer != nil {
scrollTimer.Stop()
}

ctx.View.Channels.MoveCursorDownFast()
termui.Render(ctx.View.Channels)

scrollTimer = time.NewTimer(time.Second / 2)
<-scrollTimer.C

// Only actually change channel when the timer expires
Expand Down
Loading