Esempio n. 1
0
func (e *WindowCmd) Exec(args []string) error {
	Server.Exec(client.StatusChannel, func(g *gocui.Gui, v *gocui.View, s *client.Server) error {

		if !s.Client.Connected() {
			client.StatusMessage(v, "Not connected")
			return nil
		}

		if len(args) == 2 {
			i := common.StringTo(args[1]).MustInt()

			Server.CurrentChannel = Server.Channels[i].Name
			Server.Gui.SetViewOnTop(Server.CurrentChannel)

			c := Server.GetCurrentChannel()

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

			c.Unread = false

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

			ui.UpdateMenuView(g)
		}

		return nil
	})

	return nil
}
Esempio n. 2
0
func prevView(g *gocui.Gui, v *gocui.View) error {
	curView = getCurrentChannelIndex()

	next := curView - 1

	if next < 0 {
		next = len(Server.Channels) - 1
	}

	logger.Logger.Printf("PREV INDEX %d\n", next)

	if newView, err := g.View(Server.Channels[next].Name); err != nil {
		return err
	} else {
		newView.Autoscroll = true
		g.SetViewOnTop(newView.Name())
		g.SetViewOnTop("header")
	}

	if _, err := g.SetCurrentView(Server.Channels[next].Name); err != nil {
		return err
	}

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

	ui.UpdateMenuView(g)
	FocusInputView(g, v)

	curView = next
	return nil
}
Esempio n. 3
0
func (e *PartCmd) Exec(args []string) error {
	Server.Exec(client.StatusChannel, func(g *gocui.Gui, v *gocui.View, s *client.Server) error {

		if !s.Client.Connected() {
			client.StatusMessage(v, "Not connected")
			return nil
		}

		if len(args) >= 2 {

			if args[1] == client.StatusChannel {
				return nil
			}

			s.Client.Part(args[1])

			index, err := s.RemoveChannel(args[1])

			if len(s.Channels) <= 1 {
				CurrentChannel = client.StatusChannel
				Server.CurrentChannel = client.StatusChannel
				Server.Gui.SetViewOnTop(client.StatusChannel)
			} else {
				Server.CurrentChannel = Server.Channels[index-1].Name
				Server.Gui.SetViewOnTop(Server.CurrentChannel)

				c := Server.GetCurrentChannel()

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

				c.Unread = false
			}

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

			ui.UpdateMenuView(g)

			return err
		}

		return nil
	})

	return nil
}