2017-11-15 6 views
-1

モニタの解像度を行と列に変換します。あなたは端末エミュレータウィンドウの操作コントロールを使用しているのでモニターの解像度を行と列に変換しますか?

次のコードは、(XTerm Control Sequencesを参照)、これまで私が持っているもの

python << EOF 
import subprocess 
import sys 
results = subprocess.Popen(['xrandr'],stdout=subprocess.PIPE).communicate()[0].split("current")[1].split(",")[0] 
width = results.split("x")[0].strip() 
height = results.split("x")[1].strip() 
print width + "x" + height 

row = width 
col = height 
sys.stdout.write("\x1b[8;{rows};{cols}t".format(rows=row, cols=col)) 

print """ 
     TEST 
     """ 
EOF 

答えて

1

で、端末が対応するレポートを実施することができます。このセクションでは、情報を持っています

CSI Ps ; Ps ; Ps t 
      Window manipulation (from dtterm, as well as extensions). 
      These controls may be disabled using the allowWindowOps 
      resource. Valid values for the first (and any additional 
      parameters) are: 

これが関連している:ある、あなたはその制御シーケンスを使用してピクセルで、かつウィンドウの行を知ってから、ウィンドウのサイズを得ることができた

 Ps = 1 4 -> Report xterm window in pixels. 
     Result is CSI 4 ; height ; width t 

/columnsとすると、font-sizeを計算できます。その情報(およびモニターのサイズ)を考慮すると、適合する文字行と列の数を決定できます。

関連する問題