6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-06-30 18:51:03 +00:00
prologic-saltyim/internal/app/utils.go
James Mills 95663345d4 Adds support for multiple chats (#174)
Closes #146

See attached screenshots.

Co-authored-by: James Mills <prologic@shortcircuit.net.au>
Co-authored-by: James Mills <1290234+prologic@users.noreply.github.com>
Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/174
Reviewed-by: xuu <xuu@noreply@mills.io>
2023-01-11 22:58:07 +00:00

43 lines
1.0 KiB
Go

package app
import (
"fmt"
"strings"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
colorhash "github.com/taigrr/go-colorhash"
)
func getUserColor(s string) tcell.Color {
c := colorhash.HashString(s)
return tcell.NewHexColor(int32(c))
}
func floatingModal(p tview.Primitive, width, height int) tview.Primitive {
return tview.NewFlex().
AddItem(nil, 0, 1, false).
AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(nil, 0, 1, false).
AddItem(p, height, 1, true).
AddItem(nil, 0, 1, false), width, 1, true).
AddItem(nil, 0, 1, false)
}
// getMessageWidth returns width size for dialogs based on messages.
func getMessageWidth(message string) int {
var messageWidth int
for _, msg := range strings.Split(message, "\n") {
if len(msg) > messageWidth {
messageWidth = len(msg)
}
}
return messageWidth
}
// SetTerminalTitle sets the Terminal/Console's title
func SetTerminalTitle(format string, args ...interface{}) {
fmt.Printf("\033]0;%s\007", fmt.Sprintf(format, args...))
}