Skip to content

Raw mode #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions cmd/textsecure/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
unlinkdevice int
configDir string
stress int
raw bool
)

func init() {
Expand All @@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -149,7 +156,9 @@ 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)
}
}

for _, a := range msg.Attachments() {
Expand Down Expand Up @@ -194,7 +203,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,
Expand Down