wohenyingyu01
V2EX  ›  问与答

写一个命令行工具怎样让输出的东西更新?

  •  
  •   wohenyingyu01 · Feb 29, 2016 · 2398 views
    This topic created in 3813 days ago, the information mentioned may be changed or developed.

    请教大侠:

    比如用 c 写的 print hello world ,怎样让已经 print 出来的 hello world 更新成成 123456 ,而不是重新输出一行?比如 curl 下载的时候会更新百分比,或者更高级一点的 vim ,在更新的同时还能互动?这种功能需要特定语言实现么?

    谢谢

    10 replies    2016-02-29 20:34:08 +08:00
    displayabc
        1
    displayabc  
       Feb 29, 2016   ❤️ 1
    输出\r,回到行首,重新覆盖
    Sunyanzi
        2
    Sunyanzi  
       Feb 29, 2016   ❤️ 1
    for i in {1..50}; do echo -ne "\r"$i; sleep 0.3; done

    是这个意思 ..?
    wohenyingyu01
        3
    wohenyingyu01  
    OP
       Feb 29, 2016
    @Sunyanzi
    @haython
    回头试试,不知道 java 和 swift 行不行
    des
        4
    des  
       Feb 29, 2016 via Android
    @haython 换行了怎么办的?
    mx3y
        5
    mx3y  
       Feb 29, 2016
    复制当前的文本内容,然后替换需要更新的,然后清空,再输出。
    manfay
        6
    manfay  
       Feb 29, 2016
    Ncurses
    wohenyingyu01
        7
    wohenyingyu01  
    OP
       Feb 29, 2016
    @mx3y 怎么清空?
    zhjits
        8
    zhjits  
       Feb 29, 2016
    方法 1 :根据终端窗口的长宽来填空字符或者换行
    方法 2 : libreadline
    方法 3 : ncurses
    crystom
        9
    crystom  
       Feb 29, 2016
    tracyone
        10
    tracyone  
       Feb 29, 2016
    linux 下时 getopt 和 getoptlong 函数,自行百度
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1335 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 17:10 · PVG 01:10 · LAX 10:10 · JFK 13:10
    ♥ Do have faith in what you're doing.