ui

package
v0.0.0-...-823dbf3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2022 License: BSD-2-Clause Imports: 18 Imported by: 0

Documentation

Overview

Copyright 2020 The Mellium Contributors. Use of this source code is governed by the BSD 2-clause license that can be found in the LICENSE file.

Package ui ties together various widgets to create the main Communiqué UI.

Index

Constants

View Source
const UnreadRegion = "unreadMarker"

UnreadRegion is a tview region tag that will draw an unread marker.

Variables

This section is empty.

Functions

This section is empty.

Types

type BookmarkItem

type BookmarkItem struct {
	bookmarks.Channel
	// contains filtered or unexported fields
}

BookmarkItem represents a bookmark in the list.

type Bookmarks

type Bookmarks struct {
	Width int
	// contains filtered or unexported fields
}

Bookmarks is a tview.Primitive that draws a list of bookmarks.

func (Bookmarks) Blur

func (b Bookmarks) Blur()

Blur implements tview.Primitive.

func (Bookmarks) Delete

func (b Bookmarks) Delete(bareJID string)

Delete removes a bookmark from the list.

func (Bookmarks) Draw

func (b Bookmarks) Draw(screen tcell.Screen)

Draw implements tview.Primitive.

func (Bookmarks) Focus

func (b Bookmarks) Focus(delegate func(p tview.Primitive))

Focus implements tview.Primitive.

func (Bookmarks) GetInputCapture

func (b Bookmarks) GetInputCapture() func(event *tcell.EventKey) *tcell.EventKey

GetInputCapture returns the input capture function for the underlying list.

func (Bookmarks) GetItem

func (b Bookmarks) GetItem(j string) (BookmarkItem, bool)

GetItem returns the item for the given JID.

func (Bookmarks) GetRect

func (b Bookmarks) GetRect() (int, int, int, int)

GetRect implements tview.Primitive.

func (Bookmarks) GetSelected

func (b Bookmarks) GetSelected() (BookmarkItem, bool)

GetSelected returns the currently selected bookmark.

func (Bookmarks) HasFocus

func (b Bookmarks) HasFocus() bool

HasFocus implements tview.Primitive.

func (Bookmarks) InputHandler

func (b Bookmarks) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))

InputHandler implements tview.Primitive.

func (Bookmarks) Len

func (b Bookmarks) Len() int

Len returns the length of the list.

func (Bookmarks) MouseHandler

func (b Bookmarks) MouseHandler() func(tview.MouseAction, *tcell.EventMouse, func(tview.Primitive)) (bool, tview.Primitive)

MouseHandler implements tview.Primitive.

func (*Bookmarks) OnChanged

func (b *Bookmarks) OnChanged(f func(int, string, string, rune))

OnChanged sets a callback for when the user navigates to a bookmark.

func (Bookmarks) SetInputCapture

func (b Bookmarks) SetInputCapture(capture func(event *tcell.EventKey) *tcell.EventKey) *tview.Box

SetInputCapture passes calls through to the underlying view(s).

func (Bookmarks) SetRect

func (b Bookmarks) SetRect(x, y, width, height int)

SetRect implements tview.Primitive.

func (Bookmarks) ShowStatus

func (b Bookmarks) ShowStatus(show bool)

ShowStatus shows or hides the status line under bookmarks in the list.

func (Bookmarks) Upsert

func (b Bookmarks) Upsert(bookmark bookmarks.Channel, action func())

Upsert inserts or updates a bookmark.

type Conversation

type Conversation struct {
	JID  jid.JID
	Name string

	Room bool
	// contains filtered or unexported fields
}

Conversation represents an open channel or chat.

func (Conversation) FirstUnread

func (c Conversation) FirstUnread() string

FirstUnread returns the ID of the first unread message.

type ConversationView

type ConversationView struct {
	*tview.Flex
	TextView *tview.TextView
	// contains filtered or unexported fields
}

ConversationView is a wrapper around TextView that adds other functionality important for displaying chats.

func NewConversationView

func NewConversationView(ui *UI) *ConversationView

NewConversationView configures and creates a new chat view.

func (*ConversationView) InputHandler

func (cv *ConversationView) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))

InputHandler returns the handler for this primitive.

func (*ConversationView) ScrollTo

func (cv *ConversationView) ScrollTo(row, column int)

ScrollTo scrolls to the specified row and column (both starting with 0).

func (*ConversationView) ScrollToBeginning

func (cv *ConversationView) ScrollToBeginning()

ScrollToBeginning scrolls to the top left corner of the text if the text view is scrollable.

func (*ConversationView) ScrollToEnd

func (cv *ConversationView) ScrollToEnd()

ScrollToEnd scrolls to the bottom left corner of the text if the text view is scrollable. Adding new rows to the end of the text view will cause it to scroll with the new data.

func (*ConversationView) ScrollToHighlight

func (cv *ConversationView) ScrollToHighlight()

ScrollToHighlight will cause the visible area to be scrolled so that the highlighted regions appear in the visible area of the text view. This repositioning happens the next time the text view is drawn. It happens only once so you will need to call this function repeatedly to always keep highlighted regions in view.

Nothing happens if there are no highlighted regions or if the text view is not scrollable.

type Conversations

type Conversations struct {
	Width int
	// contains filtered or unexported fields
}

Conversations is a tview.Primitive that draws the recent/open conversations. This pane includes a mix of joined channels and recently updated 1:1 chats. It does not necessarily contain all bookmarked channels or all chats from the roster (in fact, it may include channels or chats that are not bookmarked or not in the roster).

func (Conversations) Away

func (c Conversations) Away()

Away sets the state of the roster to show the user as away.

func (Conversations) Blur

func (c Conversations) Blur()

Blur implements tview.Primitive foc Conversations.

func (Conversations) Busy

func (c Conversations) Busy()

Busy sets the state of the roster to show the user as busy.

func (Conversations) Delete

func (c Conversations) Delete(bareJID string)

Delete removes an item from the list.

func (Conversations) Draw

func (c Conversations) Draw(screen tcell.Screen)

Draw implements tview.Primitive foc Conversations.

func (Conversations) Focus

func (c Conversations) Focus(delegate func(p tview.Primitive))

Focus implements tview.Primitive foc Conversations.

func (Conversations) GetInputCapture

func (c Conversations) GetInputCapture() func(event *tcell.EventKey) *tcell.EventKey

GetInputCapture returns the input capture function for the underlying list.

func (Conversations) GetItem

func (c Conversations) GetItem(j string) (Conversation, bool)

GetItem returns the item for the given JID.

func (Conversations) GetRect

func (c Conversations) GetRect() (int, int, int, int)

GetRect implements tview.Primitive foc Conversations.

func (Conversations) GetSelected

func (c Conversations) GetSelected() (Conversation, bool)

GetSelected returns the currently selected roster item.

func (Conversations) HasFocus

func (c Conversations) HasFocus() bool

HasFocus implements tview.Primitive foc Conversations.

func (Conversations) InputHandler

func (c Conversations) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))

InputHandler implements tview.Primitive foc Conversations.

func (*Conversations) Len

func (c *Conversations) Len() int

Len returns the length of the roster.

func (Conversations) MarkRead

func (c Conversations) MarkRead(j string)

MarkRead sets the given jid back to the normal font.

func (Conversations) MarkUnread

func (c Conversations) MarkUnread(j, msgID string) bool

MarkUnread sets the given jid to bold and sets the first message seen after the unread marker (unless the unread marker is already set).

func (Conversations) MouseHandler

func (c Conversations) MouseHandler() func(tview.MouseAction, *tcell.EventMouse, func(tview.Primitive)) (bool, tview.Primitive)

MouseHandler implements tview.Primitive foc Conversations.

func (Conversations) Offline

func (c Conversations) Offline()

Offline sets the state of the roster to show the user as offline.

func (*Conversations) OnChanged

func (c *Conversations) OnChanged(f func(int, string, string, rune))

OnChanged sets a callback for when the user navigates to a roster item.

func (Conversations) Online

func (c Conversations) Online()

Online sets the state of the roster to show the user as online.

func (Conversations) SetInputCapture

func (c Conversations) SetInputCapture(capture func(event *tcell.EventKey) *tcell.EventKey) *tview.Box

SetInputCapture passes calls through to the underlying view(s).

func (Conversations) SetRect

func (c Conversations) SetRect(x, y, width, height int)

SetRect implements tview.Primitive foc Conversations.

func (*Conversations) ShowStatus

func (c *Conversations) ShowStatus(show bool)

ShowStatus shows or hides the status line under contacts in the roster.

func (Conversations) Unread

func (c Conversations) Unread(j string) bool

Unread returns whether the roster item is currently marked as having unread messages. If no such roster item exists, it returns false.

func (Conversations) Upsert

func (c Conversations) Upsert(item Conversation, action func(Conversation)) int

Upsert inserts or updates an item in the list.

func (Conversations) UpsertPresence

func (c Conversations) UpsertPresence(j jid.JID, status string) bool

UpsertPresence updates an existing roster item with a newly seen resource or presence change. If the item is not in the roster, false is returned.

type Modal struct {
	*tview.Box
	// contains filtered or unexported fields
}

Modal is a centered message window used to inform the user or prompt them for an immediate decision. It needs to have at least one button (added via AddButtons()) or it will never disappear.

See https://github.com/rivo/tview/wiki/Modal for an example.

func NewModal

func NewModal() *Modal

NewModal returns a new modal message window.

func (*Modal) AddButtons

func (m *Modal) AddButtons(labels []string) *Modal

AddButtons adds buttons to the window. There must be at least one button and a "done" handler so the window can be closed again.

func (*Modal) AddInputField

func (m *Modal) AddInputField(label, value string, fieldWidth int, accept func(textToCheck string, lastChar rune) bool, changed func(text string))

AddInputField adds an input field to the form.

func (*Modal) ClearButtons

func (m *Modal) ClearButtons() *Modal

ClearButtons removes all buttons from the window.

func (*Modal) Draw

func (m *Modal) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*Modal) Focus

func (m *Modal) Focus(delegate func(p tview.Primitive))

Focus is called when this primitive receives focus.

func (*Modal) Form

func (m *Modal) Form() *tview.Form

Form returns the internal form used to add buttons and other elements to the modal.

func (*Modal) HasFocus

func (m *Modal) HasFocus() bool

HasFocus returns whether or not this primitive has focus.

func (*Modal) InputHandler

func (m *Modal) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))

InputHandler returns the handler for this primitive.

func (*Modal) MouseHandler

func (m *Modal) MouseHandler() func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive)

MouseHandler returns the mouse handler for this primitive.

func (*Modal) SetBackgroundColor

func (m *Modal) SetBackgroundColor(color tcell.Color) *Modal

SetBackgroundColor sets the color of the modal frame background.

func (*Modal) SetButtonBackgroundColor

func (m *Modal) SetButtonBackgroundColor(color tcell.Color) *Modal

SetButtonBackgroundColor sets the background color of the buttons.

func (*Modal) SetButtonTextColor

func (m *Modal) SetButtonTextColor(color tcell.Color) *Modal

SetButtonTextColor sets the color of the button texts.

func (*Modal) SetDoneFunc

func (m *Modal) SetDoneFunc(handler func(buttonIndex int, buttonLabel string)) *Modal

SetDoneFunc sets a handler which is called when one of the buttons was pressed. It receives the index of the button as well as its label text. The handler is also called when the user presses the Escape key. The index will then be negative and the label text an emptry string.

func (*Modal) SetFocus

func (m *Modal) SetFocus(index int) *Modal

SetFocus shifts the focus to the button with the given index.

func (*Modal) SetText

func (m *Modal) SetText(text string) *Modal

SetText sets the message text of the window. The text may contain line breaks. Note that words are wrapped, too, based on the final size of the window.

func (*Modal) SetTextColor

func (m *Modal) SetTextColor(color tcell.Color) *Modal

SetTextColor sets the color of the message text.

type Option

type Option func(*UI)

Option can be used to configure a new roster widget.

func Addr

func Addr(addr string) Option

Addr returns an option that sets the users address anywhere that it is displayed in the UI.

func Debug

func Debug(l *log.Logger) Option

Debug sets the verbose debug logger that will be used by the UI.

func Handle

func Handle(handler func(event interface{})) Option

Handle returns an option that configures an event handler which will be called when the user performs certain actions in the UI. Only one event handler can be registered, and subsequent calls to Handle will replace the handler. The function will be called synchronously on the UI goroutine, so don't do any intensive work (or, if you must, launch a new goroutine).

func InputCapture

func InputCapture(capture func(event *tcell.EventKey) *tcell.EventKey) Option

InputCapture returns an option that overrides the default input handler for the application.

func RosterWidth

func RosterWidth(width int) Option

RosterWidth returns an option that sets the width of the roster. It accepts a minimum of 2 and a max of 50 the default is 25.

func ShowStatus

func ShowStatus(show bool) Option

ShowStatus returns an option that shows or hides the status line under contacts in the roster.

type Roster

type Roster struct {
	Width int
	// contains filtered or unexported fields
}

Roster is a tview.Primitive that draws a roster pane.

func (Roster) Blur

func (r Roster) Blur()

Blur implements tview.Primitive for Roster.

func (Roster) Delete

func (r Roster) Delete(bareJID string)

Delete removes an item from the roster.

func (Roster) Draw

func (r Roster) Draw(screen tcell.Screen)

Draw implements tview.Primitive for Roster.

func (Roster) Focus

func (r Roster) Focus(delegate func(p tview.Primitive))

Focus implements tview.Primitive for Roster.

func (Roster) GetInputCapture

func (r Roster) GetInputCapture() func(event *tcell.EventKey) *tcell.EventKey

GetInputCapture returns the input capture function for the underlying list.

func (Roster) GetItem

func (r Roster) GetItem(j string) (RosterItem, bool)

GetItem returns the item for the given JID.

func (Roster) GetRect

func (r Roster) GetRect() (int, int, int, int)

GetRect implements tview.Primitive for Roster.

func (Roster) GetSelected

func (r Roster) GetSelected() (RosterItem, bool)

GetSelected returns the currently selected roster item.

func (Roster) HasFocus

func (r Roster) HasFocus() bool

HasFocus implements tview.Primitive for Roster.

func (Roster) InputHandler

func (r Roster) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))

InputHandler implements tview.Primitive for Roster.

func (*Roster) Len

func (r *Roster) Len() int

Len returns the length of the roster.

func (Roster) MarkRead

func (r Roster) MarkRead(j string)

MarkRead sets the given jid back to the normal font.

func (Roster) MarkUnread

func (r Roster) MarkUnread(j, msgID string) bool

MarkUnread sets the given jid to bold and sets the first message seen after the unread marker (unless the unread marker is already set).

func (Roster) MouseHandler

func (r Roster) MouseHandler() func(tview.MouseAction, *tcell.EventMouse, func(tview.Primitive)) (bool, tview.Primitive)

MouseHandler implements tview.Primitive for Roster.

func (*Roster) OnChanged

func (r *Roster) OnChanged(f func(int, string, string, rune))

OnChanged sets a callback for when the user navigates to a roster item.

func (Roster) SetInputCapture

func (r Roster) SetInputCapture(capture func(event *tcell.EventKey) *tcell.EventKey) *tview.Box

SetInputCapture passes calls through to the underlying view(s).

func (Roster) SetRect

func (r Roster) SetRect(x, y, width, height int)

SetRect implements tview.Primitive for Roster.

func (*Roster) ShowStatus

func (r *Roster) ShowStatus(show bool)

ShowStatus shows or hides the status line under contacts in the roster.

func (Roster) Unread

func (r Roster) Unread(j string) bool

Unread returns whether the roster item is currently marked as having unread messages. If no such roster item exists, it returns false.

func (Roster) Upsert

func (r Roster) Upsert(item RosterItem, action func())

Upsert inserts or updates an item in the roster.

func (Roster) UpsertPresence

func (r Roster) UpsertPresence(j jid.JID, status string) bool

UpsertPresence updates an existing roster item with a newly seen resource or presence change. If the item is not in the roster, false is returned.

type RosterItem

type RosterItem struct {
	roster.Item
	// contains filtered or unexported fields
}

RosterItem represents a contact in the roster.

func (RosterItem) FirstUnread

func (r RosterItem) FirstUnread() string

FirstUnread returns the ID of the first unread message.

type SearchDir

type SearchDir bool

SearchDir the direction of a search.

const (
	SearchUp   SearchDir = true
	SearchDown SearchDir = false
)

Valid search directions.

type Sidebar struct {
	*tview.Flex
	Width int
	// contains filtered or unexported fields
}

Sidebar is a tview.Primitive that draws a sidebar containing multiple lists that can be toggled between using a drop down.

func (Sidebar) Away

func (s Sidebar) Away()

Away sets the state of the roster to show the user as away.

func (Sidebar) Busy

func (s Sidebar) Busy()

Busy sets the state of the roster to show the user as busy.

func (*Sidebar) GetSelected

func (s *Sidebar) GetSelected() (interface{}, bool)

GetSelected returns the currently selected roster item, bookmark, or conversation.

func (*Sidebar) InputHandler

func (s *Sidebar) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))

InputHandler implements tview.Primitive for Roster.

func (Sidebar) Offline

func (s Sidebar) Offline()

Offline sets the state of the roster to show the user as offline.

func (Sidebar) Online

func (s Sidebar) Online()

Online sets the state of the roster to show the user as online.

func (*Sidebar) Search

func (s *Sidebar) Search(q string, dir SearchDir) bool

Search looks forward in the roster trying to find items that match s. It is case insensitive and looks in the primary or secondary texts. If a match is found after the current selection, we jump to the match, wrapping at the end of the list.

func (*Sidebar) SetWidth

func (s *Sidebar) SetWidth(width int)

SetWidth sets the width of the sidebar and re-adjusts the dropdown text width to match.

func (*Sidebar) ShowStatus

func (s *Sidebar) ShowStatus(show bool)

ShowStatus shows or hides the status line under the currently selected list.

func (Sidebar) UpsertPresence

func (s Sidebar) UpsertPresence(j jid.JID, status string) bool

UpsertPresence updates an existing roster item or bookmark with a newly seen resource or presence change. If the item is not in any roster, false is returned.

type UI

type UI struct {
	// contains filtered or unexported fields
}

UI is a widget that combines other widgets to make the main UI.

func New

func New(opts ...Option) *UI

New constructs a new UI.

func (*UI) Away

func (ui *UI) Away(j jid.JID, self bool)

Away sets the state of the roster to show the user as away.

func (*UI) Bookmarks

func (ui *UI) Bookmarks() *Bookmarks

Bookmarks returns the underlying bookmark pane widget.

func (*UI) Busy

func (ui *UI) Busy(j jid.JID, self bool)

Busy sets the state of the roster to show the user as busy.

func (*UI) ChatsOpen

func (ui *UI) ChatsOpen() bool

ChatsOpen returns true if the chat pane is open.

func (*UI) Conversations

func (ui *UI) Conversations() *Conversations

Conversations returns the recent conversations widget.

func (*UI) GetRect

func (ui *UI) GetRect() (x, y, width, height int)

GetRect returns the size of the UI on the screen (including borders and bounding boxes).

func (*UI) GetRosterJID

func (ui *UI) GetRosterJID() jid.JID

GetRosterJID gets the currently selected roster or bookmark JID.

func (*UI) Handle

func (ui *UI) Handle(handler func(interface{}))

Handle configures an event handler which will be called when the user performs certain actions in the UI. Only one event handler can be registered, and subsequent calls to Handle will replace the handler. The function will be called synchronously on the UI goroutine, so don't do any intensive work (or launch a new goroutine if you must).

func (*UI) History

func (ui *UI) History() *tview.TextView

History returns the chat history view. To flush any remaining data to the buffer, the writer must be closed after use.

func (*UI) Offline

func (ui *UI) Offline(j jid.JID, self bool)

Offline sets the state of the roster to show the user as offline.

func (*UI) Online

func (ui *UI) Online(j jid.JID, self bool)

Online sets the state of the roster to show the user as online.

func (*UI) PickResource

func (ui *UI) PickResource(f func(jid.JID, bool))

PickResource shows a modal with the currently selected roster items resources and lets the user pick one. It then calls f with the full JID and whether or not picking a resource was successful.

func (*UI) Redraw

func (ui *UI) Redraw()

Redraw redraws the UI.

func (*UI) Roster

func (ui *UI) Roster() *Roster

Roster returns the underlying roster pane widget.

func (*UI) RosterLen

func (ui *UI) RosterLen() int

RosterLen returns the length of the currently visible roster.

func (*UI) Run

func (ui *UI) Run() error

Run starts the application event loop.

func (*UI) SelectRoster

func (ui *UI) SelectRoster()

SelectRoster moves the input selection back to the roster and shows the logs view.

func (*UI) SetCommands

func (ui *UI) SetCommands(j jid.JID, c []commands.Command)

SetCommands populates the list of ad-hoc commands in the list commands window. It should generally be called after the commands have been loaded and after the "ShowListCMD" function has been called (since that sets the text to a loading indicator).

func (*UI) ShowAddBookmark

func (ui *UI) ShowAddBookmark()

ShowAddBookmark asks the user for a new JID.

func (*UI) ShowAddRoster

func (ui *UI) ShowAddRoster()

ShowAddRoster asks the user for a new JID.

func (*UI) ShowForm

func (ui *UI) ShowForm(formData *form.Data, buttons []string, onDone func(string))

ShowForm displays an ad-hoc commands form.

func (*UI) ShowHelpPrompt

func (ui *UI) ShowHelpPrompt()

ShowHelpPrompt shows a list of keyboard shortcuts..

func (*UI) ShowLoadCmd

func (ui *UI) ShowLoadCmd(j jid.JID)

ShowLoadCmd shows available ad-hoc commands for the selected JID.

func (*UI) ShowNote

func (ui *UI) ShowNote(note commands.Note, buttons []string, onDone func(string))

ShowNote shows a text note from an ad-hoc command.

func (*UI) ShowPasswordPrompt

func (ui *UI) ShowPasswordPrompt() string

ShowPasswordPrompt displays a modal and blocks until the user enters a password and submits it.

func (*UI) ShowQuitPrompt

func (ui *UI) ShowQuitPrompt()

ShowQuitPrompt asks if the user wants to quit the application.

func (*UI) ShowRosterInfo

func (ui *UI) ShowRosterInfo()

ShowRosterInfo displays more info about the currently selected roster item.

func (*UI) Stop

func (ui *UI) Stop()

Stop stops the application, causing Run() to return.

func (*UI) UpdateBookmarks

func (ui *UI) UpdateBookmarks(item bookmarks.Channel)

UpdateBookmarks adds an item to the bookmarks sidebar.

func (*UI) UpdateConversations

func (ui *UI) UpdateConversations(c Conversation)

UpdateConversations adds a roster item to the recent conversations list.

func (*UI) UpdateRoster

func (ui *UI) UpdateRoster(item RosterItem)

UpdateRoster adds an item to the roster.

func (*UI) Write

func (ui *UI) Write(p []byte) (n int, err error)

Write writes to the logging text view.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL