commit 0495351

Hubert Hirtz  ·  2020-08-26 15:27:14 +0000 UTC
parent dad549f
Move ui.Home and ui.homeMessages up
5 files changed,  +38, -35
M app.go
M app.go
+14, -10
  1@@ -45,14 +45,16 @@ func NewApp(cfg Config) (app *App, err error) {
  2 		return
  3 	}
  4 
  5+	app.initWindow()
  6+
  7 	var conn *tls.Conn
  8-	app.addLineNow(ui.Home, ui.Line{
  9+	app.addLineNow(Home, ui.Line{
 10 		Head: "--",
 11 		Body: fmt.Sprintf("Connecting to %s...", cfg.Addr),
 12 	})
 13 	conn, err = tls.Dial("tcp", cfg.Addr, nil)
 14 	if err != nil {
 15-		app.addLineNow(ui.Home, ui.Line{
 16+		app.addLineNow(Home, ui.Line{
 17 			Head:      "!!",
 18 			HeadColor: ui.ColorRed,
 19 			Body:      "Connection failed",
 20@@ -73,7 +75,7 @@ func NewApp(cfg Config) (app *App, err error) {
 21 		Debug:    cfg.Debug,
 22 	})
 23 	if err != nil {
 24-		app.addLineNow(ui.Home, ui.Line{
 25+		app.addLineNow(Home, ui.Line{
 26 			Head:      "!!",
 27 			HeadColor: ui.ColorRed,
 28 			Body:      "Registration failed",
 29@@ -132,7 +134,7 @@ func (app *App) handleIRCEvent(ev irc.Event) {
 30 		} else if !ev.IsValid {
 31 			head = "IN ??"
 32 		}
 33-		app.win.AddLine(ui.Home, false, ui.Line{
 34+		app.win.AddLine(Home, false, ui.Line{
 35 			At:   time.Now(),
 36 			Head: head,
 37 			Body: ev.Message,
 38@@ -142,7 +144,7 @@ func (app *App) handleIRCEvent(ev irc.Event) {
 39 		if app.s.Nick() != app.cfg.Nick {
 40 			body += " as " + app.s.Nick()
 41 		}
 42-		app.win.AddLine(ui.Home, false, ui.Line{
 43+		app.win.AddLine(Home, false, ui.Line{
 44 			At:   time.Now(),
 45 			Head: "--",
 46 			Body: body,
 47@@ -204,7 +206,7 @@ func (app *App) handleIRCEvent(ev irc.Event) {
 48 	case irc.TagEvent:
 49 		buffer := ev.Target
 50 		if !ev.TargetIsChannel {
 51-			buffer = ui.Home
 52+			buffer = Home
 53 		}
 54 		if ev.Typing == irc.TypingActive || ev.Typing == irc.TypingPaused {
 55 			app.win.TypingStart(buffer, ev.User.Name)
 56@@ -231,19 +233,21 @@ func (app *App) handleUIEvent(ev tcell.Event) {
 57 	switch ev := ev.(type) {
 58 	case *tcell.EventResize:
 59 		app.win.Resize()
 60+		app.draw()
 61 	case *tcell.EventKey:
 62 		switch ev.Key() {
 63 		case tcell.KeyCtrlC:
 64 			app.win.Exit()
 65 		case tcell.KeyCtrlL:
 66 			app.win.Resize()
 67+			app.draw()
 68 		case tcell.KeyCtrlU, tcell.KeyPgUp:
 69 			app.win.ScrollUp()
 70 			if app.s == nil {
 71 				return
 72 			}
 73 			buffer := app.win.CurrentBuffer()
 74-			if app.win.IsAtTop() && buffer != ui.Home {
 75+			if app.win.IsAtTop() && buffer != Home {
 76 				at := time.Now()
 77 				if t := app.win.CurrentBufferOldestTime(); t != nil {
 78 					at = *t
 79@@ -346,7 +350,7 @@ func (app *App) notifyHighlight(buffer, nick, content string) {
 80 	command := r.Replace(app.cfg.OnHighlight)
 81 	err = exec.Command(sh, "-c", command).Run()
 82 	if err != nil {
 83-		app.win.AddLine(ui.Home, false, ui.Line{
 84+		app.win.AddLine(Home, false, ui.Line{
 85 			At:        time.Now(),
 86 			Head:      "ERROR --",
 87 			HeadColor: ui.ColorRed,
 88@@ -360,7 +364,7 @@ func (app *App) typing() {
 89 		return
 90 	}
 91 	buffer := app.win.CurrentBuffer()
 92-	if buffer == ui.Home {
 93+	if buffer == Home {
 94 		return
 95 	}
 96 	if app.win.InputLen() == 0 {
 97@@ -426,7 +430,7 @@ func (app *App) formatMessage(ev irc.MessageEvent) (buffer string, line ui.Line,
 98 	if !ev.TargetIsChannel && isNotice {
 99 		buffer = app.win.CurrentBuffer()
100 	} else if !ev.TargetIsChannel {
101-		buffer = ui.Home
102+		buffer = Home
103 	} else {
104 		buffer = ev.Target
105 	}
+3, -3
 1@@ -168,7 +168,7 @@ func commandDoJoin(app *App, buffer string, args []string) (err error) {
 2 }
 3 
 4 func commandDoMe(app *App, buffer string, args []string) (err error) {
 5-	if buffer == ui.Home {
 6+	if buffer == Home {
 7 		buffer = app.lastQuery
 8 	}
 9 	content := fmt.Sprintf("\x01ACTION %s\x01", args[0])
10@@ -240,7 +240,7 @@ func commandDoPart(app *App, buffer string, args []string) (err error) {
11 		}
12 	}
13 
14-	if channel != ui.Home {
15+	if channel != Home {
16 		app.s.Part(channel, reason)
17 	} else {
18 		err = fmt.Errorf("cannot part home!")
19@@ -331,7 +331,7 @@ func (app *App) handleInput(buffer, content string) error {
20 	if len(args) < cmd.MinArgs {
21 		return fmt.Errorf("usage: %s %s", cmdName, cmd.Usage)
22 	}
23-	if buffer == ui.Home && !cmd.AllowHome {
24+	if buffer == Home && !cmd.AllowHome {
25 		return fmt.Errorf("command %q cannot be executed from home", cmdName)
26 	}
27 
+0, -11
 1@@ -9,17 +9,6 @@ import (
 2 	"github.com/gdamore/tcell"
 3 )
 4 
 5-var Home = "home"
 6-
 7-var homeMessages = []string{
 8-	"\x1dYou open an IRC client.",
 9-	"Welcome to the Internet Relay Network!",
10-	"Mentions & cie go here.",
11-	"May the IRC be with you.",
12-	"Hey! I'm senpai, you everyday IRC student!",
13-	"Student? No, I'm an IRC \x02client\x02!",
14-}
15-
16 func IsSplitRune(r rune) bool {
17 	return r == ' ' || r == '\t'
18 }
+0, -11
 1@@ -1,7 +1,6 @@
 2 package ui
 3 
 4 import (
 5-	"math/rand"
 6 	"sync/atomic"
 7 	"time"
 8 
 9@@ -51,17 +50,8 @@ func New(config Config) (ui *UI, err error) {
10 
11 	ui.exit.Store(false)
12 
13-	hmIdx := rand.Intn(len(homeMessages))
14 	ui.bs = NewBufferList(w, h, ui.config.NickColWidth)
15-	ui.bs.Add(Home)
16-	ui.bs.AddLine("", false, Line{
17-		At:   time.Now(),
18-		Head: "--",
19-		Body: homeMessages[hmIdx],
20-	})
21-
22 	ui.e = NewEditor(w, ui.config.AutoComplete)
23-
24 	ui.Resize()
25 
26 	return
27@@ -187,7 +177,6 @@ func (ui *UI) Resize() {
28 	w, h := ui.screen.Size()
29 	ui.e.Resize(w)
30 	ui.bs.Resize(w, h)
31-	ui.Draw()
32 }
33 
34 func (ui *UI) Draw() {
+21, -0
 1@@ -1,11 +1,32 @@
 2 package senpai
 3 
 4 import (
 5+	"math/rand"
 6 	"time"
 7 
 8 	"git.sr.ht/~taiite/senpai/ui"
 9 )
10 
11+var Home = "home"
12+
13+var homeMessages = []string{
14+	"\x1dYou open an IRC client.",
15+	"Welcome to the Internet Relay Network!",
16+	"DMs & cie go here.",
17+	"May the IRC be with you.",
18+	"Hey! I'm senpai, you everyday IRC student!",
19+	"Student? No, I'm an IRC \x02client\x02!",
20+}
21+
22+func (app *App) initWindow() {
23+	hmIdx := rand.Intn(len(homeMessages))
24+	app.win.AddBuffer(Home)
25+	app.addLineNow("", ui.Line{
26+		Head: "--",
27+		Body: homeMessages[hmIdx],
28+	})
29+}
30+
31 func (app *App) addLineNow(buffer string, line ui.Line) {
32 	if line.At.IsZero() {
33 		line.At = time.Now()