Skip to content

Commit e5ef667

Browse files
committed
show help and set no receiver on contact root
1 parent c39479f commit e5ef667

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"gitlab.com/tslocum/cbind"
1717
)
1818

19-
var VERSION string = "v0.9.2"
19+
var VERSION string = "v0.9.3"
2020

2121
var sndTxt string = ""
2222
var currentReceiver string = ""
@@ -144,6 +144,7 @@ func MakeTree() *tview.TreeView {
144144
treeView.SetChangedFunc(func(node *tview.TreeNode) {
145145
reference := node.GetReference()
146146
if reference == nil {
147+
SetDisplayedContact("")
147148
return // Selecting the root node does nothing.
148149
}
149150
children := node.GetChildren()
@@ -548,6 +549,9 @@ func (u UiHandler) NewScreen(screen string, ids []string) {
548549
textView.Clear()
549550
textView.SetText(screen)
550551
curRegions = ids
552+
if screen == "" {
553+
PrintHelp()
554+
}
551555
})
552556
}
553557

messages/session_manager.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ func (sm *SessionManager) execCommand(command Command) {
255255
default:
256256
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Unknown command: [-]" + cmd)
257257
case "backlog":
258-
//command
259258
if sm.currentReceiver == "" {
260259
return
261260
}
@@ -266,8 +265,6 @@ func (sm *SessionManager) execCommand(command Command) {
266265
go sm.getConnection().LoadChatMessages(sm.currentReceiver, count, firstMsg.Info.Id, firstMsg.Info.FromMe, false, sm)
267266
}
268267
}
269-
//FullChatHistory(currentReceiver, 20, 100000, handler)
270-
//messages.GetConnection().LoadFullChatHistory(currentReceiver, 20, 100000, handler)
271268
case "login":
272269
sm.uiHandler.PrintError(sm.login())
273270
case "connect":
@@ -282,19 +279,19 @@ func (sm *SessionManager) execCommand(command Command) {
282279
text := strings.Join(textParams, " ")
283280
sm.sendText(command.Params[0], text)
284281
} else {
285-
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Usage:[-] send [user-id[] [message text[]")
282+
sm.printCommandUsage("send", "[user-id[] [message text[]")
286283
}
287284
case "select":
288285
if checkParam(command.Params, 1) {
289286
sm.setCurrentReceiver(command.Params[0])
290287
} else {
291-
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Usage:[-] select [user-id[]")
288+
sm.printCommandUsage("select", "[user-id[]")
292289
}
293290
case "info":
294291
if checkParam(command.Params, 1) {
295292
sm.uiHandler.PrintText(sm.db.GetMessageInfo(command.Params[0]))
296293
} else {
297-
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Usage:[-] info [message-id[]")
294+
sm.printCommandUsage("info", "[message-id[]")
298295
}
299296
case "download":
300297
if checkParam(command.Params, 1) {
@@ -304,7 +301,7 @@ func (sm *SessionManager) execCommand(command Command) {
304301
sm.uiHandler.PrintText("[::d] -> " + path + "[::-]")
305302
}
306303
} else {
307-
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Usage:[-] download [message-id[]")
304+
sm.printCommandUsage("download", "[message-id[]")
308305
}
309306
case "open":
310307
if checkParam(command.Params, 1) {
@@ -314,7 +311,7 @@ func (sm *SessionManager) execCommand(command Command) {
314311
sm.uiHandler.PrintError(err)
315312
}
316313
} else {
317-
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Usage:[-] open [message-id[]")
314+
sm.printCommandUsage("open", "[message-id[]")
318315
}
319316
case "show":
320317
if checkParam(command.Params, 1) {
@@ -324,7 +321,7 @@ func (sm *SessionManager) execCommand(command Command) {
324321
sm.uiHandler.PrintError(err)
325322
}
326323
} else {
327-
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Usage:[-] show [message-id[]")
324+
sm.printCommandUsage("show", "[message-id[]")
328325
}
329326
case "url":
330327
if checkParam(command.Params, 1) {
@@ -336,7 +333,7 @@ func (sm *SessionManager) execCommand(command Command) {
336333
}
337334
}
338335
} else {
339-
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Usage:[-] url [message-id[]")
336+
sm.printCommandUsage("url", "[message-id[]")
340337
}
341338
case "upload":
342339
if sm.currentReceiver == "" {
@@ -360,7 +357,7 @@ func (sm *SessionManager) execCommand(command Command) {
360357
}
361358
}
362359
} else {
363-
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Usage:[-] upload /path/to/file")
360+
sm.printCommandUsage("upload", "/path/to/file")
364361
}
365362
sm.uiHandler.PrintError(err)
366363
case "sendimage":
@@ -385,7 +382,7 @@ func (sm *SessionManager) execCommand(command Command) {
385382
}
386383
}
387384
} else {
388-
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Usage:[-] sendimage /path/to/file")
385+
sm.printCommandUsage("sendimage", "/path/to/file")
389386
}
390387
sm.uiHandler.PrintError(err)
391388
case "sendvideo":
@@ -410,7 +407,7 @@ func (sm *SessionManager) execCommand(command Command) {
410407
}
411408
}
412409
} else {
413-
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Usage:[-] sendvideo /path/to/file")
410+
sm.printCommandUsage("sendvideo", "/path/to/file")
414411
}
415412
sm.uiHandler.PrintError(err)
416413
case "sendaudio":
@@ -435,7 +432,7 @@ func (sm *SessionManager) execCommand(command Command) {
435432
}
436433
}
437434
} else {
438-
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Usage:[-] sendaudio /path/to/file")
435+
sm.printCommandUsage("sendaudio", "/path/to/file")
439436
}
440437
sm.uiHandler.PrintError(err)
441438
case "revoke":
@@ -465,7 +462,7 @@ func (sm *SessionManager) execCommand(command Command) {
465462
}
466463
sm.uiHandler.PrintError(err)
467464
} else {
468-
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Usage:[-] revoke [message-id[]")
465+
sm.printCommandUsage("revoke", "[message-id[]")
469466
}
470467
case "leave":
471468
groupId := sm.currentReceiver
@@ -488,6 +485,11 @@ func (sm *SessionManager) execCommand(command Command) {
488485
}
489486
}
490487

488+
// helper for built-in command help
489+
func (sm *SessionManager) printCommandUsage(command string, usage string) {
490+
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Usage:[-] " + command + " " + usage)
491+
}
492+
491493
// check if parameters for command are okay
492494
func checkParam(arr []string, length int) bool {
493495
if arr == nil || len(arr) < length {

0 commit comments

Comments
 (0)