@ -344,23 +344,26 @@ func (c *client) simpleCommand(action string) {
case "SEARCH" :
c . search ( "" , "" , "?" )
case "HELP" , "?" :
go c . Visit ( helplocation )
c . Visit ( helplocation )
default :
c . SetMessage ( fmt . Sprintf ( "Unknown action %q" , action ) , true )
c . SetMessage ( syntaxErrorMessage ( action ) , true )
c . DrawMessage ( )
}
}
func ( c * client ) doCommand ( action string , values [ ] string ) {
if length := len ( values ) ; length != 1 {
c . SetMessage ( fmt . Sprintf ( "Expected 1 argument, received %d" , len ( values ) ) , true )
c . DrawMessage ( )
return
}
switch action {
case "CHECK " , "C" :
case "C" , "CHECK" :
c . displayConfigValue ( values [ 0 ] )
c . DrawMessage ( )
case "HELP" , "?" :
if val , ok := ERRS [ values [ 0 ] ] ; ok {
c . SetMessage ( "Usage: " + val , false )
} else {
msg := fmt . Sprintf ( "%q is not a valid command; help syntax: %s" , values [ 0 ] , ERRS [ action ] )
c . SetMessage ( msg , false )
}
c . DrawMessage ( )
case "PURGE" , "P" :
err := c . Certs . Purge ( values [ 0 ] )
if err != nil {
@ -405,24 +408,22 @@ func (c *client) doCommand(action string, values []string) {
c . saveFile ( u , fn )
default :
c . SetMessage ( fmt . Sprintf ( "Unknown action %q" , action ) , true )
c . SetMessage ( syntaxErrorMessage ( action ) , true )
c . DrawMessage ( )
}
}
func ( c * client ) doCommandAs ( action string , values [ ] string ) {
if len ( values ) < 2 {
c . SetMessage ( fmt . Sprintf ( "Expected 2+ arguments, received %d" , len ( values ) ) , true )
c . DrawMessage ( )
return
}
if values [ 0 ] == "." {
values [ 0 ] = c . PageState . History [ c . PageState . Position ] . Location . Full
}
switch action {
case "ADD" , "A" :
if len ( values ) < 2 {
c . SetMessage ( syntaxErrorMessage ( action ) , true )
c . DrawMessage ( )
return
}
if values [ 0 ] == "." {
values [ 0 ] = c . PageState . History [ c . PageState . Position ] . Location . Full
}
msg , err := c . BookMarks . Add ( values )
if err != nil {
c . SetMessage ( err . Error ( ) , true )
@ -441,8 +442,18 @@ func (c *client) doCommandAs(action string, values []string) {
c . Draw ( )
}
case "SEARCH" :
if len ( values ) < 2 {
c . SetMessage ( syntaxErrorMessage ( action ) , true )
c . DrawMessage ( )
return
}
c . search ( strings . Join ( values , " " ) , "" , "" )
case "SET" , "S" :
if len ( values ) < 2 {
c . SetMessage ( syntaxErrorMessage ( action ) , true )
c . DrawMessage ( )
return
}
if _ , ok := c . Options [ values [ 0 ] ] ; ok {
val := strings . Join ( values [ 1 : ] , " " )
if ! validateOpt ( values [ 0 ] , val ) {
@ -473,7 +484,7 @@ func (c *client) doCommandAs(action string, values []string) {
c . SetMessage ( fmt . Sprintf ( "Unable to set %s, it does not exist" , values [ 0 ] ) , true )
c . DrawMessage ( )
default :
c . SetMessage ( fmt . Sprintf ( "Unknown command structure" ) , true )
c . SetMessage ( syntaxErrorMessage ( action ) , true )
c . DrawMessage ( )
}
}
@ -523,7 +534,7 @@ func (c *client) doLinkCommandAs(action, target string, values []string) {
out = append ( out , values ... )
c . doCommandAs ( action , out )
default :
c . SetMessage ( fmt . Sprintf ( "Unknown command structure" ) , true )
c . SetMessage ( syntaxErrorMessage ( action ) , true )
c . DrawMessage ( )
}
}
@ -655,7 +666,7 @@ func (c *client) doLinkCommand(action, target string) {
}
c . saveFile ( u , fn )
default :
c . SetMessage ( "Unknown command structure" , true )
c . SetMessage ( syntaxErrorMessage ( action ) , true )
c . DrawMessage ( )
}
@ -977,6 +988,7 @@ func (c *client) handleGemini(u Url) {
case 2 :
// Success
if capsule . MimeMaj == "text" || ( c . Options [ "showimages" ] == "true" && capsule . MimeMaj == "image" ) {
u . Mime = capsule . MimeMin
pg := MakePage ( u , capsule . Content , capsule . Links )
pg . FileType = capsule . MimeMaj
pg . WrapContent ( c . Width - 1 , ( c . Options [ "theme" ] == "color" ) )
@ -1203,6 +1215,13 @@ func findAvailableFileName(fpath, fname string) (string, error) {
return savePath , nil
}
func syntaxErrorMessage ( action string ) string {
if val , ok := ERRS [ action ] ; ok {
return fmt . Sprintf ( "Incorrect syntax. Try: %s" , val )
}
return fmt . Sprintf ( "Unknown command %q" , action )
}
func updateTimeouts ( timeoutString string ) error {
sec , err := strconv . Atoi ( timeoutString )
if err != nil {