commit 74107f8

Hubert Hirtz  ·  2020-11-13 10:25:54 +0000 UTC
parent 09983c7
Document functions in app.go
1 files changed,  +18, -0
M app.go
M app.go
+18, -0
 1@@ -370,6 +370,8 @@ func (app *App) handleUIEvent(ev tcell.Event) {
 2 	}
 3 }
 4 
 5+// requestHistory is a wrapper around irc.Session.RequestHistory to only request
 6+// history when needed.
 7 func (app *App) requestHistory() {
 8 	if app.s == nil {
 9 		return
10@@ -384,6 +386,7 @@ func (app *App) requestHistory() {
11 	}
12 }
13 
14+// isHighlight reports whether the given message content is a highlight.
15 func (app *App) isHighlight(content string) bool {
16 	contentCf := strings.ToLower(content)
17 	if app.highlights == nil {
18@@ -397,6 +400,8 @@ func (app *App) isHighlight(content string) bool {
19 	return false
20 }
21 
22+// notifyHighlight executes the "on-highlight" command according to the given
23+// message context.
24 func (app *App) notifyHighlight(buffer, nick, content string) {
25 	sh, err := exec.LookPath("sh")
26 	if err != nil {
27@@ -424,6 +429,8 @@ func (app *App) notifyHighlight(buffer, nick, content string) {
28 	}
29 }
30 
31+// typing sends typing notifications to the IRC server according to the user
32+// input.
33 func (app *App) typing() {
34 	if app.s == nil {
35 		return
36@@ -439,6 +446,8 @@ func (app *App) typing() {
37 	}
38 }
39 
40+// completions computes the list of completions given the input text and the
41+// cursor position.
42 func (app *App) completions(cursorIdx int, text []rune) []ui.Completion {
43 	var cs []ui.Completion
44 
45@@ -485,6 +494,12 @@ func (app *App) completions(cursorIdx int, text []rune) []ui.Completion {
46 	return cs
47 }
48 
49+// formatMessage sets how a given message must be formatted.
50+//
51+// It computes three things:
52+// - which buffer the message must be added to,
53+// - the UI line,
54+// - whether senpai must trigger the "on-highlight" command.
55 func (app *App) formatMessage(ev irc.MessageEvent) (buffer string, line ui.Line, hlNotification bool) {
56 	isFromSelf := app.s.NickCf() == app.s.Casemap(ev.User.Name)
57 	isHighlight := app.isHighlight(ev.Content)
58@@ -536,6 +551,7 @@ func (app *App) formatMessage(ev irc.MessageEvent) (buffer string, line ui.Line,
59 	return
60 }
61 
62+// updatePrompt changes the prompt text according to the application context.
63 func (app *App) updatePrompt() {
64 	buffer := app.win.CurrentBuffer()
65 	command := app.win.InputIsCommand()
66@@ -546,6 +562,7 @@ func (app *App) updatePrompt() {
67 	}
68 }
69 
70+// ircColorSequence returns the color formatting sequence of a color code.
71 func ircColorSequence(code int) string {
72 	var c [3]rune
73 	c[0] = 0x03
74@@ -554,6 +571,7 @@ func ircColorSequence(code int) string {
75 	return string(c[:])
76 }
77 
78+// cleanMessage removes IRC formatting from a string.
79 func cleanMessage(s string) string {
80 	var res strings.Builder
81 	var sb ui.StyleBuffer