added color print flag and fixed "only edit" bug
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// =============================================================================
|
// =============================================================================
|
||||||
// Auth: alex
|
// Auth: alex
|
||||||
// File: client.go
|
// File: client.go
|
||||||
// Revn: 09-12-2026 3.0.2
|
// Revn: 09-15-2026 3.0.3
|
||||||
// Func: ask server for a message of the day quote
|
// Func: ask server for a message of the day quote
|
||||||
//
|
//
|
||||||
// TODO: remove ioutil import
|
// TODO: remove ioutil import
|
||||||
@@ -46,7 +46,11 @@
|
|||||||
// 09-07-2026: added fatih/color import
|
// 09-07-2026: added fatih/color import
|
||||||
// rewrote quoteAnswer() to handle coloring escape
|
// rewrote quoteAnswer() to handle coloring escape
|
||||||
// sequences
|
// sequences
|
||||||
// 09-12-2026: commented quoteAnswer()
|
//*09-12-2026: commented quoteAnswer()
|
||||||
|
//*09-15-2026: added -c flag and color code example printing
|
||||||
|
// changed edit command to be add and then remove instead
|
||||||
|
// of remove and then add, fixing server OOB error when
|
||||||
|
// editting only quote in list
|
||||||
//
|
//
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
@@ -242,7 +246,7 @@ func quoteAnswer( subcom []string ) string {
|
|||||||
|
|
||||||
c.Println() // print final newline
|
c.Println() // print final newline
|
||||||
|
|
||||||
fmt.Println( subcom[0] ) // whole-ass just print quote
|
//fmt.Println( subcom[0] ) // whole-ass just print quote
|
||||||
return "te@success" // set transaction end message
|
return "te@success" // set transaction end message
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,16 +392,18 @@ func secondEdit( subcom []string ) string {
|
|||||||
return "te@success"
|
return "te@success"
|
||||||
}
|
}
|
||||||
|
|
||||||
// edit command is a removal and an add
|
// edit command is an add and then a removal
|
||||||
var resp string
|
var resp string
|
||||||
resp = "cr@r2@" + subcom[0] + "@ar@"
|
resp = "cr@ar@"
|
||||||
// server response is text to be edited
|
|
||||||
fmt.Println( "as is: " + subcom[1] )
|
fmt.Println( "as is: " + subcom[1] )
|
||||||
fmt.Print( "preview: " ) // won't be useful until pretty print
|
fmt.Print( "preview: " ) // show raw of current quote
|
||||||
_ = quoteAnswer( subcom[1:] ) // display quote properly
|
_ = quoteAnswer( subcom[1:] ) // display quote properly
|
||||||
|
|
||||||
// get user input for new quote and send
|
// server response is user input for new quote
|
||||||
resp = resp + in( "\nupdate -> " )
|
resp = resp + in( "\nupdate -> " )
|
||||||
|
// and position of old quote to be removed
|
||||||
|
resp = resp + "@r2@" + subcom[0]
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,6 +564,7 @@ var add bool // add new quotes to quote file ( on server )
|
|||||||
var remove bool // remove quotes from quote file ( on server )
|
var remove bool // remove quotes from quote file ( on server )
|
||||||
var list bool // request entire quote file from server
|
var list bool // request entire quote file from server
|
||||||
var edit bool // edit a pre-existing quote from quote file ( on server )
|
var edit bool // edit a pre-existing quote from quote file ( on server )
|
||||||
|
var co bool // list color codes
|
||||||
var dest string // provide a new destination ip and port
|
var dest string // provide a new destination ip and port
|
||||||
var tsize int // size of transmission buffer
|
var tsize int // size of transmission buffer
|
||||||
var VERS string // version
|
var VERS string // version
|
||||||
@@ -568,18 +575,19 @@ func main() {
|
|||||||
var vv bool // big version flag
|
var vv bool // big version flag
|
||||||
|
|
||||||
// define flags
|
// define flags
|
||||||
flag.BoolVar( &add, "a", false, "add quote to list" )
|
flag.BoolVar( &add, "a", false, "add quote to list" )
|
||||||
flag.BoolVar( &remove, "r", false, "remove quote from list" )
|
flag.BoolVar( &remove, "r", false, "remove quote from list" )
|
||||||
flag.BoolVar( &list, "l", false, "print quote list" )
|
flag.BoolVar( &list, "l", false, "print quote list" )
|
||||||
flag.BoolVar( &edit, "e", false, "edit quote from list" )
|
flag.BoolVar( &edit, "e", false, "edit quote from list" )
|
||||||
flag.StringVar( &dest, "ip", "127.0.0.1:1300", "ip:port of server" )
|
flag.BoolVar( &co, "c", false, "list color codes with examples" )
|
||||||
flag.IntVar( &tsize, "s", 256, "transmission size ( bytes )" )
|
flag.StringVar( &dest, "ip", "127.0.0.1:1300", "ip:port of server" )
|
||||||
flag.BoolVar( &v, "v", false, "display version and exit" )
|
flag.IntVar( &tsize, "s", 256, "transmission size ( bytes )" )
|
||||||
flag.BoolVar( &vv, "vv", false, "display version and about info and exit" )
|
flag.BoolVar( &v, "v", false, "display version and exit" )
|
||||||
|
flag.BoolVar( &vv, "vv", false, "display version and about info and exit" )
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// FIXME get better versioning method
|
// FIXME get better versioning method
|
||||||
VERS = "3.0.2"
|
VERS = "3.0.3"
|
||||||
|
|
||||||
if vv { // display info and exit
|
if vv { // display info and exit
|
||||||
fmt.Println( "ekho client v" + VERS )
|
fmt.Println( "ekho client v" + VERS )
|
||||||
@@ -592,6 +600,54 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if co { // display color codes and examples and quit
|
||||||
|
// print color code and color example on same line
|
||||||
|
// color.XYZ print inserts newline
|
||||||
|
fmt.Print( "$1: " )
|
||||||
|
color.Red( "red" )
|
||||||
|
fmt.Print( "$2: " )
|
||||||
|
color.Yellow( "yellow" )
|
||||||
|
fmt.Print( "$3: " )
|
||||||
|
color.Green( "green" )
|
||||||
|
fmt.Print( "$4: " )
|
||||||
|
color.Blue( "blue" )
|
||||||
|
fmt.Print( "$5: " )
|
||||||
|
color.Cyan( "cyan" )
|
||||||
|
fmt.Print( "$6: " )
|
||||||
|
color.Magenta( "magenta" )
|
||||||
|
fmt.Print( "$7: " )
|
||||||
|
color.Black( "black" )
|
||||||
|
fmt.Print( "$0: " )
|
||||||
|
color.White( "white (reset)" )
|
||||||
|
// print bold codes
|
||||||
|
fmt.Print( "\n#1: " )
|
||||||
|
// create bold color object, change out actual color and print
|
||||||
|
bold := color.New( color.Bold, color.FgRed )
|
||||||
|
bold.Println( "bold red" )
|
||||||
|
fmt.Print( "#2: " )
|
||||||
|
bold.Add( color.FgYellow )
|
||||||
|
bold.Println( "bold yellow" )
|
||||||
|
fmt.Print( "#3: " )
|
||||||
|
bold.Add( color.FgGreen )
|
||||||
|
bold.Println( "bold green" )
|
||||||
|
fmt.Print( "#4: " )
|
||||||
|
bold.Add( color.FgBlue )
|
||||||
|
bold.Println( "bold blue" )
|
||||||
|
fmt.Print( "#5: " )
|
||||||
|
bold.Add( color.FgCyan )
|
||||||
|
bold.Println( "bold Cyan" )
|
||||||
|
fmt.Print( "#6: " )
|
||||||
|
bold.Add( color.FgMagenta )
|
||||||
|
bold.Println( "bold magenta" )
|
||||||
|
fmt.Print( "#7: " )
|
||||||
|
bold.Add( color.FgBlack )
|
||||||
|
bold.Println( "bold black" )
|
||||||
|
fmt.Print( "#0: " )
|
||||||
|
bold.Add( color.FgWhite )
|
||||||
|
bold.Println( "bold white" )
|
||||||
|
return // bail
|
||||||
|
}
|
||||||
|
|
||||||
service := dest // declare server ip:port
|
service := dest // declare server ip:port
|
||||||
|
|
||||||
// create address object
|
// create address object
|
||||||
|
|||||||
Reference in New Issue
Block a user