Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 8d92dc0

Browse files
committed
cleanup
1 parent 5864a63 commit 8d92dc0

File tree

10 files changed

+133
-38
lines changed

10 files changed

+133
-38
lines changed

komanda.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ import (
1212
"github.com/mephux/komanda-cli/komanda/client"
1313
"github.com/mephux/komanda-cli/komanda/config"
1414
"github.com/mephux/komanda-cli/komanda/logger"
15+
"github.com/mephux/komanda-cli/komanda/version"
1516
"gopkg.in/alecthomas/kingpin.v2"
1617
)
1718

1819
// Build value
1920
var Build = ""
2021

2122
var (
22-
app = kingpin.New(komanda.Name, komanda.Description)
23+
app = kingpin.New(version.Name, version.Description)
2324
ssl = app.Flag("ssl", "enable ssl").Short('s').Bool()
2425

2526
insecureSkipVerify = app.
@@ -40,6 +41,8 @@ var (
4041
func main() {
4142
runtime.GOMAXPROCS(runtime.NumCPU())
4243

44+
version.Build = Build
45+
4346
if p, err := common.HomeDir(); err == nil {
4447
config.ConfigFolder = path.Join(p, config.ConfigFolder)
4548
config.ConfigFile = path.Join(config.ConfigFolder, config.ConfigFile)
@@ -54,7 +57,7 @@ func main() {
5457
Build = fmt.Sprintf(".%s", Build)
5558
}
5659

57-
versionOutput := fmt.Sprintf("%s%s", komanda.Version, Build)
60+
versionOutput := fmt.Sprintf("%s%s", version.Version, Build)
5861

5962
app.Version(versionOutput)
6063
args, err := app.Parse(os.Args[1:])

komanda/client/channel.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (channel *Channel) AddNick(nick string) {
163163
func (channel *Channel) Render(update bool) error {
164164

165165
view, err := channel.Server.Gui.SetView(channel.Name,
166-
-1, -1, channel.MaxX, channel.MaxY-3)
166+
-1, -1, channel.MaxX, channel.MaxY-2)
167167

168168
if err != gocui.ErrUnknownView {
169169
return err

komanda/command/clear.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/mephux/komanda-cli/komanda/client"
88
"github.com/mephux/komanda-cli/komanda/color"
99
"github.com/mephux/komanda-cli/komanda/config"
10-
"github.com/mephux/komanda-cli/komanda/ui"
10+
"github.com/mephux/komanda-cli/komanda/version"
1111
)
1212

1313
type cmd struct {
@@ -30,8 +30,11 @@ func (e *cmd) Exec(args []string) error {
3030

3131
if Server.CurrentChannel == client.StatusChannel {
3232
fmt.Fprint(v, "\n\n")
33-
fmt.Fprintln(v, color.String(config.C.Color.Logo, ui.Logo))
34-
fmt.Fprintln(v, color.String(config.C.Color.Red, ui.VersionLine))
33+
fmt.Fprintln(v, version.ColorLogo())
34+
fmt.Fprintln(v, color.String(config.C.Color.Red,
35+
fmt.Sprintf(" Version: %s%s Source Code: %s\n",
36+
version.Version, version.Build, version.Website),
37+
))
3538
} else {
3639
fmt.Fprint(v, "\n\n")
3740
c.NickListString(v, false)

komanda/command/logo.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/mephux/komanda-cli/komanda/client"
88
"github.com/mephux/komanda-cli/komanda/color"
99
"github.com/mephux/komanda-cli/komanda/config"
10-
"github.com/mephux/komanda-cli/komanda/ui"
10+
"github.com/mephux/komanda-cli/komanda/version"
1111
)
1212

1313
// LogoCmd struct
@@ -24,8 +24,11 @@ func (e *LogoCmd) Metadata() CommandMetadata {
2424
func (e *LogoCmd) Exec(args []string) error {
2525

2626
Server.Exec(Server.CurrentChannel, func(c *client.Channel, g *gocui.Gui, v *gocui.View, s *client.Server) error {
27-
fmt.Fprintln(v, ui.Logo)
28-
fmt.Fprintln(v, color.String(config.C.Color.Green, ui.VersionLine))
27+
fmt.Fprintln(v, version.ColorLogo())
28+
fmt.Fprintln(v, color.String(config.C.Color.Red,
29+
fmt.Sprintf(" Version: %s%s Source Code: %s\n",
30+
version.Version, version.Build, version.Website),
31+
))
2932
return nil
3033
})
3134

komanda/command/version.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package command
22

33
import (
4+
"fmt"
5+
46
"github.com/jroimartin/gocui"
57
"github.com/mephux/komanda-cli/komanda/client"
6-
"github.com/mephux/komanda-cli/komanda/ui"
8+
"github.com/mephux/komanda-cli/komanda/color"
9+
"github.com/mephux/komanda-cli/komanda/config"
10+
"github.com/mephux/komanda-cli/komanda/version"
711
)
812

913
// VersionCmd struct
@@ -19,7 +23,12 @@ func (e *VersionCmd) Metadata() CommandMetadata {
1923
// Exec version command
2024
func (e *VersionCmd) Exec(args []string) error {
2125
Server.Exec(client.StatusChannel, func(c *client.Channel, g *gocui.Gui, v *gocui.View, s *client.Server) error {
22-
client.StatusMessage(v, ui.VersionLine)
26+
client.StatusMessage(v,
27+
color.String(config.C.Color.Red,
28+
fmt.Sprintf("Version: %s%s Source Code: %s",
29+
version.Version, version.Build, version.Website),
30+
),
31+
)
2332
return nil
2433
})
2534

komanda/gui.go

+29-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package komanda
22

33
import (
4-
"fmt"
54
"log"
65
"os"
76

@@ -21,11 +20,11 @@ var Server *client.Server
2120
func Run(build string, server *client.Server) {
2221
var err error
2322

24-
ui.Name = Name
25-
ui.Logo = ColorLogo()
23+
// ui.Name = Name
24+
// ui.Logo = ColorLogo()
2625

27-
ui.VersionLine = fmt.Sprintf(" Version: %s%s Source Code: %s\n",
28-
Version, build, Website)
26+
// ui.VersionLine = fmt.Sprintf(" Version: %s%s Source Code: %s\n",
27+
// Version, build, Website)
2928

3029
g, err := gocui.NewGui(gocui.Output256)
3130

@@ -79,21 +78,43 @@ func Run(build string, server *client.Server) {
7978
log.Panicln(err)
8079
}
8180

82-
if err := g.SetKeybinding(client.StatusChannel,
83-
gocui.MouseLeft,
84-
gocui.ModNone, FocusAndResetAll); err != nil {
81+
// if err := g.SetKeybinding("",
82+
// gocui.MouseWheelUp,
83+
// gocui.ModNone, ScrollUp); err != nil {
84+
// log.Panicln(err)
85+
// }
86+
87+
// if err := g.SetKeybinding("",
88+
// gocui.MouseWheelDown,
89+
// gocui.ModNone, ScrollDown); err != nil {
90+
// log.Panicln(err)
91+
// }
92+
93+
if err := g.SetKeybinding("", gocui.KeyPgdn,
94+
gocui.ModNone, ScrollDown); err != nil {
95+
log.Panicln(err)
96+
}
97+
98+
if err := g.SetKeybinding("", gocui.KeyPgup,
99+
gocui.ModNone, ScrollUp); err != nil {
85100
log.Panicln(err)
86101
}
87102

88103
if err := g.SetKeybinding("", gocui.KeyCtrlN,
89104
gocui.ModAlt, ScrollDown); err != nil {
90105
log.Panicln(err)
91106
}
107+
92108
if err := g.SetKeybinding("", gocui.KeyCtrlP,
93109
gocui.ModAlt, ScrollUp); err != nil {
94110
log.Panicln(err)
95111
}
96112

113+
if err := g.SetKeybinding("", gocui.KeyTab,
114+
gocui.ModNone, nextViewActive); err != nil {
115+
log.Panicln(err)
116+
}
117+
97118
if err := g.SetKeybinding("", gocui.KeyCtrlN,
98119
gocui.ModNone, nextView); err != nil {
99120
log.Panicln(err)

komanda/ui/layout.go

+11-14
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,13 @@ import (
99
"github.com/mephux/komanda-cli/komanda/color"
1010
"github.com/mephux/komanda-cli/komanda/config"
1111
"github.com/mephux/komanda-cli/komanda/logger"
12+
"github.com/mephux/komanda-cli/komanda/version"
1213
)
1314

1415
var (
15-
// Logo global
16-
Logo = ""
17-
18-
// VersionLine global
19-
VersionLine = ""
20-
2116
// Server Global
2217
Server *client.Server
2318

24-
// Name for notifications
25-
Name = "komanda"
26-
2719
notify *notificator.Notificator
2820

2921
// Editor for input
@@ -35,7 +27,7 @@ func Layout(g *gocui.Gui) error {
3527
maxX, maxY := g.Size()
3628

3729
notify = notificator.New(notificator.Options{
38-
AppName: Name,
30+
AppName: version.Name,
3931
})
4032

4133
// if _, err := g.SetView("sidebar", -1, -1, int(0.2*float32(maxX)), maxY-3); err != nil {
@@ -63,10 +55,15 @@ func Layout(g *gocui.Gui) error {
6355
view.BgColor = gocui.ColorBlack
6456

6557
fmt.Fprint(view, "\n\n")
66-
fmt.Fprintln(view, Logo)
67-
fmt.Fprintln(view, color.String(config.C.Color.Green, VersionLine))
68-
69-
client.StatusMessage(view, fmt.Sprintf("Welcome to the %s IRC client.", Name))
58+
fmt.Fprintln(view, version.ColorLogo())
59+
fmt.Fprintln(view, color.String(
60+
config.C.Color.Green,
61+
fmt.Sprintf(" Version: %s%s Source Code: %s\n",
62+
version.Version, version.Build, version.Website),
63+
),
64+
)
65+
66+
client.StatusMessage(view, fmt.Sprintf("Welcome to the %s IRC client.", version.Name))
7067
client.StatusMessage(view, "Type /help for a list of commands.\n")
7168

7269
return nil

komanda/util.go

+52
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,18 @@ func simpleEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
161161

162162
if line := v.ViewBuffer(); len(line) > 0 {
163163
GetLine(Server.Gui, v)
164+
} else {
165+
if c, err := Server.Gui.View(Server.CurrentChannel); err == nil {
166+
c.Autoscroll = true
167+
}
164168
}
165169
// v.EditNewLine()
166170
// v.Rewind()
167171

172+
// case key == gocui.MouseMiddle:
173+
// nextView(Server.Gui, v)
174+
// case key == gocui.MouseRight:
175+
168176
case key == gocui.KeyArrowDown:
169177
inHistroy = true
170178

@@ -199,9 +207,11 @@ func simpleEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
199207

200208
case key == gocui.KeyCtrlA:
201209
v.SetCursor(0, 0)
210+
v.SetOrigin(0, 0)
202211
case key == gocui.KeyCtrlK:
203212
v.Clear()
204213
v.SetCursor(0, 0)
214+
v.SetOrigin(0, 0)
205215
case key == gocui.KeyCtrlE:
206216
v.SetCursor(len(v.Buffer())-1, 0)
207217
case key == gocui.KeyCtrlLsqBracket:
@@ -439,6 +449,48 @@ func nextView(g *gocui.Gui, v *gocui.View) error {
439449
return nil
440450
}
441451

452+
func nextViewActive(g *gocui.Gui, v *gocui.View) error {
453+
curView = getCurrentChannelIndex()
454+
455+
if curView >= len(Server.Channels)-1 {
456+
curView = 0
457+
}
458+
459+
for index, channel := range Server.Channels {
460+
461+
if index >= curView {
462+
if channel.Unread || channel.Highlight {
463+
464+
view, err := channel.View()
465+
466+
if err != nil {
467+
return err
468+
}
469+
470+
view.Autoscroll = true
471+
g.SetViewOnTop(view.Name())
472+
g.SetViewOnTop("header")
473+
474+
if _, err := g.SetCurrentView(channel.Name); err != nil {
475+
return err
476+
}
477+
478+
// logger.Logger.Printf("Set Current View %d\n", Server.Channels[next].Name)
479+
Server.CurrentChannel = channel.Name
480+
channel.Unread = false
481+
channel.Highlight = false
482+
483+
ui.UpdateMenuView(g)
484+
FocusInputView(g, v)
485+
return nil
486+
}
487+
}
488+
489+
}
490+
491+
return nil
492+
}
493+
442494
func prevView(g *gocui.Gui, v *gocui.View) error {
443495
curView = getCurrentChannelIndex()
444496

komanda/version.go komanda/version/version.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package komanda
1+
package version
22

33
import "github.com/mephux/komanda-cli/komanda/color"
44

@@ -19,11 +19,16 @@ const Name = "komanda"
1919
const Description = "The Komanda Command-line IRC Client"
2020

2121
// Version number
22-
const Version = "0.7.0"
22+
const Version = "0.8.0"
2323

2424
// Website number
2525
const Website = "github.com/mephux/komanda"
2626

27+
var (
28+
// Build number
29+
Build string
30+
)
31+
2732
//ColorLogo with color
2833
func ColorLogo() string {
2934
var logo string

vendor/github.com/jroimartin/gocui/keybinding.go

+5-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)