0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ターミナルのカーソル操作(ANSIコマンド)

0
Posted at

Description

カーソル操作の基本をスクリプトにしてみました。
使い方はソースコード見てください。
CUIで動くプログラムを作る時に役立ちそうです。
詳しくはこれがまとめてくれてます。
ANSI Escape Sequences(GitHub)

script.sh (ファイル保存して試してください。)

#!/bin/bash

echo -en "\033[?25l" # カーソルを非表示
for ((i=0; i<14; i++)) do
 echo -n "processing"
 for ((j=0; j<i; j++)) do
  sleep 0.02
  echo -n "." 
 done
 echo -e "\033[F" # カーソルを前の行の一番左に
done
 echo -en "\x1b[2K" # カーソルがある行を削除
echo "perfect!!" 
echo -e "\033[?25h" # カーソルを再表示

Resource

ANSI escape code(Wikipedia)
ANSI Escape Sequences(GitHub)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?