mirror of
https://github.com/IllusionMan1212/gorc.git
synced 2026-10-24 02:12:33 +00:00
WIP: working on adding inputbox and wrapping the messages in a viewport
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
# binary
|
||||||
|
gorc
|
||||||
@@ -24,7 +24,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := tea.NewProgram(app.InitialState(), tea.WithAltScreen()).Start(); err != nil {
|
if err := tea.NewProgram(app.InitialState(),
|
||||||
|
tea.WithAltScreen(),
|
||||||
|
tea.WithMouseCellMotion(),
|
||||||
|
).Start(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ func initialUiState() UI {
|
|||||||
|
|
||||||
return UI{
|
return UI{
|
||||||
login: login.NewLogin(),
|
login: login.NewLogin(),
|
||||||
|
mainScreen: mainscreen.NewMainScreen(),
|
||||||
windowWidth: width,
|
windowWidth: width,
|
||||||
windowHeight: height,
|
windowHeight: height,
|
||||||
}
|
}
|
||||||
@@ -100,6 +101,9 @@ func (s State) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
Width(msg.Width).
|
Width(msg.Width).
|
||||||
Height(msg.Height)
|
Height(msg.Height)
|
||||||
|
|
||||||
|
s.ui.mainScreen.Viewport.Width = msg.Width
|
||||||
|
s.ui.mainScreen.Viewport.Height = msg.Height - mainscreen.InputBoxHeight
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
case login.ConnectingMsg:
|
case login.ConnectingMsg:
|
||||||
host := s.ui.login.Inputs[0].Value()
|
host := s.ui.login.Inputs[0].Value()
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ func NewLogin() State {
|
|||||||
for i := range ls.Inputs {
|
for i := range ls.Inputs {
|
||||||
t = textinput.NewModel()
|
t = textinput.NewModel()
|
||||||
t.CursorStyle = ui.CursorStyle
|
t.CursorStyle = ui.CursorStyle
|
||||||
|
t.Prompt = "| "
|
||||||
|
|
||||||
switch i {
|
switch i {
|
||||||
case 0:
|
case 0:
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// 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 mainscreen
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/charmbracelet/bubbles/textinput"
|
||||||
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
|
)
|
||||||
|
|
||||||
|
type InputState struct {
|
||||||
|
input textinput.Model
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewInputBox() InputState {
|
||||||
|
var input textinput.Model
|
||||||
|
input.Placeholder = "Send a message..."
|
||||||
|
state := InputState{input}
|
||||||
|
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s InputState) Update(msg tea.Msg) (InputState, tea.Cmd) {
|
||||||
|
return s, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s InputState) View() string {
|
||||||
|
return InputboxStyle.Render(s.input.View())
|
||||||
|
}
|
||||||
@@ -21,25 +21,49 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/charmbracelet/bubbles/viewport"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/illusionman1212/gorc/client"
|
"github.com/illusionman1212/gorc/client"
|
||||||
"github.com/illusionman1212/gorc/parser"
|
"github.com/illusionman1212/gorc/parser"
|
||||||
|
"github.com/illusionman1212/gorc/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
content string
|
Content string
|
||||||
Reader *bufio.Reader
|
Reader *bufio.Reader
|
||||||
Client *client.Client
|
Client *client.Client
|
||||||
|
Viewport viewport.Model
|
||||||
|
|
||||||
|
inputBox InputState
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMainScreen() State {
|
||||||
|
newViewport := viewport.Model{Width: ui.MainStyle.GetWidth(), Height: ui.MainStyle.GetHeight() - InputBoxHeight}
|
||||||
|
newViewport.HighPerformanceRendering = false
|
||||||
|
newViewport.SetContent("")
|
||||||
|
|
||||||
|
state := State{
|
||||||
|
Content: "",
|
||||||
|
Reader: nil,
|
||||||
|
Client: nil,
|
||||||
|
Viewport: newViewport,
|
||||||
|
inputBox: NewInputBox(),
|
||||||
|
}
|
||||||
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
|
func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
|
||||||
|
var cmd tea.Cmd
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case InitialReadMsg:
|
case InitialReadMsg:
|
||||||
return s, s.readFromServer
|
return s, s.readFromServer
|
||||||
case ReceivedIRCCommandMsg:
|
case ReceivedIRCCommandMsg:
|
||||||
message := parser.ParseIRCMessage(msg.Msg)
|
message := parser.ParseIRCMessage(msg.Msg)
|
||||||
fullMsg := fmt.Sprintf("%s %s %s %s", message.Tags, message.Source, message.Command, strings.Join(message.Parameters, " "))
|
fullMsg := fmt.Sprintf("%s %s %s %s", message.Tags, message.Source, message.Command, strings.Join(message.Parameters, " "))
|
||||||
s.content += fullMsg
|
s.Content += fullMsg
|
||||||
|
|
||||||
|
s.Viewport.SetContent(s.Content)
|
||||||
|
|
||||||
// TODO: handle different commands
|
// TODO: handle different commands
|
||||||
switch message.Command {
|
switch message.Command {
|
||||||
@@ -51,9 +75,15 @@ func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
|
|||||||
return s, s.readFromServer
|
return s, s.readFromServer
|
||||||
}
|
}
|
||||||
|
|
||||||
return s, nil
|
s.Viewport, cmd = s.Viewport.Update(msg)
|
||||||
|
|
||||||
|
return s, cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s State) View() string {
|
func (s State) View() string {
|
||||||
return s.content
|
mainscreen := s.Viewport.View()
|
||||||
|
|
||||||
|
screen := lipgloss.JoinVertical(0, MessagesStyle.Render(mainscreen), s.inputBox.View())
|
||||||
|
|
||||||
|
return screen
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// 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 mainscreen
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
"github.com/illusionman1212/gorc/ui"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
InputboxStyle = lipgloss.NewStyle().
|
||||||
|
Border(lipgloss.NormalBorder(), true).
|
||||||
|
Padding(0, 1).
|
||||||
|
Width(ui.MainStyle.GetWidth()).
|
||||||
|
BorderForeground(lipgloss.Color("105"))
|
||||||
|
MessagesStyle = lipgloss.NewStyle().
|
||||||
|
Border(lipgloss.NormalBorder(), true).
|
||||||
|
Width(ui.MainStyle.GetWidth()).
|
||||||
|
Height(ui.MainStyle.GetHeight() - InputBoxHeight).
|
||||||
|
BorderForeground(lipgloss.Color("105"))
|
||||||
|
|
||||||
|
InputBoxHeight = 1
|
||||||
|
)
|
||||||
+2
-2
@@ -19,7 +19,7 @@ package ui
|
|||||||
import "github.com/charmbracelet/lipgloss"
|
import "github.com/charmbracelet/lipgloss"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Border = lipgloss.Border{
|
BorderRound = lipgloss.Border{
|
||||||
Top: "─",
|
Top: "─",
|
||||||
Bottom: "─",
|
Bottom: "─",
|
||||||
Left: "│",
|
Left: "│",
|
||||||
@@ -35,7 +35,7 @@ var (
|
|||||||
Height(40)
|
Height(40)
|
||||||
|
|
||||||
DialogStyle = lipgloss.NewStyle().
|
DialogStyle = lipgloss.NewStyle().
|
||||||
Border(Border, true).
|
Border(BorderRound, true).
|
||||||
Align(lipgloss.Center).
|
Align(lipgloss.Center).
|
||||||
Width(50).
|
Width(50).
|
||||||
Padding(3, 6).
|
Padding(3, 6).
|
||||||
|
|||||||
Reference in New Issue
Block a user