1
0
mirror of https://github.com/writeas/writeas-cli synced 2025-07-26 23:08:16 +00:00

Add ability to set post font

This commit is contained in:
Matt Baer 2015-11-01 21:24:34 -05:00
parent c372ed6740
commit ec47b9ea66
2 changed files with 48 additions and 3 deletions

View File

@ -24,6 +24,11 @@ const (
VERSION = "0.3"
)
// Defaults for posts on Write.as.
const (
defaultFont = PostFontMono
)
var postFlags = []cli.Flag{
cli.BoolFlag{
Name: "tor, t",
@ -38,6 +43,11 @@ var postFlags = []cli.Flag{
Name: "code",
Usage: "Specifies this post is code",
},
cli.StringFlag{
Name: "font",
Usage: "Sets post font to given value",
Value: defaultFont,
},
}
func main() {
@ -234,7 +244,7 @@ func handlePost(fullPost []byte, c *cli.Context) error {
fmt.Println("Posting...")
}
return DoPost(fullPost, false, tor, c.Bool("code"))
return DoPost(fullPost, c.String("font"), false, tor, c.Bool("code"))
}
func cmdPost(c *cli.Context) {
@ -430,15 +440,25 @@ func DoFetch(friendlyId string, tor bool) {
}
}
func DoPost(post []byte, encrypt, tor, code bool) error {
func DoPost(post []byte, font string, encrypt, tor, code bool) error {
data := url.Values{}
data.Set("w", string(post))
if encrypt {
data.Add("e", "")
}
font := "mono"
if code {
if font != defaultFont {
fmt.Printf("A non-default font '%s' and --code flag given. 'code' type takes precedence.\n", font)
}
font = "code"
} else {
// Validate font value
if f, ok := postFontMap[font]; ok {
font = string(f)
} else {
fmt.Printf("Font '%s' invalid. Using default '%s'\n", font, defaultFont)
font = string(defaultFont)
}
}
data.Add("font", font)

25
writeas/fonts.go Normal file
View File

@ -0,0 +1,25 @@
package main
// postFont represents a valid post appearance value in the API.
type postFont string
// Valid appearance types for posts.
const (
PostFontNormal postFont = "norm"
PostFontSans = "sans"
PostFontMono = "mono"
PostFontWrap = "wrap"
PostFontCode = "code"
)
var postFontMap = map[string]postFont{
"norm": PostFontNormal,
"normal": PostFontNormal,
"serif": PostFontNormal,
"sans": PostFontSans,
"sansserif": PostFontSans,
"mono": PostFontMono,
"monospace": PostFontMono,
"wrap": PostFontWrap,
"code": PostFontCode,
}