1
0
mirror of https://github.com/Rudi9719/kbtui.git synced 2026-03-24 11:27:24 +00:00
Files
kbtui/cmdUploadFile.go
Casper Weiss Bang 439f09aa1c Mo' colors
Changes:
- Stream is colored now
- Stream is formatted
- Stream has it's own formatting option
- Colors are now a style, and is a struct
- Color struct has a pretty cool functional interface
- colored mentions and PMs
- Every message uses the same function (it's dry!!)
- Colorize errors!
- Create function for visualizing errors
- colorized some of the command output!
- Color is stored in a Style
- Create a Text struct that can use to stylize strings "easily"
- Text can be used to build strings
- color highlighting on code
- added tml config support
- added different color for mention url
- Added sprintf to use formatting with PrintFeed and PrintError

Known Bugs: (added as todos whereever)
- Cannot use multiple formatting at the same time (*bold _italic_*
doesn't work
- sprintf is pretty shit
- background doesn't cover as a `block` in codeblocks
- not possible to escape sprintf thing
2019-10-23 23:45:42 +02:00

50 lines
1.2 KiB
Go

// +build !rm_basic_commands allcommands uploadcmd
package main
import (
"fmt"
"os"
"strings"
)
func init() {
command := Command{
Cmd: []string{"upload", "u"},
Description: "$filePath $fileName - Upload file from absolute path with optional name",
Help: "",
Exec: cmdUploadFile,
}
RegisterCommand(command)
}
func cmdUploadFile(cmd []string) {
if len(cmd) < 2 {
printInfo(fmt.Sprintf("%s%s $filePath $fileName - Upload file from absolute path with optional name", cmdPrefix, cmd[0]))
return
}
filePath := cmd[1]
if !strings.HasPrefix(filePath, "/") {
dir, err := os.Getwd()
if err != nil {
printError(fmt.Sprintf("There was an error determining path %+v", err))
}
filePath = fmt.Sprintf("%s/%s", dir, filePath)
}
var fileName string
if len(cmd) == 3 {
fileName = cmd[2]
} else {
fileName = ""
}
chat := k.NewChat(channel)
_, err := chat.Upload(fileName, filePath)
channelName := messageLinkKeybaseColor.stylize(channel.Name).string()
if err != nil {
printError(fmt.Sprintf("There was an error uploading %s to %s\n%+v", filePath, channelName, err))
} else {
printInfo(fmt.Sprintf("Uploaded %s to %s", filePath, channelName))
}
}