summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Hirtz <hubert@hirtzfr.eu>2020-08-26 17:27:14 +0200
committerHubert Hirtz <hubert@hirtzfr.eu>2020-08-26 17:53:40 +0200
commit0495351b44cc7fc171c98cbcce57e966092ce6a1 (patch)
tree062866db03bec6f1fd85f76413283294943bde18
parentUpdate tcell and support italics (diff)
Move ui.Home and ui.homeMessages up
-rw-r--r--app.go24
-rw-r--r--commands.go6
-rw-r--r--ui/buffers.go11
-rw-r--r--ui/ui.go11
-rw-r--r--window.go21
5 files changed, 38 insertions, 35 deletions
diff --git a/app.go b/app.go
index 417f18e..f22a30c 100644
--- a/app.go
+++ b/app.go
@@ -45,14 +45,16 @@ func NewApp(cfg Config) (app *App, err error) {
return
}
+ app.initWindow()
+
var conn *tls.Conn
- app.addLineNow(ui.Home, ui.Line{
+ app.addLineNow(Home, ui.Line{
Head: "--",
Body: fmt.Sprintf("Connecting to %s...", cfg.Addr),
})
conn, err = tls.Dial("tcp", cfg.Addr, nil)
if err != nil {
- app.addLineNow(ui.Home, ui.Line{
+ app.addLineNow(Home, ui.Line{
Head: "!!",
HeadColor: ui.ColorRed,
Body: "Connection failed",
@@ -73,7 +75,7 @@ func NewApp(cfg Config) (app *App, err error) {
Debug: cfg.Debug,
})
if err != nil {
- app.addLineNow(ui.Home, ui.Line{
+ app.addLineNow(Home, ui.Line{
Head: "!!",
HeadColor: ui.ColorRed,
Body: "Registration failed",
@@ -132,7 +134,7 @@ func (app *App) handleIRCEvent(ev irc.Event) {
} else if !ev.IsValid {
head = "IN ??"
}
- app.win.AddLine(ui.Home, false, ui.Line{
+ app.win.AddLine(Home, false, ui.Line{
At: time.Now(),
Head: head,
Body: ev.Message,
@@ -142,7 +144,7 @@ func (app *App) handleIRCEvent(ev irc.Event) {
if app.s.Nick() != app.cfg.Nick {
body += " as " + app.s.Nick()
}
- app.win.AddLine(ui.Home, false, ui.Line{
+ app.win.AddLine(Home, false, ui.Line{
At: time.Now(),
Head: "--",
Body: body,
@@ -204,7 +206,7 @@ func (app *App) handleIRCEvent(ev irc.Event) {
case irc.TagEvent:
buffer := ev.Target
if !ev.TargetIsChannel {
- buffer = ui.Home
+ buffer = Home
}
if ev.Typing == irc.TypingActive || ev.Typing == irc.TypingPaused {
app.win.TypingStart(buffer, ev.User.Name)
@@ -231,19 +233,21 @@ func (app *App) handleUIEvent(ev tcell.Event) {
switch ev := ev.(type) {
case *tcell.EventResize:
app.win.Resize()
+ app.draw()
case *tcell.EventKey:
switch ev.Key() {
case tcell.KeyCtrlC:
app.win.Exit()
case tcell.KeyCtrlL:
app.win.Resize()
+ app.draw()
case tcell.KeyCtrlU, tcell.KeyPgUp:
app.win.ScrollUp()
if app.s == nil {
return
}
buffer := app.win.CurrentBuffer()
- if app.win.IsAtTop() && buffer != ui.Home {
+ if app.win.IsAtTop() && buffer != Home {
at := time.Now()
if t := app.win.CurrentBufferOldestTime(); t != nil {
at = *t
@@ -346,7 +350,7 @@ func (app *App) notifyHighlight(buffer, nick, content string) {
command := r.Replace(app.cfg.OnHighlight)
err = exec.Command(sh, "-c", command).Run()
if err != nil {
- app.win.AddLine(ui.Home, false, ui.Line{
+ app.win.AddLine(Home, false, ui.Line{
At: time.Now(),
Head: "ERROR --",
HeadColor: ui.ColorRed,
@@ -360,7 +364,7 @@ func (app *App) typing() {
return
}
buffer := app.win.CurrentBuffer()
- if buffer == ui.Home {
+ if buffer == Home {
return
}
if app.win.InputLen() == 0 {
@@ -426,7 +430,7 @@ func (app *App) formatMessage(ev irc.MessageEvent) (buffer string, line ui.Line,
if !ev.TargetIsChannel && isNotice {
buffer = app.win.CurrentBuffer()
} else if !ev.TargetIsChannel {
- buffer = ui.Home
+ buffer = Home
} else {
buffer = ev.Target
}
diff --git a/commands.go b/commands.go
index 72c70b6..253b0d4 100644
--- a/commands.go
+++ b/commands.go
@@ -168,7 +168,7 @@ func commandDoJoin(app *App, buffer string, args []string) (err error) {
}
func commandDoMe(app *App, buffer string, args []string) (err error) {
- if buffer == ui.Home {
+ if buffer == Home {
buffer = app.lastQuery
}
content := fmt.Sprintf("\x01ACTION %s\x01", args[0])
@@ -240,7 +240,7 @@ func commandDoPart(app *App, buffer string, args []string) (err error) {
}
}
- if channel != ui.Home {
+ if channel != Home {
app.s.Part(channel, reason)
} else {
err = fmt.Errorf("cannot part home!")
@@ -331,7 +331,7 @@ func (app *App) handleInput(buffer, content string) error {
if len(args) < cmd.MinArgs {
return fmt.Errorf("usage: %s %s", cmdName, cmd.Usage)
}
- if buffer == ui.Home && !cmd.AllowHome {
+ if buffer == Home && !cmd.AllowHome {
return fmt.Errorf("command %q cannot be executed from home", cmdName)
}
diff --git a/ui/buffers.go b/ui/buffers.go
index 606a7ee..5620f60 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -9,17 +9,6 @@ import (
"github.com/gdamore/tcell"
)
-var Home = "home"
-
-var homeMessages = []string{
- "\x1dYou open an IRC client.",
- "Welcome to the Internet Relay Network!",
- "Mentions & cie go here.",
- "May the IRC be with you.",
- "Hey! I'm senpai, you everyday IRC student!",
- "Student? No, I'm an IRC \x02client\x02!",
-}
-
func IsSplitRune(r rune) bool {
return r == ' ' || r == '\t'
}
diff --git a/ui/ui.go b/ui/ui.go
index 8c8d0ec..dc6e73a 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -1,7 +1,6 @@
package ui
import (
- "math/rand"
"sync/atomic"
"time"
@@ -51,17 +50,8 @@ func New(config Config) (ui *UI, err error) {
ui.exit.Store(false)
- hmIdx := rand.Intn(len(homeMessages))
ui.bs = NewBufferList(w, h, ui.config.NickColWidth)
- ui.bs.Add(Home)
- ui.bs.AddLine("", false, Line{
- At: time.Now(),
- Head: "--",
- Body: homeMessages[hmIdx],
- })
-
ui.e = NewEditor(w, ui.config.AutoComplete)
-
ui.Resize()
return
@@ -187,7 +177,6 @@ func (ui *UI) Resize() {
w, h := ui.screen.Size()
ui.e.Resize(w)
ui.bs.Resize(w, h)
- ui.Draw()
}
func (ui *UI) Draw() {
diff --git a/window.go b/window.go
index 77719f2..a3b7e91 100644
--- a/window.go
+++ b/window.go
@@ -1,11 +1,32 @@
package senpai
import (
+ "math/rand"
"time"
"git.sr.ht/~taiite/senpai/ui"
)
+var Home = "home"
+
+var homeMessages = []string{
+ "\x1dYou open an IRC client.",
+ "Welcome to the Internet Relay Network!",
+ "DMs & cie go here.",
+ "May the IRC be with you.",
+ "Hey! I'm senpai, you everyday IRC student!",
+ "Student? No, I'm an IRC \x02client\x02!",
+}
+
+func (app *App) initWindow() {
+ hmIdx := rand.Intn(len(homeMessages))
+ app.win.AddBuffer(Home)
+ app.addLineNow("", ui.Line{
+ Head: "--",
+ Body: homeMessages[hmIdx],
+ })
+}
+
func (app *App) addLineNow(buffer string, line ui.Line) {
if line.At.IsZero() {
line.At = time.Now()