-
Notifications
You must be signed in to change notification settings - Fork 16
/
text.go
55 lines (49 loc) · 1.31 KB
/
text.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package cmd
import (
goio "io"
"os"
"github.com/evolbioinfo/gotree/draw"
"github.com/evolbioinfo/gotree/io"
"github.com/evolbioinfo/gotree/tree"
"github.com/spf13/cobra"
)
var termwidth int
// textCmd represents the text command
var textCmd = &cobra.Command{
Use: "text",
Short: "Print trees in ASCII",
Long: `Print trees in ASCII.`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
var f *os.File
var treefile goio.Closer
var treechan <-chan tree.Trees
var d draw.TreeDrawer
var l draw.TreeLayout
if f, err = openWriteFile(outtreefile); err != nil {
io.LogError(err)
return
}
defer closeWriteFile(f, outtreefile)
if treefile, treechan, err = readTrees(intreefile); err != nil {
io.LogError(err)
return
}
defer treefile.Close()
for t := range treechan {
if t.Err != nil {
io.LogError(t.Err)
return t.Err
}
d = draw.NewTextTreeDrawer(f, termwidth, len(t.Tree.Tips())*2, 0)
l = draw.NewNormalLayout(d, !drawNoBranchLengths, !drawNoTipLabels, drawInternalNodeLabels, drawSupport)
l.SetDisplayNodeComments(drawNodeComment)
l.SetSupportCutoff(drawSupportCutoff)
l.DrawTree(t.Tree)
}
return
},
}
func init() {
drawCmd.AddCommand(textCmd)
textCmd.PersistentFlags().IntVarP(&termwidth, "width", "w", 200, "Width of tree/terminal (in characters)")
}