浏览代码

Add ability to set post font

tags/v0.4
Matt Baer 8 年前
父节点
当前提交
ec47b9ea66
共有 2 个文件被更改,包括 48 次插入3 次删除
  1. +23
    -3
      writeas/cli.go
  2. +25
    -0
      writeas/fonts.go

+ 23
- 3
writeas/cli.go 查看文件

@@ -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
- 0
writeas/fonts.go 查看文件

@@ -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,
}

正在加载...
取消
保存