-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e49dde5
commit e8dca42
Showing
4 changed files
with
182 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/gdamore/tcell" | ||
"github.com/mattn/go-mastodon" | ||
"github.com/rivo/tview" | ||
) | ||
|
||
func NewVisibilityOverlay(app *App) *VisibilityOverlay { | ||
v := &VisibilityOverlay{ | ||
app: app, | ||
Flex: tview.NewFlex(), | ||
TextBottom: tview.NewTextView(), | ||
List: tview.NewList(), | ||
} | ||
|
||
v.TextBottom.SetBackgroundColor(app.Config.Style.Background) | ||
v.TextBottom.SetDynamicColors(true) | ||
v.List.SetBackgroundColor(app.Config.Style.Background) | ||
v.List.SetMainTextColor(app.Config.Style.Text) | ||
v.List.SetSelectedBackgroundColor(app.Config.Style.ListSelectedBackground) | ||
v.List.SetSelectedTextColor(app.Config.Style.ListSelectedText) | ||
v.List.ShowSecondaryText(false) | ||
v.List.SetHighlightFullLine(true) | ||
v.Flex.SetDrawFunc(app.Config.ClearContent) | ||
v.TextBottom.SetText(ColorKey(app.Config.Style, "", "Enter", "")) | ||
return v | ||
} | ||
|
||
type VisibilityOverlay struct { | ||
app *App | ||
Flex *tview.Flex | ||
TextBottom *tview.TextView | ||
List *tview.List | ||
Selected int | ||
} | ||
|
||
func (v *VisibilityOverlay) SetVisibilty(s string) { | ||
v.List.Clear() | ||
visibilities := []string{ | ||
mastodon.VisibilityPublic, | ||
mastodon.VisibilityFollowersOnly, | ||
mastodon.VisibilityUnlisted, | ||
mastodon.VisibilityDirectMessage, | ||
} | ||
|
||
selected := 0 | ||
for i, item := range visibilities { | ||
if s == item { | ||
selected = i | ||
} | ||
v.List.AddItem( | ||
VisibilityToText(item), | ||
"", 0, nil) | ||
} | ||
v.List.SetCurrentItem(selected) | ||
v.Selected = selected | ||
} | ||
|
||
func (v *VisibilityOverlay) Show() { | ||
v.List.SetCurrentItem(v.Selected) | ||
} | ||
|
||
func (v *VisibilityOverlay) Prev() { | ||
index := v.List.GetCurrentItem() | ||
if index-1 >= 0 { | ||
v.List.SetCurrentItem(index - 1) | ||
} | ||
} | ||
|
||
func (v *VisibilityOverlay) Next() { | ||
index := v.List.GetCurrentItem() | ||
if index+1 < v.List.GetItemCount() { | ||
v.List.SetCurrentItem(index + 1) | ||
} | ||
} | ||
|
||
func (v *VisibilityOverlay) SetVisibilityIndex() { | ||
index := v.List.GetCurrentItem() | ||
v.Selected = index | ||
} | ||
|
||
func (v *VisibilityOverlay) GetVisibility() string { | ||
visibilities := []string{ | ||
mastodon.VisibilityPublic, | ||
mastodon.VisibilityFollowersOnly, | ||
mastodon.VisibilityUnlisted, | ||
mastodon.VisibilityDirectMessage, | ||
} | ||
return visibilities[v.Selected] | ||
} | ||
|
||
func (v *VisibilityOverlay) InputHandler(event *tcell.EventKey) { | ||
if event.Key() == tcell.KeyRune { | ||
switch event.Rune() { | ||
case 'j', 'J': | ||
v.Next() | ||
case 'k', 'K': | ||
v.Prev() | ||
case 'q', 'Q': | ||
v.app.UI.SetFocus(MessageFocus) | ||
} | ||
} else { | ||
switch event.Key() { | ||
case tcell.KeyEnter: | ||
v.SetVisibilityIndex() | ||
v.app.UI.SetFocus(MessageFocus) | ||
case tcell.KeyUp: | ||
v.Prev() | ||
case tcell.KeyDown: | ||
v.Next() | ||
case tcell.KeyEsc: | ||
v.app.UI.SetFocus(MessageFocus) | ||
} | ||
} | ||
} |