use println instead of print
This commit is contained in:
25
main.go
25
main.go
@@ -115,7 +115,7 @@ func main() {
|
|||||||
app.SetFocus(textInput)
|
app.SetFocus(textInput)
|
||||||
go func() {
|
go func() {
|
||||||
if err := StartTextReceiver(); err != nil {
|
if err := StartTextReceiver(); err != nil {
|
||||||
fmt.Fprint(textView, "[red]", err, "[-]")
|
fmt.Fprintln(textView, "[red]", err, "[-]")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
app.Run()
|
app.Run()
|
||||||
@@ -123,7 +123,16 @@ func main() {
|
|||||||
|
|
||||||
// prints help to chat view
|
// prints help to chat view
|
||||||
func PrintHelp() {
|
func PrintHelp() {
|
||||||
fmt.Fprint(textView, "[::b]WhatsCLI "+VERSION+"\n\n[-][-::u]Commands:[-::-]\n/name NewName = name selected contact\n/addname 1234567 NewName = add name for number\n/load = reload contacts\n/quit = exit app\n/help = show this help\n\n[-::u]Keys:[-::-]\n<Tab> = switch input/contacts\n<Up/Dn> = scroll history\n\n")
|
fmt.Fprintln(textView, "[::b]WhatsCLI "+VERSION+"\n\n[-]")
|
||||||
|
fmt.Fprintln(textView, "[-::u]Commands:[-::-]")
|
||||||
|
fmt.Fprintln(textView, "/name NewName = name selected contact")
|
||||||
|
fmt.Fprintln(textView, "/addname 1234567 NewName = add name for number")
|
||||||
|
fmt.Fprintln(textView, "/load = reload contacts")
|
||||||
|
fmt.Fprintln(textView, "/quit = exit app")
|
||||||
|
fmt.Fprintln(textView, "/help = show this help\n")
|
||||||
|
fmt.Fprintln(textView, "[-::u]Keys:[-::-]")
|
||||||
|
fmt.Fprintln(textView, "<Tab> = switch input/contacts")
|
||||||
|
fmt.Fprintln(textView, "<Up/Dn> = scroll history\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
// called when text is entered by the user
|
// called when text is entered by the user
|
||||||
@@ -152,7 +161,7 @@ func EnterCommand(key tcell.Key) {
|
|||||||
//command
|
//command
|
||||||
parts := strings.Split(sndTxt, " ")
|
parts := strings.Split(sndTxt, " ")
|
||||||
if len(parts) < 3 {
|
if len(parts) < 3 {
|
||||||
fmt.Fprint(textView, "Use /addname 1234567 NewName\n")
|
fmt.Fprintln(textView, "Use /addname 1234567 NewName")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
messages.SetIdName(parts[1]+messages.CONTACTSUFFIX, strings.TrimPrefix(sndTxt, "/addname "+parts[1]+" "))
|
messages.SetIdName(parts[1]+messages.CONTACTSUFFIX, strings.TrimPrefix(sndTxt, "/addname "+parts[1]+" "))
|
||||||
@@ -162,7 +171,7 @@ func EnterCommand(key tcell.Key) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if currentReceiver == "" {
|
if currentReceiver == "" {
|
||||||
fmt.Fprint(textView, "[red]no contact selected[-]\n")
|
fmt.Fprintln(textView, "[red]no contact selected[-]")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if strings.Index(sndTxt, "/name ") == 0 {
|
if strings.Index(sndTxt, "/name ") == 0 {
|
||||||
@@ -269,7 +278,7 @@ func StartTextReceiver() error {
|
|||||||
messages.SetIdName(contact.Jid, contact.Name)
|
messages.SetIdName(contact.Jid, contact.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Fprint(textView, "closing the receiver\n")
|
fmt.Fprintln(textView, "closing the receiver")
|
||||||
wac.Disconnect()
|
wac.Disconnect()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -292,7 +301,7 @@ func SendText(wid string, text string) {
|
|||||||
msgStore.AddTextMessage(msg)
|
msgStore.AddTextMessage(msg)
|
||||||
connection.AddHandler(handler)
|
connection.AddHandler(handler)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprint(textView, "[red]error sending message: ", err, "\n[-]")
|
fmt.Fprintln(textView, "[red]error sending message: ", err, "[-]")
|
||||||
} else {
|
} else {
|
||||||
//fmt.Fprint(textView, "Sent msg with ID: ", msgID, "\n")
|
//fmt.Fprint(textView, "Sent msg with ID: ", msgID, "\n")
|
||||||
}
|
}
|
||||||
@@ -304,7 +313,7 @@ type textHandler struct{}
|
|||||||
// HandleError implements the error handler interface for go-whatsapp
|
// HandleError implements the error handler interface for go-whatsapp
|
||||||
func (t textHandler) HandleError(err error) {
|
func (t textHandler) HandleError(err error) {
|
||||||
// TODO : handle go routine here
|
// TODO : handle go routine here
|
||||||
fmt.Fprint(textView, "[red]error in textHandler : ", err, "\n[-]")
|
fmt.Fprintln(textView, "[red]error in textHandler : ", err, "[-]")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +329,7 @@ func (t textHandler) HandleTextMessage(msg whatsapp.TextMessage) {
|
|||||||
|
|
||||||
// prints a text message to the TextView
|
// prints a text message to the TextView
|
||||||
func PrintTextMessage(msg whatsapp.TextMessage) {
|
func PrintTextMessage(msg whatsapp.TextMessage) {
|
||||||
fmt.Fprint(textView, messages.GetTextMessageString(&msg))
|
fmt.Fprintln(textView, messages.GetTextMessageString(&msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
// methods to convert messages to TextMessage
|
// methods to convert messages to TextMessage
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ func (db *MessageDatabase) GetMessagesString(wid string) string {
|
|||||||
var out = ""
|
var out = ""
|
||||||
for _, element := range (*db).textMessages[wid] {
|
for _, element := range (*db).textMessages[wid] {
|
||||||
out += GetTextMessageString(&element)
|
out += GetTextMessageString(&element)
|
||||||
|
out += "\n"
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
@@ -71,14 +72,14 @@ func GetTextMessageString(msg *whatsapp.TextMessage) string {
|
|||||||
text := tview.Escape((*msg).Text)
|
text := tview.Escape((*msg).Text)
|
||||||
tim := time.Unix(int64((*msg).Info.Timestamp), 0)
|
tim := time.Unix(int64((*msg).Info.Timestamp), 0)
|
||||||
if (*msg).Info.FromMe { //msg from me
|
if (*msg).Info.FromMe { //msg from me
|
||||||
out += "[-::d](" + tim.Format("02-01-06 15:04:05") + ") [blue::b]Me: [-::-]" + text + "\n"
|
out += "[-::d](" + tim.Format("02-01-06 15:04:05") + ") [blue::b]Me: [-::-]" + text
|
||||||
} else if strings.Contains((*msg).Info.RemoteJid, GROUPSUFFIX) { // group msg
|
} else if strings.Contains((*msg).Info.RemoteJid, GROUPSUFFIX) { // group msg
|
||||||
//(*msg).Info.SenderJid
|
//(*msg).Info.SenderJid
|
||||||
userId := (*msg).Info.SenderJid
|
userId := (*msg).Info.SenderJid
|
||||||
//userId := strings.Split(string((*msg).Info.RemoteJid), "-")[0] + CONTACTSUFFIX
|
//userId := strings.Split(string((*msg).Info.RemoteJid), "-")[0] + CONTACTSUFFIX
|
||||||
out += "[-::d](" + tim.Format("02-01-06 15:04:05") + ") [green::b]" + GetIdName(userId) + ": [-::-]" + text + "\n"
|
out += "[-::d](" + tim.Format("02-01-06 15:04:05") + ") [green::b]" + GetIdName(userId) + ": [-::-]" + text
|
||||||
} else { // message from others
|
} else { // message from others
|
||||||
out += "[-::d](" + tim.Format("02-01-06 15:04:05") + ") [green::b]" + GetIdName((*msg).Info.RemoteJid) + ": [-::-]" + text + "\n"
|
out += "[-::d](" + tim.Format("02-01-06 15:04:05") + ") [green::b]" + GetIdName((*msg).Info.RemoteJid) + ": [-::-]" + text
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ var (
|
|||||||
type QRCodeString string
|
type QRCodeString string
|
||||||
|
|
||||||
func (v *QRCodeString) Print() {
|
func (v *QRCodeString) Print() {
|
||||||
fmt.Fprint(outer, *v)
|
fmt.Fprintln(outer, *v)
|
||||||
}
|
}
|
||||||
|
|
||||||
type qrcodeTerminal struct {
|
type qrcodeTerminal struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user