From 77af9e8f9ef405d6ea33dd0a7f5355239ccd316c Mon Sep 17 00:00:00 2001 From: morph027 Date: Sun, 13 Aug 2017 14:14:54 +0200 Subject: [PATCH 1/2] added -raw flag, refs #30 --- cmd/textsecure/main.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cmd/textsecure/main.go b/cmd/textsecure/main.go index 59882ae..b8428cb 100644 --- a/cmd/textsecure/main.go +++ b/cmd/textsecure/main.go @@ -35,6 +35,7 @@ var ( unlinkdevice int configDir string stress int + raw bool ) func init() { @@ -51,6 +52,7 @@ func init() { flag.IntVar(&unlinkdevice, "unlinkdevice", 0, "Unlink a device, the argument is the id of the device to delete") flag.IntVar(&stress, "stress", 0, "Automatically send many messages to the peer") flag.StringVar(&configDir, "config", ".config", "Location of config dir") + flag.BoolVar(&raw, "raw", false, "raw mode, disable ansi colors") } var ( @@ -121,7 +123,12 @@ func sendAttachment(isGroup bool, to, message string, f io.Reader) error { // conversationLoop sends messages read from the console func conversationLoop(isGroup bool) { for { - message := readLine(fmt.Sprintf("%s>", blue)) + var message string + if raw { + message = readLine(fmt.Sprintf("")) + } else { + message = readLine(fmt.Sprintf("%s>", blue)) + } if message == "" { continue } @@ -149,7 +156,12 @@ func messageHandler(msg *textsecure.Message) { } if msg.Message() != "" { - fmt.Printf("\r %s%s\n>", pretty(msg), blue) + if ! raw { + fmt.Printf("\r %s%s\n>", pretty(msg), blue) + } + if hook != "" { + exec.Command(hook,msg.Message()).Start() + } } for _, a := range msg.Attachments() { @@ -194,7 +206,11 @@ func pretty(msg *textsecure.Message) string { if msg.Group() != nil { src = src + "[" + msg.Group().Name + "]" } - return fmt.Sprintf("%s%s %s%s %s%s", yellow, timestamp(msg), red, src, green, msg.Message()) + if raw { + return fmt.Sprintf("%s %s %s", timestamp(msg), src, msg.Message()) + } else { + return fmt.Sprintf("%s%s %s%s %s%s", yellow, timestamp(msg), red, src, green, msg.Message()) + } } // getName returns the local contact name corresponding to a phone number, From e5c9a9a83cb4656097e5955f0536cc838fdfb7a3 Mon Sep 17 00:00:00 2001 From: morph027 Date: Sun, 13 Aug 2017 14:35:22 +0200 Subject: [PATCH 2/2] remove too much of copy paste --- cmd/textsecure/main.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/cmd/textsecure/main.go b/cmd/textsecure/main.go index b8428cb..e103182 100644 --- a/cmd/textsecure/main.go +++ b/cmd/textsecure/main.go @@ -159,9 +159,6 @@ func messageHandler(msg *textsecure.Message) { if ! raw { fmt.Printf("\r %s%s\n>", pretty(msg), blue) } - if hook != "" { - exec.Command(hook,msg.Message()).Start() - } } for _, a := range msg.Attachments() {