@ -26,6 +26,15 @@ func (w *appWriter) Write(p []byte) (int, error) {
@@ -26,6 +26,15 @@ func (w *appWriter) Write(p []byte) (int, error) {
return n , err
}
func ( c * Client ) connect ( ) {
l ( "Connecting..." )
err := telnet . DialToAndCall ( "fibs.com:4321" , c )
if err != nil {
lf ( "disconnected: %s" , err )
}
}
func RunApp ( c * Client ) error {
app = cview . NewApplication ( )
app . EnableMouse ( true )
@ -47,16 +56,49 @@ func RunApp(c *Client) error {
@@ -47,16 +56,49 @@ func RunApp(c *Client) error {
f . AddItem ( statusBuffer , 0 , 1 , false )
f . AddItem ( inputField , 1 , 1 , true )
app . SetRoot ( f , true )
form := cview . NewForm ( )
usernameField := cview . NewInputField ( )
usernameField . SetLabel ( "Username" )
usernameField . SetFieldWidth ( 16 )
passwordField := cview . NewInputField ( )
passwordField . SetLabel ( "Password" )
passwordField . SetFieldWidth ( 16 )
passwordField . SetMaskCharacter ( '*' )
form . AddFormItem ( usernameField )
form . AddFormItem ( passwordField )
form . AddButton ( "Connect" , func ( ) {
c . username = usernameField . GetText ( )
c . password = passwordField . GetText ( )
app . SetRoot ( f , true )
app . SetFocus ( inputField )
go c . connect ( )
} )
form . SetPadding ( 1 , 0 , 2 , 0 )
logInHeader := cview . NewTextView ( )
logInHeader . SetDynamicColors ( true )
logInHeader . SetText ( "\n [" + cview . ColorHex ( cview . Styles . SecondaryTextColor ) + "] Connect to FIBS[-]" )
logInFooter := cview . NewTextView ( )
logInFooter . SetText ( " For information on how to play backgammon, visit\n https://bkgm.com/rules.html\n\n For information on how to register, visit\n http://www.fibs.com/help.html#register\n\n For information on bgammon (this FIBS client), visit\n https://code.rocketnine.space/tslocum/bgammon" )
f2 := cview . NewFlex ( ) // Login flex
f2 . SetDirection ( cview . FlexRow )
f2 . AddItem ( logInHeader , 2 , 1 , true )
f2 . AddItem ( form , 8 , 1 , true )
f2 . AddItem ( logInFooter , 0 , 1 , true )
app . SetFocus ( inputField )
if c . username == "" || c . password == "" {
app . SetRoot ( f2 , true )
app . SetFocus ( form )
} else {
app . SetRoot ( f , true )
app . SetFocus ( inputField )
go func ( ) {
err := telnet . DialToAndCall ( "fibs.com:4321" , c )
if err != nil {
lf ( "disconnected: %s" , err )
}
} ( )
go c . connect ( )
}
return app . Run ( )
}