12 月 162023
 

Source: https://cirw.in/blog/bracketed-paste

  • Enable bracketed paste: printf “\e[?2004h”
  • Wait for paste to start: you’ll see \e[200~ on STDIN.
  • Wait for paste to stop: you’ll see \e[201~ on STDIN.
  • Disable bracketed paste: printf "\e[?2004l"

Source: 貼到終端機的內容兩端出現莫名其妙的亂碼字符

貼到終端機的內容兩端出現莫名其妙的亂碼字符,例如貼上的內容是HelloWorld,貼到終端機為:

00~HelloWorld01~
ESC[200~HelloWorldESC[201~

這是由於終端開啟了括號貼上模式,採用這種模式其中一個好處是程式很容易判斷輸入是貼上的還是手動輸入的。

開啟括號貼上模式方法:

printf "\e[?2004h"

關閉括號貼上模式:

printf "\e[?2004l"

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

CAPTCHA Image
Play CAPTCHA Audio
Reload Image