@ -25,6 +25,8 @@ var (
@@ -25,6 +25,8 @@ var (
g * gocui . Gui
)
var config * Config
func main ( ) {
if ! k . LoggedIn {
fmt . Println ( "You are not logged in." )
@ -37,7 +39,7 @@ func main() {
@@ -37,7 +39,7 @@ func main() {
}
defer g . Close ( )
g . SetManagerFunc ( layout )
go RunCommand ( "config" , "load" )
RunCommand ( "config" , "load" )
go populateList ( )
go updateChatWindow ( )
if len ( os . Args ) > 1 {
@ -82,7 +84,7 @@ func layout(g *gocui.Gui) error {
@@ -82,7 +84,7 @@ func layout(g *gocui.Gui) error {
chatView . Autoscroll = true
chatView . Wrap = true
welcomeText := basicStyle . stylize ( "Welcome $USER!\n\nYour chats will appear here.\nSupported commands are as follows:\n" )
welcomeText = welcomeText . replace ( "$USER" , mentionColor . stylize ( k . Username ) )
welcomeText = welcomeText . replace ( "$USER" , config . Colors . Message . Mention . stylize ( k . Username ) )
fmt . Fprintln ( chatView , welcomeText . string ( ) )
RunCommand ( "help" )
}
@ -95,7 +97,7 @@ func layout(g *gocui.Gui) error {
@@ -95,7 +97,7 @@ func layout(g *gocui.Gui) error {
}
inputView . Editable = true
inputView . Wrap = true
inputView . Title = fmt . Sprintf ( " Not in a chat - write `%sj` to join" , cmdPrefix )
inputView . Title = fmt . Sprintf ( " Not in a chat - write `%sj` to join" , config . Basics . C mdPrefix )
g . Cursor = true
}
if listView , err4 := g . SetView ( "List" , 0 , 0 , maxX / 2 - maxX / 3 - 1 , maxY - 1 , 0 ) ; err4 != nil {
@ -255,7 +257,7 @@ func printError(message string) {
@@ -255,7 +257,7 @@ func printError(message string) {
printErrorF ( message )
}
func printErrorF ( message string , parts ... StyledString ) {
printToView ( "Feed" , errorCol or. sprintf ( removeFormatting ( message ) , parts ... ) . string ( ) )
printToView ( "Feed" , config . Colors . Feed . Err or. sprintf ( removeFormatting ( message ) , parts ... ) . string ( ) )
}
// this removes formatting
@ -265,7 +267,7 @@ func printInfo(message string) {
@@ -265,7 +267,7 @@ func printInfo(message string) {
// this removes formatting
func printInfoF ( message string , parts ... StyledString ) {
printToView ( "Feed" , feedColor . sprintf ( removeFormatting ( message ) , parts ... ) . string ( ) )
printToView ( "Feed" , config . Colors . Feed . Basic . sprintf ( removeFormatting ( message ) , parts ... ) . string ( ) )
}
func printToView ( viewName string , message string ) {
g . Update ( func ( g * gocui . Gui ) error {
@ -349,10 +351,10 @@ func populateList() {
@@ -349,10 +351,10 @@ func populateList() {
log . Printf ( "%+v" , err )
} else {
clearView ( "List" )
var textBase = channelsColor . stylize ( "" )
var recentPMs = textBase . append ( channelsHeaderColo r . stylize ( "---[PMs]---\n" ) )
var textBase = config . Colors . Channels . Basic . stylize ( "" )
var recentPMs = textBase . append ( config . Colors . C hannels . Header . stylize ( "---[PMs]---\n" ) )
var recentPMsCount = 0
var recentChannels = textBase . append ( channelsHeaderColo r . stylize ( "---[Teams]---\n" ) )
var recentChannels = textBase . append ( config . Colors . C hannels . Header . stylize ( "---[Teams]---\n" ) )
var recentChannelsCount = 0
for _ , s := range testVar . Result . Conversations {
channels = append ( channels , s . Channel )
@ -361,7 +363,7 @@ func populateList() {
@@ -361,7 +363,7 @@ func populateList() {
if recentChannelsCount <= ( ( maxY - 2 ) / 3 ) {
channel := fmt . Sprintf ( "%s\n\t#%s\n" , s . Channel . Name , s . Channel . TopicName )
if s . Unread {
recentChannels = recentChannels . append ( channelUnreadColor . stylize ( "*" + channel ) )
recentChannels = recentChannels . append ( config . Colors . C hannels . Unread . stylize ( "*" + channel ) )
} else {
recentChannels = recentChannels . appendString ( channel )
}
@ -371,7 +373,7 @@ func populateList() {
@@ -371,7 +373,7 @@ func populateList() {
if recentPMsCount <= ( ( maxY - 2 ) / 3 ) {
pmName := fmt . Sprintf ( "%s\n" , cleanChannelName ( s . Channel . Name ) )
if s . Unread {
recentPMs = recentPMs . append ( channelUnreadColor . stylize ( "*" + pmName ) )
recentPMs = recentPMs . append ( config . Colors . C hannels . Unread . stylize ( "*" + pmName ) )
} else {
recentPMs = recentPMs . appendString ( pmName )
}
@ -388,35 +390,35 @@ func populateList() {
@@ -388,35 +390,35 @@ func populateList() {
// Formatting
func formatMessageBody ( body string ) StyledString {
output := messageBodyColor . stylize ( body )
output := config . Colors . Message . Body . stylize ( body )
output = colorReplaceMentionMe ( output )
output = output . colorRegex ( ` _[^_]*_ ` , messageBodyColor . withItalic ( ) )
output = output . colorRegex ( ` ~[^~]*~ ` , messageBodyColor . withStrikethrough ( ) )
output = output . colorRegex ( ` @[\w_]*(\.[\w_]+)* ` , messageLinkKeybaseColor )
output = output . colorRegex ( ` _[^_]*_ ` , config . Colors . Message . Body . withItalic ( ) )
output = output . colorRegex ( ` ~[^~]*~ ` , config . Colors . Message . Body . withStrikethrough ( ) )
output = output . colorRegex ( ` @[\w_]*(\.[\w_]+)* ` , config . Colors . Message . LinkKeybase )
// TODO change how bold, italic etc works, so it uses boldOn boldOff ([1m and [22m)
output = output . colorRegex ( ` \*[^\*]*\* ` , messageBodyColor . withBold ( ) )
output = output . colorRegex ( ` \*[^\*]*\* ` , config . Colors . Message . Body . withBold ( ) )
output = output . replaceString ( "```" , "<code>" )
// TODO make background color cover whole line
output = output . colorRegex ( "<code>(.*\n)*<code>" , messageCodeColor )
output = output . colorRegex ( "`[^`]*`" , messageCodeColor )
output = output . colorRegex ( "<code>(.*\n)*<code>" , config . Colors . Message . Code )
output = output . colorRegex ( "`[^`]*`" , config . Colors . Message . Code )
// mention URL
output = output . colorRegex ( ` (https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=] { 1,256}\.[a-zA-Z0-9()] { 1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)) ` , messageLinkURLColor )
output = output . colorRegex ( ` (https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=] { 1,256}\.[a-zA-Z0-9()] { 1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)) ` , config . Colors . Message . LinkURL )
return output
}
// TODO use this more
func formatChannel ( ch keybase . Channel ) StyledString {
return messageLinkKeybaseColor . stylize ( fmt . Sprintf ( "@%s#%s" , ch . Name , ch . TopicName ) )
return config . Colors . Message . LinkKeybase . stylize ( fmt . Sprintf ( "@%s#%s" , ch . Name , ch . TopicName ) )
}
func colorReplaceMentionMe ( msg StyledString ) StyledString {
return msg . colorRegex ( ` (@?\b ` + k . Username + ` \b) ` , mentionColor )
return msg . colorRegex ( ` (@?\b ` + k . Username + ` \b) ` , config . Colors . Message . Mention )
}
func colorUsername ( username string ) StyledString {
var color = messageSenderDefaultColor
var color = config . Colors . Message . SenderDefault
if username == k . Username {
color = mentionColor
color = config . Colors . Message . Mention
}
return color . stylize ( username )
}
@ -427,27 +429,27 @@ func cleanChannelName(c string) string {
@@ -427,27 +429,27 @@ func cleanChannelName(c string) string {
}
func formatMessage ( api keybase . ChatAPI , formatString string ) string {
ret := messageHeaderColo r. stylize ( "" )
ret := config . Colors . Message . Heade r. stylize ( "" )
msgType := api . Msg . Content . Type
switch msgType {
case "text" , "attachment" :
ret = messageHeaderColo r. stylize ( formatString )
ret = config . Colors . Message . Heade r. stylize ( formatString )
tm := time . Unix ( int64 ( api . Msg . SentAt ) , 0 )
var msg = formatMessageBody ( api . Msg . Content . Text . Body )
if msgType == "attachment" {
msg = messageBodyColor . stylize ( "$TITLE\n$FILE" )
msg = config . Colors . Message . Body . stylize ( "$TITLE\n$FILE" )
attachment := api . Msg . Content . Attachment
msg = msg . replaceString ( "$TITLE" , attachment . Object . Title )
msg = msg . replace ( "$FILE" , messageAttachmentColor . stylize ( fmt . Sprintf ( "[Attachment: %s]" , attachment . Object . Filename ) ) )
msg = msg . replace ( "$FILE" , config . Colors . Message . Attachment . stylize ( fmt . Sprintf ( "[Attachment: %s]" , attachment . Object . Filename ) ) )
}
user := colorUsername ( api . Msg . Sender . Username )
device := messageSenderDeviceColor . stylize ( api . Msg . Sender . DeviceName )
msgID := messageIDColor . stylize ( fmt . Sprintf ( "%d" , api . Msg . ID ) )
date := messageTimeColor . stylize ( tm . Format ( d ateFormat) )
msgTime := messageTimeColor . stylize ( tm . Format ( timeFormat ) )
device := config . Colors . Message . SenderDevice . stylize ( api . Msg . Sender . DeviceName )
msgID := config . Colors . Message . ID . stylize ( fmt . Sprintf ( "%d" , api . Msg . ID ) )
date := config . Colors . Message . Time . stylize ( tm . Format ( config . Formatting . D ateFormat) )
msgTime := config . Colors . Message . Time . stylize ( tm . Format ( config . Forma tting . T imeFormat) )
channelName := messageIDColor . stylize ( fmt . Sprintf ( "@%s#%s" , api . Msg . Channel . Name , api . Msg . Channel . TopicName ) )
channelName := config . Colors . Message . ID . stylize ( fmt . Sprintf ( "@%s#%s" , api . Msg . Channel . Name , api . Msg . Channel . TopicName ) )
ret = ret . replace ( "$MSG" , msg )
ret = ret . replace ( "$USER" , user )
ret = ret . replace ( "$DEVICE" , device )
@ -459,9 +461,9 @@ func formatMessage(api keybase.ChatAPI, formatString string) string {
@@ -459,9 +461,9 @@ func formatMessage(api keybase.ChatAPI, formatString string) string {
return ret . string ( )
}
func formatOutput ( api keybase . ChatAPI ) string {
format := outputFormat
format := c onfig . Formatting . O utputFormat
if stream {
format = outputStreamFormat
format = c onfig . Formatting . O utputStreamFormat
}
return formatMessage ( api , format )
}
@ -489,7 +491,7 @@ func handleMessage(api keybase.ChatAPI) {
@@ -489,7 +491,7 @@ func handleMessage(api keybase.ChatAPI) {
if m . Text == k . Username {
// We are in a team
if topicName != channel . TopicName {
printInfo ( formatMessage ( api , mentionFormat ) )
printInfo ( formatMessage ( api , config . For matting . OutputM entionFormat) )
fmt . Print ( "\a" )
}
@ -498,7 +500,7 @@ func handleMessage(api keybase.ChatAPI) {
@@ -498,7 +500,7 @@ func handleMessage(api keybase.ChatAPI) {
}
} else {
if msgSender != channel . Name {
printInfo ( formatMessage ( api , p mFormat) )
printInfo ( formatMessage ( api , config . For matting . PM Format) )
fmt . Print ( "\a" )
}
@ -516,7 +518,7 @@ func handleMessage(api keybase.ChatAPI) {
@@ -516,7 +518,7 @@ func handleMessage(api keybase.ChatAPI) {
if api . Msg . Channel . MembersType == keybase . TEAM {
printToView ( "Chat" , formatOutput ( api ) )
} else {
printToView ( "Chat" , formatMessage ( api , p mFormat) )
printToView ( "Chat" , formatMessage ( api , config . For matting . PM Format) )
}
}
} else {
@ -550,8 +552,8 @@ func handleInput(viewName string) error {
@@ -550,8 +552,8 @@ func handleInput(viewName string) error {
if inputString == "" {
return nil
}
if strings . HasPrefix ( inputString , cmdPrefix ) {
cmd := deleteEmpty ( strings . Split ( inputString [ len ( cmdPrefix ) : ] , " " ) )
if strings . HasPrefix ( inputString , config . Basics . C mdPrefix ) {
cmd := deleteEmpty ( strings . Split ( inputString [ len ( config . Basics . C mdPrefix ) : ] , " " ) )
if len ( cmd ) < 1 {
return nil
}