rewrote quoteAnswer
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// =============================================================================
|
||||
// Auth: alex
|
||||
// File: client.go
|
||||
// Revn: 09-06-2026 3.0.0
|
||||
// Revn: 09-12-2026 3.0.2
|
||||
// Func: ask server for a message of the day quote
|
||||
//
|
||||
// TODO: remove ioutil import
|
||||
@@ -43,6 +43,10 @@
|
||||
// 09-04-2026: rewrote in() with bufio instead of scanln
|
||||
//#09-06-2026: fixed blank message error in secondEdit()
|
||||
// comments
|
||||
// 09-07-2026: added fatih/color import
|
||||
// rewrote quoteAnswer() to handle coloring escape
|
||||
// sequences
|
||||
// 09-12-2026: commented quoteAnswer()
|
||||
//
|
||||
// =============================================================================
|
||||
|
||||
@@ -60,6 +64,7 @@ import (
|
||||
"strconv" // Atoi, Itoa
|
||||
"strings" // Split
|
||||
"time" // Now, UnixNano
|
||||
"github.com/fatih/color" // color.New, Printf, Println
|
||||
)
|
||||
|
||||
|
||||
@@ -169,6 +174,74 @@ func sizeAnswer( subcom []string ) string {
|
||||
|
||||
// receive quote, print
|
||||
func quoteAnswer( subcom []string ) string {
|
||||
|
||||
// split subcommand over spaces
|
||||
words := strings.Split( subcom[0], " " )
|
||||
|
||||
// default text is white
|
||||
c := color.New( color.FgWhite )
|
||||
for _, w := range words {
|
||||
// if first char is normal color escape character
|
||||
if string( w[0] ) == "$" {
|
||||
// see which color is requested
|
||||
switch string( w[1] ) {
|
||||
case "1": // 1 -> red
|
||||
c = color.New( color.FgRed )
|
||||
case "2": // 2 -> yellow
|
||||
c = color.New( color.FgYellow )
|
||||
case "3": // 3 -> green
|
||||
c = color.New( color.FgGreen )
|
||||
case "4": // 4 -> blue
|
||||
c = color.New( color.FgBlue )
|
||||
case "5": // 5 -> cyan
|
||||
c = color.New( color.FgCyan )
|
||||
case "6": // 6 -> magenta
|
||||
c = color.New( color.FgMagenta )
|
||||
case "7": // 7 -> black
|
||||
c = color.New( color.FgBlack )
|
||||
case "0": // 0 -> white again
|
||||
c = color.New( color.FgWhite )
|
||||
default:
|
||||
// none of these, continue with the last color
|
||||
}
|
||||
// color chosen, print string with trailing space, minus
|
||||
// first two characters
|
||||
c.Printf( "%s ", w[2:] )
|
||||
// if first char is bold color escape character
|
||||
} else if string( w[0] ) == "#" {
|
||||
// see which color is requested
|
||||
switch string( w[1] ) {
|
||||
case "1": // 1 -> red
|
||||
c = color.New( color.FgRed, color.Bold )
|
||||
case "2": // 2 -> yellow
|
||||
c = color.New( color.FgYellow, color.Bold )
|
||||
case "3": // 3 -> green
|
||||
c = color.New( color.FgGreen, color.Bold )
|
||||
case "4": // 4 -> blue
|
||||
c = color.New( color.FgBlue, color.Bold )
|
||||
case "5": // 5 -> cyan
|
||||
c = color.New( color.FgCyan, color.Bold )
|
||||
case "6": // 6 -> magenta
|
||||
c = color.New( color.FgMagenta, color.Bold )
|
||||
case "7": // 7 -> black
|
||||
c = color.New( color.FgBlack, color.Bold )
|
||||
case "0": // 0 -> white again
|
||||
c = color.New( color.FgWhite, color.Bold )
|
||||
default:
|
||||
// none of these, continue with the last color
|
||||
}
|
||||
// color chosen, print string with trailing space, minus
|
||||
// first two characters
|
||||
c.Printf( "%s ", w[2:] )
|
||||
} else { // TODO add if for if w[0] is "\"
|
||||
// using the currently selected color, print the next work
|
||||
// and a trailing space
|
||||
c.Printf( "%s ", w )
|
||||
}
|
||||
}
|
||||
|
||||
c.Println() // print final newline
|
||||
|
||||
fmt.Println( subcom[0] ) // whole-ass just print quote
|
||||
return "te@success" // set transaction end message
|
||||
}
|
||||
@@ -480,7 +553,6 @@ func handle( conn net.Conn ) {
|
||||
//var qsize int // keep track of num of quotes
|
||||
var conn net.Conn // keep track of connection
|
||||
|
||||
|
||||
// global flag variables
|
||||
var add bool // add new quotes to quote file ( on server )
|
||||
var remove bool // remove quotes from quote file ( on server )
|
||||
@@ -507,7 +579,7 @@ func main() {
|
||||
flag.Parse()
|
||||
|
||||
// FIXME get better versioning method
|
||||
VERS = "3.0.0"
|
||||
VERS = "3.0.2"
|
||||
|
||||
if vv { // display info and exit
|
||||
fmt.Println( "ekho client v" + VERS )
|
||||
|
||||
Reference in New Issue
Block a user