【Clojure 基本知識】小技巧s

;;模擬console原位更新輸出

;;空格擦除法,輸出空格,是爲了擦除短字符串尾部沒有佔用的位置,因爲退格只是回退,並不刪除
(dotimes [_ 10](let [n (rand) sn (.substring (str n ) 2) len (count sn)](print sn)(flush)(Thread/sleep 500) (dotimes[_ len](print "\b"))(flush)))

;;回退鍵配合刪除字符,由於刪除後,光標又前進一位,所以需要再次回退
(dotimes [_ 10](let [n (rand) sn (.substring (str n ) 2) len (count sn)](print sn)(flush)(Thread/sleep 500) (dotimes[t len](print "\b\u007f\b"))(flush)))

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章