Documentation ¶
Index ¶
- Constants
- func BottomPrimaryLayout(topView, bottomView string) func(*gocui.Gui) error
- func RenderMessage(message *arbor.ChatMessage, width int, colorPre string, colorPost string) [][]byte
- type Binding
- type EditCore
- type Editor
- func (e *Editor) ActionInsertNewline(g *gocui.Gui, v *gocui.View) error
- func (e *Editor) ActionInsertTab(g *gocui.Gui, v *gocui.View) error
- func (e *Editor) ActionTogglePasteMode(g *gocui.Gui, v *gocui.View) error
- func (e *Editor) Clear() error
- func (e *Editor) EnterIsLiteral() bool
- func (e *Editor) Focus(replyTo *arbor.ChatMessage) error
- func (e *Editor) Layout(g *gocui.Gui) error
- func (e *Editor) Unfocus() error
- type HistoryState
- func (h HistoryState) Current() string
- func (h *HistoryState) CursorBeginning()
- func (h *HistoryState) CursorDown()
- func (h *HistoryState) CursorEnd()
- func (h *HistoryState) CursorLines() (int, int)
- func (h *HistoryState) CursorUp()
- func (h *HistoryState) Height() int
- func (h *HistoryState) New(message *arbor.ChatMessage) error
- func (h *HistoryState) Render(target io.Writer) error
- func (h *HistoryState) SetDimensions(height, width int)
- type TUI
Constants ¶
const ( // CurrentColor is the ANSI escape sequence for the color that is used to highlight // the currently-selected message CurrentColor = red // AncestorColor is the ANSI escape sequence for the color that is use to highlight // the ancestors of the currently-selected message AncestorColor = yellow // ClearColor is the ANSI escape sequence to return to the default color ClearColor = "\x1b[0;0m" )
Variables ¶
This section is empty.
Functions ¶
func BottomPrimaryLayout ¶
BottomPrimaryLayout manages two gocui.Views within a gocui.Gui by respecting the size requests of the bottom view at the expense of the size of the top. The bottom view will be positioned at the bottom of the Gui, regardless of whatever internal position it may have requested. The bottom view will also be prevented from exapanding beyond half of the available screen real-estate.
Note that BottomPrimaryLayout returns a Layout function, so proper usage is: ``` manager := gocui.ManagerFunc(BottomPrimaryLayout("bottom-view-name", "top-view-name")) ```
func RenderMessage ¶
func RenderMessage(message *arbor.ChatMessage, width int, colorPre string, colorPost string) [][]byte
RenderMessage creates a text format of a message that wraps its contents to fit within the provided width. If a user "foo" sent a long message, the result should look like:
`foo: jsdkfljsdfkljsfkljsdkfj
jskfldjfkdjsflsdkfjsldf jksdfljskdfjslkfjsldkfj`
The important thing to note is that lines are broken at the same place and that subsequent lines are padded with runewidth(username)+2 spaces. Each row of output is returned as a byte slice.
Types ¶
type Binding ¶
type Binding struct { View string Key interface{} Modifier gocui.Modifier Handler func(*gocui.Gui, *gocui.View) error HandlerName string }
Binding represents a binding between a keypress and a handler function
type Editor ¶
type Editor struct { Title string ReplyTo *arbor.ChatMessage Content string // contains filtered or unexported fields }
Editor acts as a controller for an editable gocui.View This editor provides a layout function that will manage its own size, but not its position within the TUI. Its size when empty will be 1 internal row, but will expand as content is added.
Insofar as it is possible, Editor is decoupled from the *gocui.View. Their only interactions are in the Layout function, which synchronizes the state of this controller with the state of the view, and the Action* methods defined on the editor (these are meant as keystroke handlers)
func (*Editor) ActionInsertNewline ¶
ActionInsertNewline adds a newline character into the editor at the current cursor position.
func (*Editor) ActionInsertTab ¶
ActionInsertTab adds a tab character into the editor at the current cursor position.
func (*Editor) ActionTogglePasteMode ¶
ActionTogglePasteMode toggles whether or not the <Enter> key is interpreted literally.
func (*Editor) Clear ¶
Clear erases the current contents of the editor. This should be performed within a gocui.Update context.
func (*Editor) EnterIsLiteral ¶
EnterIsLiteral returns whether or not pressing the "Enter" key should insert a newline into the editor.
func (*Editor) Focus ¶
func (e *Editor) Focus(replyTo *arbor.ChatMessage) error
Focus lets the Editor perform any changes needed when it gains focus. It should always be called from within a gocui.Update function (or similar) so that the changes are rendered immediately
func (*Editor) Layout ¶
Layout is responsible for setting the desired view dimensions for the Editor, but *not* for setting its position. That is handled by a higher-order layout function. Layout also executes any state changes the editor requests, such as gaining focus or clearing the Editor's contents.
type HistoryState ¶
type HistoryState struct { // history represents chat messages in the order in which they were received. // Index 0 holds the oldes messages, and the highest valid index holds the most // recent. History []*arbor.ChatMessage types.Archive // contains filtered or unexported fields }
HistoryState maintains the state of what is visible in the client and can render it to any io.Writer.
func NewHistoryState ¶
func NewHistoryState(a types.Archive) (*HistoryState, error)
NewHistoryState creates an empty HistoryState ready to be updated.
func (HistoryState) Current ¶
func (h HistoryState) Current() string
Current returns the id of the currently-selected message, if there is one. The first message added to a HistoryState is marked as current automatically. After that, Current can only be changed by scrolling.
func (*HistoryState) CursorBeginning ¶
func (h *HistoryState) CursorBeginning()
CursorBeginning moves the current message to the beginning of the history.
func (*HistoryState) CursorDown ¶
func (h *HistoryState) CursorDown()
CursorDown moves the current message downward within the history, if it is possible to do so. If there are no messages in the history, it does nothing. If the current message is at the bottom of the history, it does nothing.
func (*HistoryState) CursorEnd ¶
func (h *HistoryState) CursorEnd()
CursorEnd moves the current message to the end of the history.
func (*HistoryState) CursorLines ¶
func (h *HistoryState) CursorLines() (int, int)
CursorLines returns the range of rendered lines that contain the selected message. These are expressed in 0-based indicies. If the results were (1,2), that would mean that the current message spans the second and third lines of the rendered output.
func (*HistoryState) CursorUp ¶
func (h *HistoryState) CursorUp()
CursorUp moves the current message upward within the history, if it is possible to do so. If there are no messages in the history, it does nothing. If the current message is at the top of the history, it does nothing.
func (*HistoryState) Height ¶
func (h *HistoryState) Height() int
Height returns the number of lines of text rendered in the last render.
func (*HistoryState) New ¶
func (h *HistoryState) New(message *arbor.ChatMessage) error
New alerts the HistoryState of a newly received message.
func (*HistoryState) Render ¶
func (h *HistoryState) Render(target io.Writer) error
Render writes the correct contents of the history to the provided writer. Each time it is invoked, it will render the entire history, so the writer should be empty when it is invoked.
func (*HistoryState) SetDimensions ¶
func (h *HistoryState) SetDimensions(height, width int)
SetDimensions notifes the HistoryState that the renderable display area has changed so that its next render can avoid rendering offscreen.
type TUI ¶
TUI is the default terminal user interface implementation for this client
func NewTUI ¶
NewTUI creates a new terminal user interface. The provided channel will be used to relay any protocol messages initiated by the TUI.
func (*TUI) AwaitExit ¶
func (t *TUI) AwaitExit()
AwaitExit unconditionally blocks until the TUI exits.
func (*TUI) Display ¶
func (t *TUI) Display(message *arbor.ChatMessage)
Display adds the provided message to the visible interface.
func (*TUI) Keybindings ¶
Keybindings returns the default keybindings