mirror of
https://github.com/IllusionMan1212/gorc.git
synced 2026-10-24 02:12:33 +00:00
refactor: handle slash commands in a separate function
* quit gorc when "/quit" is sent * move tea commands into their own package * other small fixes
This commit is contained in:
+4
-3
@@ -19,6 +19,7 @@ package app
|
||||
import (
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/illusionman1212/gorc/cmds"
|
||||
"github.com/illusionman1212/gorc/irc"
|
||||
"github.com/illusionman1212/gorc/irc/handler"
|
||||
"github.com/illusionman1212/gorc/ui"
|
||||
@@ -69,7 +70,7 @@ func (s State) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "ctrl+c":
|
||||
return s, s.Quit
|
||||
return s, cmds.Quit(s.Client)
|
||||
}
|
||||
|
||||
case tea.WindowSizeMsg:
|
||||
@@ -80,7 +81,7 @@ func (s State) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
s.UI.MainScreen.SetSize(msg.Width, msg.Height)
|
||||
|
||||
return s, nil
|
||||
case login.ConnectingMsg:
|
||||
case cmds.ConnectMsg:
|
||||
host := s.UI.Login.Inputs[0].Value()
|
||||
port := s.UI.Login.Inputs[1].Value()
|
||||
channel := s.UI.Login.Inputs[2].Value()
|
||||
@@ -94,7 +95,7 @@ func (s State) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
s.Client.Initialize(host, port, tlsEnabled)
|
||||
s.Client.Register(nickname, password, channel)
|
||||
|
||||
mainscreen.LastTabIndexInTabBar = len(s.Client.Channels) - 1
|
||||
s.Client.LastTabIndexInTabBar = len(s.Client.Channels) - 1
|
||||
|
||||
go handler.ReadLoop(s.Client)
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
// gorc project
|
||||
// Copyright (C) 2021 IllusionMan1212
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, see https://www.gnu.org/licenses.
|
||||
|
||||
package app
|
||||
|
||||
import tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
func (s *State) Quit() tea.Msg {
|
||||
if s.Client.TcpConn != nil {
|
||||
s.Client.SendCommand("QUIT")
|
||||
}
|
||||
|
||||
return tea.Quit()
|
||||
}
|
||||
Reference in New Issue
Block a user