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

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
djcas9 committed Nov 24, 2016
1 parent 5864a63 commit 8d92dc0
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 38 deletions.
7 changes: 5 additions & 2 deletions komanda.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import (
"github.com/mephux/komanda-cli/komanda/client"
"github.com/mephux/komanda-cli/komanda/config"
"github.com/mephux/komanda-cli/komanda/logger"
"github.com/mephux/komanda-cli/komanda/version"
"gopkg.in/alecthomas/kingpin.v2"
)

// Build value
var Build = ""

var (
app = kingpin.New(komanda.Name, komanda.Description)
app = kingpin.New(version.Name, version.Description)
ssl = app.Flag("ssl", "enable ssl").Short('s').Bool()

insecureSkipVerify = app.
Expand All @@ -40,6 +41,8 @@ var (
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())

version.Build = Build

if p, err := common.HomeDir(); err == nil {
config.ConfigFolder = path.Join(p, config.ConfigFolder)
config.ConfigFile = path.Join(config.ConfigFolder, config.ConfigFile)
Expand All @@ -54,7 +57,7 @@ func main() {
Build = fmt.Sprintf(".%s", Build)
}

versionOutput := fmt.Sprintf("%s%s", komanda.Version, Build)
versionOutput := fmt.Sprintf("%s%s", version.Version, Build)

app.Version(versionOutput)
args, err := app.Parse(os.Args[1:])
Expand Down
2 changes: 1 addition & 1 deletion komanda/client/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (channel *Channel) AddNick(nick string) {
func (channel *Channel) Render(update bool) error {

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

if err != gocui.ErrUnknownView {
return err
Expand Down
9 changes: 6 additions & 3 deletions komanda/command/clear.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/mephux/komanda-cli/komanda/client"
"github.com/mephux/komanda-cli/komanda/color"
"github.com/mephux/komanda-cli/komanda/config"
"github.com/mephux/komanda-cli/komanda/ui"
"github.com/mephux/komanda-cli/komanda/version"
)

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

if Server.CurrentChannel == client.StatusChannel {
fmt.Fprint(v, "\n\n")
fmt.Fprintln(v, color.String(config.C.Color.Logo, ui.Logo))
fmt.Fprintln(v, color.String(config.C.Color.Red, ui.VersionLine))
fmt.Fprintln(v, version.ColorLogo())
fmt.Fprintln(v, color.String(config.C.Color.Red,
fmt.Sprintf(" Version: %s%s Source Code: %s\n",
version.Version, version.Build, version.Website),
))
} else {
fmt.Fprint(v, "\n\n")
c.NickListString(v, false)
Expand Down
9 changes: 6 additions & 3 deletions komanda/command/logo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/mephux/komanda-cli/komanda/client"
"github.com/mephux/komanda-cli/komanda/color"
"github.com/mephux/komanda-cli/komanda/config"
"github.com/mephux/komanda-cli/komanda/ui"
"github.com/mephux/komanda-cli/komanda/version"
)

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

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

Expand Down
13 changes: 11 additions & 2 deletions komanda/command/version.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package command

import (
"fmt"

"github.com/jroimartin/gocui"
"github.com/mephux/komanda-cli/komanda/client"
"github.com/mephux/komanda-cli/komanda/ui"
"github.com/mephux/komanda-cli/komanda/color"
"github.com/mephux/komanda-cli/komanda/config"
"github.com/mephux/komanda-cli/komanda/version"
)

// VersionCmd struct
Expand All @@ -19,7 +23,12 @@ func (e *VersionCmd) Metadata() CommandMetadata {
// Exec version command
func (e *VersionCmd) Exec(args []string) error {
Server.Exec(client.StatusChannel, func(c *client.Channel, g *gocui.Gui, v *gocui.View, s *client.Server) error {
client.StatusMessage(v, ui.VersionLine)
client.StatusMessage(v,
color.String(config.C.Color.Red,
fmt.Sprintf("Version: %s%s Source Code: %s",
version.Version, version.Build, version.Website),
),
)
return nil
})

Expand Down
37 changes: 29 additions & 8 deletions komanda/gui.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package komanda

import (
"fmt"
"log"
"os"

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

ui.Name = Name
ui.Logo = ColorLogo()
// ui.Name = Name
// ui.Logo = ColorLogo()

ui.VersionLine = fmt.Sprintf(" Version: %s%s Source Code: %s\n",
Version, build, Website)
// ui.VersionLine = fmt.Sprintf(" Version: %s%s Source Code: %s\n",
// Version, build, Website)

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

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

if err := g.SetKeybinding(client.StatusChannel,
gocui.MouseLeft,
gocui.ModNone, FocusAndResetAll); err != nil {
// if err := g.SetKeybinding("",
// gocui.MouseWheelUp,
// gocui.ModNone, ScrollUp); err != nil {
// log.Panicln(err)
// }

// if err := g.SetKeybinding("",
// gocui.MouseWheelDown,
// gocui.ModNone, ScrollDown); err != nil {
// log.Panicln(err)
// }

if err := g.SetKeybinding("", gocui.KeyPgdn,
gocui.ModNone, ScrollDown); err != nil {
log.Panicln(err)
}

if err := g.SetKeybinding("", gocui.KeyPgup,
gocui.ModNone, ScrollUp); err != nil {
log.Panicln(err)
}

if err := g.SetKeybinding("", gocui.KeyCtrlN,
gocui.ModAlt, ScrollDown); err != nil {
log.Panicln(err)
}

if err := g.SetKeybinding("", gocui.KeyCtrlP,
gocui.ModAlt, ScrollUp); err != nil {
log.Panicln(err)
}

if err := g.SetKeybinding("", gocui.KeyTab,
gocui.ModNone, nextViewActive); err != nil {
log.Panicln(err)
}

if err := g.SetKeybinding("", gocui.KeyCtrlN,
gocui.ModNone, nextView); err != nil {
log.Panicln(err)
Expand Down
25 changes: 11 additions & 14 deletions komanda/ui/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,13 @@ import (
"github.com/mephux/komanda-cli/komanda/color"
"github.com/mephux/komanda-cli/komanda/config"
"github.com/mephux/komanda-cli/komanda/logger"
"github.com/mephux/komanda-cli/komanda/version"
)

var (
// Logo global
Logo = ""

// VersionLine global
VersionLine = ""

// Server Global
Server *client.Server

// Name for notifications
Name = "komanda"

notify *notificator.Notificator

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

notify = notificator.New(notificator.Options{
AppName: Name,
AppName: version.Name,
})

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

fmt.Fprint(view, "\n\n")
fmt.Fprintln(view, Logo)
fmt.Fprintln(view, color.String(config.C.Color.Green, VersionLine))

client.StatusMessage(view, fmt.Sprintf("Welcome to the %s IRC client.", Name))
fmt.Fprintln(view, version.ColorLogo())
fmt.Fprintln(view, color.String(
config.C.Color.Green,
fmt.Sprintf(" Version: %s%s Source Code: %s\n",
version.Version, version.Build, version.Website),
),
)

client.StatusMessage(view, fmt.Sprintf("Welcome to the %s IRC client.", version.Name))
client.StatusMessage(view, "Type /help for a list of commands.\n")

return nil
Expand Down
52 changes: 52 additions & 0 deletions komanda/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,18 @@ func simpleEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {

if line := v.ViewBuffer(); len(line) > 0 {
GetLine(Server.Gui, v)
} else {
if c, err := Server.Gui.View(Server.CurrentChannel); err == nil {
c.Autoscroll = true
}
}
// v.EditNewLine()
// v.Rewind()

// case key == gocui.MouseMiddle:
// nextView(Server.Gui, v)
// case key == gocui.MouseRight:

case key == gocui.KeyArrowDown:
inHistroy = true

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

case key == gocui.KeyCtrlA:
v.SetCursor(0, 0)
v.SetOrigin(0, 0)
case key == gocui.KeyCtrlK:
v.Clear()
v.SetCursor(0, 0)
v.SetOrigin(0, 0)
case key == gocui.KeyCtrlE:
v.SetCursor(len(v.Buffer())-1, 0)
case key == gocui.KeyCtrlLsqBracket:
Expand Down Expand Up @@ -439,6 +449,48 @@ func nextView(g *gocui.Gui, v *gocui.View) error {
return nil
}

func nextViewActive(g *gocui.Gui, v *gocui.View) error {
curView = getCurrentChannelIndex()

if curView >= len(Server.Channels)-1 {
curView = 0
}

for index, channel := range Server.Channels {

if index >= curView {
if channel.Unread || channel.Highlight {

view, err := channel.View()

if err != nil {
return err
}

view.Autoscroll = true
g.SetViewOnTop(view.Name())
g.SetViewOnTop("header")

if _, err := g.SetCurrentView(channel.Name); err != nil {
return err
}

// logger.Logger.Printf("Set Current View %d\n", Server.Channels[next].Name)
Server.CurrentChannel = channel.Name
channel.Unread = false
channel.Highlight = false

ui.UpdateMenuView(g)
FocusInputView(g, v)
return nil
}
}

}

return nil
}

func prevView(g *gocui.Gui, v *gocui.View) error {
curView = getCurrentChannelIndex()

Expand Down
9 changes: 7 additions & 2 deletions komanda/version.go → komanda/version/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package komanda
package version

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

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

// Version number
const Version = "0.7.0"
const Version = "0.8.0"

// Website number
const Website = "github.com/mephux/komanda"

var (
// Build number
Build string
)

//ColorLogo with color
func ColorLogo() string {
var logo string
Expand Down
8 changes: 5 additions & 3 deletions vendor/github.com/jroimartin/gocui/keybinding.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8d92dc0

Please sign in to comment.