feat: welcome/start docs

This commit is contained in:
2023-07-23 16:07:05 +02:00
parent fba6f7e0e0
commit 3d76d7c98b
4 changed files with 78 additions and 20 deletions

View File

@ -6,6 +6,15 @@ import (
tea "github.com/charmbracelet/bubbletea"
)
const cmdHelp = `/clear
/connect
/help
/profile create <name> <password> <password>
/profile info
/profile unlock <password>
/start
/quit`
func isHelpCmd(cmds []string) bool {
if cmds[0] == "help" {
return true
@ -20,6 +29,13 @@ func isQuitCmd(cmds []string) bool {
return false
}
func isStartCmd(cmds []string) bool {
if cmds[0] == "start" {
return true
}
return false
}
func isProfileCreateCmd(cmds []string) bool {
if cmds[0] == "profile" && cmds[1] == "create" {
return true
@ -65,6 +81,9 @@ func handleCommand(cmd, hiddenInput string) tea.Msg {
case isQuitCmd(cmds):
return shutdownMsg{}
case isStartCmd(cmds):
return startMsg{}
case isProfileCreateCmd(cmds):
if len(cmds) != 5 {
return cmdMsg{output: strings.Split(cmdHelp, "\n")}

10
main.go
View File

@ -20,15 +20,7 @@ const (
A text-based user interface for metadata resistant online chat.
Options:
-h output help
`
cmdHelp = `/clear
/connect
/help
/profile create <name> <password> <password>
/profile info
/profile unlock <password>
/quit`
-h output help `
)
func main() {

View File

@ -24,6 +24,8 @@ type cmdMsg struct{ output []string }
type offlineMsg struct{}
type startMsg struct{}
type stillConnectingMsg struct{}
type shutdownMsg struct{}

View File

@ -13,6 +13,39 @@ import (
"github.com/charmbracelet/lipgloss"
)
const (
welcomeMessage = `
_________ ________ ____ ______
/ ____/ | / _/ __ \/ __ \/ ____/
/ / / /| | / // /_/ / / / / __/
/ /___/ ___ |_/ // _, _/ /_/ / /___
\____/_/ |_/___/_/ |_/_____/_____/
Metadata resistant messaging
pre-alpha v0.1.0
Run /start for the getting started guide
Use the /help command to see the command listing
`
gettingStartedMessage = `
== Getting started guide ==
Welcome to Cairde, a text based user interface (TUI) for metadata resistant
messaging. In order to get started, you'll need to connect to the Tor network,
initialise Cwtch and create your first profile. It's easy!
1. Type /connect to start your Tor engines and initialise Cwtch.
2. Type "/profile create <name> <password> <password>" to create a profile.
Please replace <...> with your own name/passwords.
TODO:
* how to invite contacts
* how to toggle contact via menu
`
)
type model struct {
username string
userDir string
@ -28,6 +61,8 @@ type model struct {
width int
height int
showWelcomeMessage bool
statusViewport viewport.Model
profiles profiles
@ -46,13 +81,14 @@ func newModel(username, homeDir string) model {
input.Focus()
return model{
username: username,
userDir: path.Join(homeDir, "/.cairde/"),
connState: offline,
menuBar: []string{"status"},
menuState: 0,
input: input,
statusBuffer: make(chan string),
username: username,
userDir: path.Join(homeDir, "/.cairde/"),
connState: offline,
menuBar: []string{"status"},
menuState: 0,
input: input,
statusBuffer: make(chan string),
showWelcomeMessage: true,
}
}
@ -102,6 +138,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds = append(cmds, cmd)
}
if m.showWelcomeMessage {
cmds = append(cmds, m.sendStatusCmd(
strings.Split(welcomeMessage, "\n")...,
))
m.showWelcomeMessage = false
}
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width - 2
@ -161,6 +204,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.input.Reset()
cmds = append(cmds, m.sendStatusCmd("conn: initialising, please hold"))
case startMsg:
cmds = append(cmds, m.sendStatusCmd(
strings.Split(gettingStartedMessage, "\n")...,
))
m.input.Reset()
case shutdownMsg:
m.input.Reset()
return m, tea.Quit
@ -267,10 +316,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.app = msg.app
m.acn = msg.acn
m.connState = connected
cmds = append(cmds, m.sendStatusCmd(
"create or unlock a profile to get started",
"run /help to see the command listing",
))
case errMsg:
cmds = append(cmds, m.sendStatusCmd(msg.Error()))