Documentation
¶
Overview ¶
Package launcheripc is the launcher socket: the protocol between `lys-shell launcher` (the rofi shim) and the launcher surface in the shell, with both halves - the CLI's client and the shell's server.
One persistent connection per session carries newline-delimited JSON frames, and the connection doubles as the session's lifetime: when the CLI dies the server sees EOF and closes the surface; when the server replies with a terminal frame, the CLI prints it and exits with rofi's code.
Index ¶
Constants ¶
const ( FrameOpen = "open" FrameRows = "rows" FrameRowsDone = "rows-done" FrameOpened = "opened" FrameBusy = "busy" FrameResult = "result" FrameCancelled = "cancelled" FrameDump = "dump" )
Frame type tags.
const RowChunk = 2000
RowChunk is the number of rows per rows frame when streaming stdin.
Variables ¶
var ErrDisconnected = errors.New("launcher session ended unexpectedly")
ErrDisconnected is the shell closing the connection without a terminal frame.
Functions ¶
func SocketPath ¶
SocketPath is $XDG_RUNTIME_DIR/lys-shell/launcher.sock; an error naming XDG_RUNTIME_DIR when the process has no absolute one.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the CLI's connection to the launcher surface. The write half must stay open for the whole session: closing it half-closes the socket, and the shell reads that EOF as the client dying and tears the surface down.
func Open ¶
func Open(options SessionOptions, replace bool) (*Client, error)
Open connects the launcher socket and sends the open frame.
func (*Client) FinishRows ¶
FinishRows signals stdin EOF. It does not close the write half.
func (*Client) NextFrame ¶
func (c *Client) NextFrame() (ServerFrame, error)
NextFrame reads the next shell frame; EOF is ErrDisconnected. The shell owes its first frame at once, and the rest whenever the person acts.
type ClientFrame ¶
type ClientFrame struct {
Type string `json:"type"`
// Options and Replace are the open frame's.
Options *SessionOptions `json:"options,omitempty"`
Replace bool `json:"replace,omitempty"`
// Items is the rows frame's chunk.
Items []string `json:"items,omitempty"`
}
ClientFrame is a CLI -> shell frame: open (Options, Replace), rows (Items), or rows-done.
func (ClientFrame) MarshalJSON ¶
func (f ClientFrame) MarshalJSON() ([]byte, error)
MarshalJSON writes the variant's fields, all of them, an open frame's replace and a rows frame's items included.
type Handler ¶
type Handler interface {
// Open starts a session. It is called on the connection's
// goroutine and must not block; the surface eventually Replies.
Open(s *Session)
// ClientGone reports a CLI whose socket died (ctrl-C): close the
// session if it is still the live one, and Reply to release the
// connection.
ClientGone(id uint64)
}
Handler is the surface side of the socket.
type Selected ¶
type Selected struct {
// Index is the row's input index; -1 for accepted custom input.
Index int64 `json:"index"`
Text string `json:"text"`
}
Selected is one accepted row.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server accepts launcher sessions.
type ServerFrame ¶
type ServerFrame struct {
Type string `json:"type"`
// Code is the rofi exit code: 0 accept, 1 cancel, 10..28
// kb-custom-N.
Code int `json:"code"`
Selected []Selected `json:"selected,omitempty"`
// Filter is the query at accept time (rofi -format f/F).
Filter string `json:"filter"`
Items []string `json:"items,omitempty"`
}
ServerFrame is a shell -> CLI frame: opened, busy, result (Code, Selected, Filter), cancelled (Code), or dump (Items).
func Busy ¶
func Busy() ServerFrame
Busy is the reply when another session is live and replace was not asked for.
func Dump ¶
func Dump(items []string) ServerFrame
Dump is the -dump reply: the filtered rows in display order.
func Result ¶
func Result(code int, selected []Selected, filter string) ServerFrame
Result is a result frame.
func (ServerFrame) MarshalJSON ¶
func (f ServerFrame) MarshalJSON() ([]byte, error)
MarshalJSON writes only the fields the frame's variant carries.
type Session ¶
type Session struct {
// ID is the connection's identity; ClientGone names it.
ID uint64
Options SessionOptions
// Replace is rofi -replace: displace a live session instead of
// answering busy.
Replace bool
// Rows streams the dmenu rows; it closes on rows-done or when the
// client goes away.
Rows <-chan []string
// contains filtered or unexported fields
}
Session is one CLI session handed to the surface.
func NewSession ¶
func NewSession(id uint64, options SessionOptions, replace bool, rows <-chan []string) (*Session, <-chan ServerFrame)
NewSession builds a session and the channel its terminal frame comes out of (one frame; a Release sends the zero frame). The server opens every session through it; a surface under test opens them directly.
func (*Session) Release ¶
func (s *Session) Release()
Release ends the session without a frame: the client is gone, so there is nobody to answer.
func (*Session) Reply ¶
func (s *Session) Reply(f ServerFrame)
Reply sends the session's terminal frame (result, cancelled, busy, or dump); the server writes it and closes the connection. Only the first call counts.
type SessionOptions ¶
type SessionOptions struct {
Mode *string `json:"mode,omitempty"`
Modes []string `json:"modes,omitempty"`
ErrorMessage *string `json:"error-message,omitempty"`
Prompt *string `json:"prompt,omitempty"`
Lines *uint32 `json:"lines,omitempty"`
Mesg *string `json:"mesg,omitempty"`
Filter *string `json:"filter,omitempty"`
Select *string `json:"select,omitempty"`
SelectedRow *uint32 `json:"selected-row,omitempty"`
WindowTitle *string `json:"window-title,omitempty"`
MultiSelect bool `json:"multi-select,omitempty"`
OnlyMatch bool `json:"only-match,omitempty"`
NoCustom bool `json:"no-custom,omitempty"`
Password bool `json:"password,omitempty"`
MarkupRows bool `json:"markup-rows,omitempty"`
Sync bool `json:"sync,omitempty"`
Dump bool `json:"dump,omitempty"`
Urgent []uint32 `json:"urgent,omitempty"`
Active []uint32 `json:"active,omitempty"`
BallotSelected *string `json:"ballot-selected,omitempty"`
BallotUnselected *string `json:"ballot-unselected,omitempty"`
DisplayColumns []uint32 `json:"display-columns,omitempty"`
DisplayColumnSeparator *string `json:"display-column-separator,omitempty"`
EllipsizeMode *string `json:"ellipsize-mode,omitempty"`
KeepRight bool `json:"keep-right,omitempty"`
Matching *string `json:"matching,omitempty"`
Tokenize *bool `json:"tokenize,omitempty"`
NegateChar *string `json:"negate-char,omitempty"`
NormalizeMatch *bool `json:"normalize-match,omitempty"`
Sort *bool `json:"sort,omitempty"`
SortingMethod *string `json:"sorting-method,omitempty"`
CaseSensitive *bool `json:"case-sensitive,omitempty"`
CaseSmart *bool `json:"case-smart,omitempty"`
CaseInsensitive *bool `json:"case-insensitive,omitempty"`
Location *uint8 `json:"location,omitempty"`
Width *Width `json:"width,omitempty"`
XOffset *int32 `json:"xoffset,omitempty"`
YOffset *int32 `json:"yoffset,omitempty"`
Monitor *string `json:"monitor,omitempty"`
NoFixedNumLines bool `json:"no-fixed-num-lines,omitempty"`
SidebarMode *bool `json:"sidebar-mode,omitempty"`
Cycle *bool `json:"cycle,omitempty"`
AutoSelect *bool `json:"auto-select,omitempty"`
HoverSelect *bool `json:"hover-select,omitempty"`
ShowIcons *bool `json:"show-icons,omitempty"`
IconTheme *string `json:"icon-theme,omitempty"`
Terminal *string `json:"terminal,omitempty"`
RunCommand *string `json:"run-command,omitempty"`
RunShellCommand *string `json:"run-shell-command,omitempty"`
RunListCommand *string `json:"run-list-command,omitempty"`
SSHClient *string `json:"ssh-client,omitempty"`
SSHCommand *string `json:"ssh-command,omitempty"`
ParseHosts *bool `json:"parse-hosts,omitempty"`
ParseKnownHosts *bool `json:"parse-known-hosts,omitempty"`
WindowFormat *string `json:"window-format,omitempty"`
WindowCommand *string `json:"window-command,omitempty"`
WindowMatchFields []string `json:"window-match-fields,omitempty"`
HideActiveWindow *bool `json:"hide-active-window,omitempty"`
DrunCategories []string `json:"drun-categories,omitempty"`
DrunExcludeCategories []string `json:"drun-exclude-categories,omitempty"`
DrunMatchFields []string `json:"drun-match-fields,omitempty"`
DrunDisplayFormat *string `json:"drun-display-format,omitempty"`
DrunShowActions *bool `json:"drun-show-actions,omitempty"`
DrunURLLauncher *string `json:"drun-url-launcher,omitempty"`
ApplicationFallbackIcon *string `json:"application-fallback-icon,omitempty"`
IgnoredPrefixes []string `json:"ignored-prefixes,omitempty"`
CombiModes []string `json:"combi-modes,omitempty"`
CombiDisplayFormat *string `json:"combi-display-format,omitempty"`
// KbOverrides maps an action (no kb- prefix) to its key list.
KbOverrides map[string]string `json:"kb-overrides,omitempty"`
// MouseOverrides maps an action (me-/ml- prefix kept, the two
// namespaces have their own names) to its binding list.
MouseOverrides map[string]string `json:"mouse-overrides,omitempty"`
// DisplayNames maps a mode to its display name (-display-<mode>).
DisplayNames map[string]string `json:"display-names,omitempty"`
OnSelectionChanged *string `json:"on-selection-changed,omitempty"`
OnEntryAccepted *string `json:"on-entry-accepted,omitempty"`
OnModeChanged *string `json:"on-mode-changed,omitempty"`
OnMenuCanceled *string `json:"on-menu-canceled,omitempty"`
OnMenuError *string `json:"on-menu-error,omitempty"`
Font *string `json:"font,omitempty"`
Style *string `json:"style,omitempty"`
PreviewCmd *string `json:"preview-cmd,omitempty"`
CompleterMode *string `json:"completer-mode,omitempty"`
}
SessionOptions is the open frame's per-invocation options: rofi's flag surface. Every field is optional; the shell merges the set ones over [launcher].
type Width ¶
type Width struct {
Unit WidthUnit
// Value is the percent, the char count, or the pixels.
Value float64
}
Width is a parsed -width. The zero Width is no width.
func ParseWidth ¶
ParseWidth reads a rofi -width: NNpx is pixels, a negative number a character count, anything else a percentage. Not a number is an error naming the value.
func (Width) MarshalJSON ¶
MarshalJSON writes the externally tagged form: {"percent":60.0}, {"chars":30}, {"pixels":600}.
func (*Width) UnmarshalJSON ¶
UnmarshalJSON reads the tagged form; an unknown tag is an error.
type WidthUnit ¶
type WidthUnit uint8
WidthUnit is the unit of a rofi -width value.
const ( // WidthPercent is `-width 60`: percent of the monitor's width. WidthPercent WidthUnit = iota + 1 // WidthChars is `-width -30`: a character count, measured against // the font's advance. WidthChars // WidthPixels is `-width 600px`. WidthPixels )
Width units, distinguished by syntax in rofi rather than a suffix.