@@ -75,7 +75,7 @@ func main() {
7575 }
7676
7777 if * r {
78- * chars = reverseString (* chars )
78+ * chars = pic2ascii . ReverseString (* chars )
7979 }
8080
8181 toAscii := func (img image.Image ) string {
@@ -106,22 +106,24 @@ func main() {
106106 dds := []string {}
107107 sg := pic2ascii .SliceGIF (img )
108108 for _ , v := range sg {
109- dds = append (dds , fmt .Sprintln (toAscii (v )))
109+ dd := toAscii (v )
110+ dds = append (dds , dd )
110111 }
111112
112- if * o == "" {
113- if img .LoopCount == 0 {
114- img .LoopCount = * m
115- }
113+ if * o != "" {
114+ ioutil .WriteFile (* o , []byte (strings .Join (dds , "\n " )), 0666 )
115+ return
116+ }
117+
118+ if img .LoopCount == 0 {
119+ img .LoopCount = * m
120+ }
116121
117- for i := 0 ; i != img .LoopCount ; i ++ {
118- for k , v := range dds {
119- fmt .Println (v )
120- time .Sleep (time .Duration (img .Delay [k ]) * time .Second / 100 )
121- }
122+ for i := 0 ; i != img .LoopCount ; i ++ {
123+ for k , v := range dds {
124+ fmt .Println (v )
125+ time .Sleep (time .Duration (img .Delay [k ]) * time .Second / 100 )
122126 }
123- } else {
124- ioutil .WriteFile (* o , []byte (strings .Join (dds , "\n " )), 0666 )
125127 }
126128
127129 default :
@@ -132,20 +134,11 @@ func main() {
132134 }
133135
134136 dd := toAscii (img )
135- if * o == "" {
136- fmt .Print (dd )
137- } else {
137+ if * o != "" {
138138 ioutil .WriteFile (* o , []byte (dd ), 0666 )
139+ return
139140 }
140- }
141- }
142141
143- func reverseString (s string ) string {
144- str := []rune (s )
145- l := len (str ) / 2
146- for i := 0 ; i < l ; i ++ {
147- j := len (str ) - i - 1
148- str [i ], str [j ] = str [j ], str [i ]
142+ fmt .Print (dd )
149143 }
150- return string (str )
151144}
0 commit comments